Created
June 21, 2012 11:22
-
-
Save madr/2965201 to your computer and use it in GitHub Desktop.
Upload static file dir recursively to Amazon S3 using python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import listdir | |
from os.path import isdir | |
from simples3 import S3Bucket # pip install simples3 | |
root = "../static" | |
exclude = [".DS_Store"] | |
A = "access key" | |
B = "secret key" | |
bucket = "guidenext" | |
s3 = S3Bucket(bucket, | |
access_key=A, | |
secret_key=B, | |
base_url="http://%s.s3.amazonaws.com" % bucket) | |
def upload_file(src): | |
print "- uploading %s" % src | |
f = open(src) | |
s3.put(src.replace(root, "admin"), f.read()) | |
def upload_dir(path): | |
for f in listdir(path): | |
if f not in exclude: | |
if isdir("%s/%s" % (path, f)) is True: | |
upload_dir("%s/%s" % (path, f)) | |
else: | |
upload_file("%s/%s" % (path, f)) | |
upload_dir(root) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment