Пример #1
0
def __upload(proj, repo, branch, data, maker, force=True):
    root, source, dist = (None, None, None)
    try:
        root = Folder(data.root or '~')
        source = root.child_folder('src')
        source.make()
        source = source.child_folder(proj)
        dist = root.child_folder('dist')
        tree = Tree(source, repo=repo, branch=branch)
        key = None
        if not force:
            key = check_revision_already_published(proj, data.bucket, tree)

        if not key:
            b = Bucket(data.bucket)
            b.make()
            key_folder = Folder(proj).child_folder(branch)
            zippath = dist.child_file(proj + '.zip')
            tree.clone(tip_only=True)
            sha = tree.get_revision(short=False)
            key_folder = key_folder.child_folder(sha)
            target = dist.child_folder(proj)
            target.make()
            maker(source, target)
            target.zip(zippath.path)
            b.add_file(zippath, target_folder=key_folder.path)
            key = b.bucket.get_key(key_folder.child(zippath.name))
    finally:
        if source:
            source.delete()
        if dist:
            dist.delete()

    return key.generate_url(30000)
Пример #2
0
def __dump_and_upload_result(name, data):
    result = HERE.child_file('result.log')
    with open(result.path, 'a') as f:
        f.write('*********' + name + '************')
        f.write(yaml.dump(data))
        f.write('*********' + name + '************')
    b = Bucket(data['bucket'],
                aws_access_key_id=data['keys']['access_key'],
                aws_secret_access_key=data['keys']['secret'])
    b.make()
    b.add_file(result)
Пример #3
0
def upload_stack(config, **kwargs):
    config, env, files = validate_stack(config, **kwargs)
    if not config:
        raise Exception("Invalid template.")
    bucket_name = config.publish.get("bucket", None)
    if not bucket_name:
        raise Exception("You need to provide a bucket name for publishing your stack.")
    path = config.publish.get("path", None)
    if path:
        path = path.rstrip("/") + "/"
    bucket = Bucket(bucket_name, **kwargs)
    bucket.make()
    result = {}
    url_format = "http://{bucket_name}.s3.amazonaws.com/{path}{template_name}"
    for rpath, (source, target) in files.iteritems():
        full_path = bucket.add_file(target, acl="private", target_folder=path)
        signed_url = bucket.get_signed_url(full_path)
        url = url_format.format(bucket_name=bucket_name, path=path, template_name=rpath)
        result[rpath] = dict(url=url, source=source, target=target)
    return ConfigDict(dict(result=result, files=files, config=config))