@@ -27,37 +27,33 @@ def __init__(self):
2727 self .s3 = None
2828
2929 def configure (self ):
30- if settings .AWS_ENABLED :
31- if settings .AWS_S3_FAKE_S3 is None :
32- # The host must be manually specified in Python 2.7.9+ due to
33- # https://github.com/boto/boto/issues/2836 this bug in boto with .s in
34- # bucket names.
35- host = settings .AWS_S3_HOST if settings .AWS_S3_HOST else NoHostProvided
36-
37- self .s3 = boto .connect_s3 (
38- settings .AWS_ACCESS_KEY_ID ,
39- settings .AWS_SECRET_ACCESS_KEY ,
40- host = host ,
41- calling_format = OrdinaryCallingFormat ()
42- )
43- else :
44- host , port = (settings .AWS_S3_FAKE_S3 .split (':' , 2 ) + [80 ])[:2 ]
45- port = int (port )
46- self .s3 = boto .connect_s3 ("key_id" , "secret_key" , is_secure = False , port = port ,
47- host = host , calling_format = OrdinaryCallingFormat ())
48- _ensure_bucket_exists (self .s3 , settings .AWS_S3_SOURCE_BUCKET )
49- _ensure_bucket_exists (self .s3 , settings .AWS_S3_EXPORT_BUCKET )
50- _ensure_bucket_exists (self .s3 , settings .AWS_S3_BUILDS_BUCKET )
51-
52- self .buckets = {
53- 'source' : self .s3 .get_bucket (settings .AWS_S3_SOURCE_BUCKET ),
54- 'export' : self .s3 .get_bucket (settings .AWS_S3_EXPORT_BUCKET ),
55- 'builds' : self .s3 .get_bucket (settings .AWS_S3_BUILDS_BUCKET ),
56- }
57- self .configured = True
30+ if settings .AWS_S3_FAKE_S3 is None :
31+ # The host must be manually specified in Python 2.7.9+ due to
32+ # https://github.com/boto/boto/issues/2836 this bug in boto with .s in
33+ # bucket names.
34+ host = settings .AWS_S3_HOST if settings .AWS_S3_HOST else NoHostProvided
35+
36+ self .s3 = boto .connect_s3 (
37+ settings .AWS_ACCESS_KEY_ID ,
38+ settings .AWS_SECRET_ACCESS_KEY ,
39+ host = host ,
40+ calling_format = OrdinaryCallingFormat ()
41+ )
5842 else :
59- self .s3 = None
60- self .buckets = None
43+ host , port = (settings .AWS_S3_FAKE_S3 .split (':' , 2 ) + [80 ])[:2 ]
44+ port = int (port )
45+ self .s3 = boto .connect_s3 ("key_id" , "secret_key" , is_secure = False , port = port ,
46+ host = host , calling_format = OrdinaryCallingFormat ())
47+ _ensure_bucket_exists (self .s3 , settings .AWS_S3_SOURCE_BUCKET )
48+ _ensure_bucket_exists (self .s3 , settings .AWS_S3_EXPORT_BUCKET )
49+ _ensure_bucket_exists (self .s3 , settings .AWS_S3_BUILDS_BUCKET )
50+
51+ self .buckets = {
52+ 'source' : self .s3 .get_bucket (settings .AWS_S3_SOURCE_BUCKET ),
53+ 'export' : self .s3 .get_bucket (settings .AWS_S3_EXPORT_BUCKET ),
54+ 'builds' : self .s3 .get_bucket (settings .AWS_S3_BUILDS_BUCKET ),
55+ }
56+ self .configured = True
6157
6258 def __getitem__ (self , item ):
6359 if settings .TESTING :
@@ -70,38 +66,24 @@ def __getitem__(self, item):
7066_buckets = BucketHolder ()
7167
7268
73- def _requires_aws (fn ):
74- if settings .AWS_ENABLED :
75- return fn
76- else :
77- def complain (* args , ** kwargs ):
78- raise Exception ("AWS_ENABLED must be True to call %s" % fn .__name__ )
79-
80- return complain
81-
82-
83- @_requires_aws
8469def read_file (bucket_name , path ):
8570 bucket = _buckets [bucket_name ]
8671 key = bucket .get_key (path )
8772 return key .get_contents_as_string ()
8873
8974
90- @_requires_aws
9175def read_file_to_filesystem (bucket_name , path , destination ):
9276 bucket = _buckets [bucket_name ]
9377 key = bucket .get_key (path )
9478 key .get_contents_to_filename (destination )
9579
9680
97- @_requires_aws
9881def delete_file (bucket_name , path ):
9982 bucket = _buckets [bucket_name ]
10083 key = bucket .get_key (path )
10184 key .delete ()
10285
10386
104- @_requires_aws
10587def save_file (bucket_name , path , value , public = False , content_type = 'application/octet-stream' ):
10688 bucket = _buckets [bucket_name ]
10789 key = Key (bucket )
@@ -115,7 +97,6 @@ def save_file(bucket_name, path, value, public=False, content_type='application/
11597 key .set_contents_from_string (value , policy = policy , headers = {'Content-Type' : content_type })
11698
11799
118- @_requires_aws
119100def upload_file (bucket_name , dest_path , src_path , public = False , content_type = 'application/octet-stream' ,
120101 download_filename = None ):
121102 bucket = _buckets [bucket_name ]
@@ -137,7 +118,6 @@ def upload_file(bucket_name, dest_path, src_path, public=False, content_type='ap
137118 key .set_contents_from_filename (src_path , policy = policy , headers = headers )
138119
139120
140- @_requires_aws
141121def get_signed_url (bucket_name , path , headers = None ):
142122 bucket = _buckets [bucket_name ]
143123 key = bucket .get_key (path )
0 commit comments