Example #1
0
def upload_assets(user, secret, bucket, _retries=5):
    access_key = user if user else os.environ['AWS_ACCESS_KEY_ID']
    access_secret = secret if secret else os.environ['AWS_SECRET_ACCESS_KEY']
    bucket = bucket if bucket else os.environ['S3_BUCKET_NAME']

    retries = 0

    import subprocess
    # build assets and capture the output
    print 'Building assets...'
    proc = subprocess.Popen(['python', 'manage.py', 'assets', 'build'],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT)
    proc.wait()

    print 'Connecting to S3...'
    conn, bucket = connect_to_s3(access_key, access_secret, bucket)
    print 'Uploading files...'

    for path in proc.communicate()[0].split('\n')[:-1]:
        key = path.split('public')[1]
        print 'Uploading {}'.format(key)
        while retries <= _retries:
            try:
                upload_file(key,
                            bucket,
                            root=current_app.config['APP_DIR'] + '/static')
                break
            except Exception, e:
                print 'Error: {}'.format(e), 'Retrying...'
                retries += 1
        if retries > _retries:
            print 'File {} did not upload'.format(key)
        retries = 0
Example #2
0
def upload_assets(user, secret, bucket, _retries=5):
    access_key = user if user else os.environ["AWS_ACCESS_KEY_ID"]
    access_secret = secret if secret else os.environ["AWS_SECRET_ACCESS_KEY"]
    bucket = bucket if bucket else os.environ["S3_BUCKET_NAME"]

    retries = 0

    import subprocess

    # build assets and capture the output
    print "Building assets..."
    proc = subprocess.Popen(
        ["python", "manage.py", "assets", "build"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
    )
    proc.wait()

    print "Connecting to S3..."
    conn, bucket = connect_to_s3(access_key, access_secret, bucket)
    print "Uploading files..."

    for path in proc.communicate()[0].split("\n")[:-1]:
        key = path.split("public")[1]
        print "Uploading {}".format(key)
        while retries <= _retries:
            try:
                upload_file(key, bucket, root=current_app.config["APP_DIR"] + "/static")
                break
            except Exception, e:
                print "Error: {}".format(e), "Retrying..."
                retries += 1
        if retries > _retries:
            print "File {} did not upload".format(key)
        retries = 0
Example #3
0
def upload_assets(user, secret, bucket, _retries=5):
    access_key = user if user else os.environ['AWS_ACCESS_KEY_ID']
    access_secret = secret if secret else os.environ['AWS_SECRET_ACCESS_KEY']
    bucket = bucket if bucket else os.environ['S3_BUCKET_NAME']

    retries = 0

    import subprocess
    # build assets and capture the output
    print 'Building assets...'
    proc = subprocess.Popen(
        ['python', 'manage.py', 'assets', 'build'],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT
    )
    proc.wait()

    print 'Connecting to S3...'
    conn, bucket = connect_to_s3(access_key, access_secret, bucket)
    print 'Uploading files...'

    for path in proc.communicate()[0].split('\n')[:-1]:
        key = path.split('public')[1]
        print 'Uploading {}'.format(key)
        while retries <= _retries:
            try:
                upload_file(key, bucket, root=current_app.config['APP_DIR'] + '/static')
                break
            except Exception, e:
                print 'Error: {}'.format(e), 'Retrying...'
                retries += 1
        if retries > _retries:
            print 'File {} did not upload'.format(key)
        retries = 0
Example #4
0
                break
            except Exception, e:
                print 'Error: {}'.format(e), 'Retrying...'
                retries += 1
        if retries > _retries:
            print 'File {} did not upload'.format(key)
        retries = 0

    for fontfile in os.listdir(
            os.path.join(current_app.config['APP_DIR'], 'static', 'fonts')):
        print 'Uploading {}'.format(fontfile)
        while retries <= _retries:
            try:
                upload_file(fontfile,
                            bucket,
                            root=current_app.config['APP_DIR'] +
                            '/static/fonts',
                            prefix='/static/fonts')
                break
            except Exception, e:
                print 'Error: {}'.format(e), 'Retrying...'
                retries += 1
        if retries > _retries:
            print 'File {} did not upload'.format(fontfile)
        retries = 0

    print 'Uploading images...'
    for root, _, files in os.walk(current_app.config['APP_DIR'] +
                                  '/static/img'):
        for filepath in files:
            print 'Uploading {}'.format(filepath)
Example #5
0
            try:
                upload_file(key, bucket, root=current_app.config["APP_DIR"] + "/static")
                break
            except Exception, e:
                print "Error: {}".format(e), "Retrying..."
                retries += 1
        if retries > _retries:
            print "File {} did not upload".format(key)
        retries = 0

    for fontfile in os.listdir(os.path.join(current_app.config["APP_DIR"], "static", "fonts")):
        print "Uploading {}".format(fontfile)
        while retries <= _retries:
            try:
                upload_file(
                    fontfile, bucket, root=current_app.config["APP_DIR"] + "/static/fonts", prefix="/static/fonts"
                )
                break
            except Exception, e:
                print "Error: {}".format(e), "Retrying..."
                retries += 1
        if retries > _retries:
            print "File {} did not upload".format(fontfile)
        retries = 0

    print "Uploading images..."
    for root, _, files in os.walk(current_app.config["APP_DIR"] + "/static/img"):
        for filepath in files:
            print "Uploading {}".format(filepath)
            while retries <= _retries:
                try:
Example #6
0
            try:
                upload_file(key, bucket, root=current_app.config['APP_DIR'] + '/static')
                break
            except Exception, e:
                print 'Error: {}'.format(e), 'Retrying...'
                retries += 1
        if retries > _retries:
            print 'File {} did not upload'.format(key)
        retries = 0

    for fontfile in os.listdir(os.path.join(current_app.config['APP_DIR'], 'static', 'fonts')):
        print 'Uploading {}'.format(fontfile)
        while retries <= _retries:
            try:
                upload_file(
                    fontfile, bucket, root=current_app.config['APP_DIR'] + '/static/fonts',
                    prefix='/static/fonts'
                )
                break
            except Exception, e:
                print 'Error: {}'.format(e), 'Retrying...'
                retries += 1
        if retries > _retries:
            print 'File {} did not upload'.format(fontfile)
        retries = 0

    print 'Uploading images...'
    for root, _, files in os.walk(current_app.config['APP_DIR'] + '/static/img'):
        for filepath in files:
            print 'Uploading {}'.format(filepath)
            while retries <= _retries:
                try: