#! /usr/bin/env python2 """ Upload script Note, due to strange encoding/type bugs in boto3, this script must be run under python 2. """ from __future__ import print_function import mimetypes import os import os.path import boto3 microsite_bucket = 'dev-film-transparency-microsite' def upload(path): s3 = boto3.resource('s3') for dirpath, dirnames, filenames in os.walk(path): for filename in filenames: if filename.endswith('.hbs'): continue filepath = os.path.join(dirpath, filename) s3path = filepath[len(path)+1:] content_type, encoding = mimetypes.guess_type(filepath) with open(filepath) as fh: msg_tmpl = ( 'Uploading {filepath} ' 'with content-type {content_type}') print(msg_tmpl.format(filepath=filepath, content_type=content_type)) s3.Object(microsite_bucket, s3path).put( Body=fh, ContentEncoding=(encoding if encoding else ''), ContentType=content_type) upload('../public')