#!/data/wre/prereqs/bin/python # Configurations log = '/dev/null' # or e.g. /tmp/cdn.log DEBUG = 0 # end config from datetime import datetime, timedelta import locale import sys import subprocess def futureDate(): """ futureDate: a date in the pseudo-infinite future, for expiring pseudo-never RFC-2616-14.21 says one year max, but prominent examples use 10 years, e.g. http://developer.yahoo.com/performance/rules.html """ # stackoverflow.com/questions/225086/rfc-1123-date-representation-in-python locale.setlocale(locale.LC_TIME, 'en_US') in10yr = datetime.utcnow() + timedelta(days=3650) return in10yr.strftime('%a, %d %b %Y %H:%M:%S GMT') try: bucketName = sys.argv[1] bucketPath = sys.argv[2] storageLocation = sys.argv[3] except: sys.exit('Usage: %s ' % sys.argv[0]) forever = futureDate() cmd = "/data/wre/prereqs/bin/s3cmd --config=/data/WebGUI/etc/%s.s3cfg" % (bucketName) cmd += " put --recursive --acl-public --add-header 'Expires: %s' " % (forever) cmd += "-- '%s' s3://%s/" % (storageLocation, bucketPath) cmd += " >> %s 2>&1" % log if DEBUG > 2: print cmd sys.exit(subprocess.call(cmd, shell=True))