diff options
| author | Scott Ostler <scottbot9000@gmail.com> | 2010-11-06 20:32:36 -0400 |
|---|---|---|
| committer | Scott Ostler <scottbot9000@gmail.com> | 2010-11-06 20:32:36 -0400 |
| commit | f9b9a3b3b1d47bc69213f3e8eb88fe76691aad33 (patch) | |
| tree | 8367a08d3e3ea4e9c14182880cd207f617098d5f | |
| parent | d765ecafa41542f3745522c164f9c8ed9bb0eb62 (diff) | |
s3upload.py now only initializes AWS connection when uploading
| -rw-r--r-- | scripts/s3upload.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/scripts/s3upload.py b/scripts/s3upload.py index 9263a8f..163f3b6 100644 --- a/scripts/s3upload.py +++ b/scripts/s3upload.py @@ -28,7 +28,7 @@ def retry_func(f, count): print 'Error! retrying %s more time(s)' % (count - 1) retry_func(f, count - 1) -def upload_file(path, conn, verbose=True, dryrun=False): +def upload_file(path, verbose=True, dryrun=False): path = os.path.normpath(path) if path == '.' or not os.path.isfile(path): return @@ -41,6 +41,7 @@ def upload_file(path, conn, verbose=True, dryrun=False): path = path.replace('\\', '/') # Windows hack start = time.time() def do_upload(): + conn = get_or_initialize_aws_connection() conn.put(BUCKET_NAME, path, S3.S3Object(filedata), {'x-amz-acl': 'public-read', 'Content-Type': content_type}) @@ -52,26 +53,25 @@ def upload_file(path, conn, verbose=True, dryrun=False): print "uploaded %s (%0.0fms) (%sKB)" % (path, ms_took, size / 1024) return 1 -def upload_directory(path, conn, verbose=True, dryrun=False): +def upload_directory(path, verbose=True, dryrun=False): counter = 0 for f in sorted(os.listdir(path)): subpath = os.path.join(path, f) if os.path.isdir(subpath): - counter += upload_directory(subpath, conn, verbose=verbose, dryrun=dryrun) + counter += upload_directory(subpath, verbose=verbose, dryrun=dryrun) else: - counter += upload_file(subpath, conn, verbose=verbose, dryrun=dryrun) + counter += upload_file(subpath, verbose=verbose, dryrun=dryrun) return counter def do_upload(path, verbose=True, dryrun=False): - conn = get_or_initialize_aws_connection() counter = 0 start = time.time() if os.path.isdir(path): - counter += upload_directory(path, conn, verbose=verbose, dryrun=dryrun) + counter += upload_directory(path, verbose=verbose, dryrun=dryrun) else: - counter += upload_file(path, conn, verbose=verbose, dryrun=dryrun) + counter += upload_file(path, verbose=verbose, dryrun=dryrun) s_took = (time.time() - start) |
