Skip to content

Commit 5d4f3ca

Browse files
author
Joseph Atkins-Turkish
committed
Remove support for AWS_ENABLED==False
1 parent 86fb8be commit 5d4f3ca

File tree

10 files changed

+25
-128
lines changed

10 files changed

+25
-128
lines changed

app.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"AWS_ACCESS_KEY_ID": {
88
"required": true
99
},
10-
"AWS_ENABLED": "yes",
1110
"AWS_S3_BUILDS_BUCKET": "builds-staging.cloudpebble.net",
1211
"AWS_S3_EXPORT_BUCKET": "export-staging.cloudpebble.net",
1312
"AWS_S3_SOURCE_BUCKET": "source-staging.cloudpebble.net",

cloudpebble/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@
341341
MAILCHIMP_API_KEY = _environ.get('MAILCHIMP_API_KEY', None)
342342
MAILCHIMP_LIST_ID = _environ.get('MAILCHIMP_LIST_ID', None)
343343

344-
AWS_ENABLED = 'AWS_ENABLED' in _environ
345344
AWS_ACCESS_KEY_ID = _environ.get('AWS_ACCESS_KEY_ID', None)
346345
AWS_SECRET_ACCESS_KEY = _environ.get('AWS_SECRET_ACCESS_KEY', None)
347346

ide/api/project.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ def save_project_dependencies(request, project_id):
263263
else:
264264
send_td_event('cloudpebble_save_project_settings', request=request, project=project)
265265

266+
266267
@require_POST
267268
@login_required
268269
@json_view

ide/api/resource.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
from django.conf import settings
32
from django.contrib.auth.decorators import login_required
43
from django.db import transaction, IntegrityError
54
from django.http import HttpResponse, HttpResponseRedirect
@@ -238,13 +237,8 @@ def show_resource(request, project_id, resource_id, variant):
238237
}
239238
content_disposition = "attachment; filename=\"%s\"" % resource.file_name
240239
content_type = content_types[resource.kind]
241-
if settings.AWS_ENABLED:
242-
headers = {
243-
'response-content-disposition': content_disposition,
244-
'Content-Type': content_type
245-
}
246-
return HttpResponseRedirect(s3.get_signed_url('source', variant.s3_path, headers=headers))
247-
else:
248-
response = HttpResponse(open(variant.local_filename), content_type=content_type)
249-
response['Content-Disposition'] = content_disposition
250-
return response
240+
headers = {
241+
'response-content-disposition': content_disposition,
242+
'Content-Type': content_type
243+
}
244+
return HttpResponseRedirect(s3.get_signed_url('source', variant.s3_path, headers=headers))

ide/models/build.py

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import uuid
22
import json
3-
import shutil
4-
import os
5-
import os.path
63
from django.conf import settings
74
from django.db import models
85
from ide.models.project import Project
@@ -42,19 +39,10 @@ class BuildResult(IdeModel):
4239
finished = models.DateTimeField(blank=True, null=True)
4340

4441
def _get_dir(self):
45-
if settings.AWS_ENABLED:
46-
return '%s/' % self.uuid
47-
else:
48-
path = '%s%s/%s/%s/' % (settings.MEDIA_ROOT, self.uuid[0], self.uuid[1], self.uuid)
49-
if not os.path.exists(path):
50-
os.makedirs(path)
51-
return path
42+
return '%s/' % self.uuid
5243

5344
def get_url(self):
54-
if settings.AWS_ENABLED:
55-
return "%s%s/" % (settings.MEDIA_URL, self.uuid)
56-
else:
57-
return '%s%s/%s/%s/' % (settings.MEDIA_URL, self.uuid[0], self.uuid[1], self.uuid)
45+
return "%s%s/" % (settings.MEDIA_URL, self.uuid)
5846

5947
@property
6048
def pbw(self):
@@ -88,26 +76,14 @@ def get_debug_info_filename(self, platform, kind):
8876
return self._get_dir() + self.DEBUG_INFO_MAP[platform][kind]
8977

9078
def save_build_log(self, text):
91-
if not settings.AWS_ENABLED:
92-
with open(self.build_log, 'w') as f:
93-
f.write(text)
94-
else:
95-
s3.save_file('builds', self.build_log, text, public=True, content_type='text/plain')
79+
s3.save_file('builds', self.build_log, text, public=True, content_type='text/plain')
9680

9781
def read_build_log(self):
98-
if not settings.AWS_ENABLED:
99-
with open(self.build_log, 'r') as f:
100-
return f.read()
101-
else:
102-
return s3.read_file('builds', self.build_log)
82+
return s3.read_file('builds', self.build_log)
10383

10484
def save_debug_info(self, json_info, platform, kind):
10585
text = json.dumps(json_info)
106-
if not settings.AWS_ENABLED:
107-
with open(self.get_debug_info_filename(platform, kind), 'w') as f:
108-
f.write(text)
109-
else:
110-
s3.save_file('builds', self.get_debug_info_filename(platform, kind), text, public=True, content_type='application/json')
86+
s3.save_file('builds', self.get_debug_info_filename(platform, kind), text, public=True, content_type='application/json')
11187

11288
def save_package(self, package_path):
11389
if not settings.AWS_ENABLED:
@@ -117,17 +93,10 @@ def save_package(self, package_path):
11793
s3.upload_file('builds', self.package, package_path, public=True, download_filename=filename, content_type='application/gzip')
11894

11995
def save_pbw(self, pbw_path):
120-
if not settings.AWS_ENABLED:
121-
shutil.move(pbw_path, self.pbw)
122-
else:
123-
s3.upload_file('builds', self.pbw, pbw_path, public=True, download_filename='%s.pbw' % self.project.app_short_name.replace('/','-'))
96+
s3.upload_file('builds', self.pbw, pbw_path, public=True, download_filename='%s.pbw' % self.project.app_short_name.replace('/','-'))
12497

12598
def save_simplyjs(self, javascript):
126-
if not settings.AWS_ENABLED:
127-
with open(self.simplyjs, 'w') as f:
128-
f.write(javascript)
129-
else:
130-
s3.save_file('builds', self.simplyjs, javascript, public=True, content_type='text/javascript')
99+
s3.save_file('builds', self.simplyjs, javascript, public=True, content_type='text/javascript')
131100

132101
def get_sizes(self):
133102
sizes = {}

ide/models/meta.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.db.models.signals import pre_save
33
from django.dispatch import receiver
44

5+
56
class IdeModel(models.Model):
67
class Meta:
78
abstract = True

ide/models/s3file.py

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import shutil
2-
import os
31
import logging
42

53
from django.utils.translation import ugettext as _
@@ -18,7 +16,6 @@ class S3File(IdeModel):
1816
bucket_name = 'source'
1917
folder = None
2018
project = None
21-
_create_local_if_not_exists = False
2219

2320
@property
2421
def padded_id(self):
@@ -37,41 +34,11 @@ def s3_id(self):
3734
def s3_path(self):
3835
return '%s/%s' % (self.folder, self.s3_id)
3936

40-
def _get_contents_local(self):
41-
try:
42-
return open(self.local_filename).read()
43-
except IOError:
44-
if self._create_local_if_not_exists:
45-
return ''
46-
else:
47-
raise
48-
49-
def _save_string_local(self, string):
50-
if not os.path.exists(os.path.dirname(self.local_filename)):
51-
os.makedirs(os.path.dirname(self.local_filename))
52-
with open(self.local_filename, 'wb') as out:
53-
out.write(string)
54-
55-
def _copy_to_path_local(self, path):
56-
try:
57-
shutil.copy(self.local_filename, path)
58-
except IOError as err:
59-
if err.errno == 2 and self._crete_local_if_not_exists:
60-
open(path, 'w').close() # create the file if it's missing.
61-
else:
62-
raise
63-
6437
def get_contents(self):
65-
if not settings.AWS_ENABLED:
66-
return self._get_contents_local()
67-
else:
68-
return s3.read_file(self.bucket_name, self.s3_path)
38+
return s3.read_file(self.bucket_name, self.s3_path)
6939

7040
def save_string(self, string):
71-
if not settings.AWS_ENABLED:
72-
self._save_string_local(string)
73-
else:
74-
s3.save_file(self.bucket_name, self.s3_path, string)
41+
s3.save_file(self.bucket_name, self.s3_path, string)
7542
if self.project:
7643
self.project.last_modified = now()
7744
self.project.save()
@@ -85,10 +52,7 @@ def save_text(self, content):
8552
self.save_string(content.encode('utf-8'))
8653

8754
def copy_to_path(self, path):
88-
if not settings.AWS_ENABLED:
89-
self._copy_to_path_local(path)
90-
else:
91-
s3.read_file_to_filesystem(self.bucket_name, self.s3_path, path)
55+
s3.read_file_to_filesystem(self.bucket_name, self.s3_path, path)
9256

9357
class Meta(IdeModel.Meta):
9458
abstract = True
@@ -97,13 +61,7 @@ class Meta(IdeModel.Meta):
9761
@receiver(post_delete)
9862
def delete_file(sender, instance, **kwargs):
9963
if issubclass(sender, S3File):
100-
if settings.AWS_ENABLED:
101-
try:
102-
s3.delete_file(sender.bucket_name, instance.s3_path)
103-
except:
104-
logger.exception("Failed to delete S3 file")
105-
else:
106-
try:
107-
os.unlink(instance.local_filename)
108-
except OSError:
109-
pass
64+
try:
65+
s3.delete_file(sender.bucket_name, instance.s3_path)
66+
except:
67+
logger.exception("Failed to delete S3 file")

ide/models/textfile.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class TextFile(S3File):
1010
""" TextFile adds support to S3File for last-modified timestamps and code folding """
1111
last_modified = models.DateTimeField(blank=True, null=True, auto_now=True)
1212
folded_lines = models.TextField(default="[]")
13-
_create_local_if_not_exists = True
1413

1514
def was_modified_since(self, expected_modification_time):
1615
if isinstance(expected_modification_time, int):

ide/tasks/archive.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,9 @@ def create_archive(project_id):
6161

6262
send_td_event('cloudpebble_export_project', project=project)
6363

64-
if not settings.AWS_ENABLED:
65-
outfile = '%s%s/%s.zip' % (settings.EXPORT_DIRECTORY, u, prefix)
66-
os.makedirs(os.path.dirname(outfile), 0755)
67-
shutil.copy(filename, outfile)
68-
os.chmod(outfile, 0644)
69-
return '%s%s/%s.zip' % (settings.EXPORT_ROOT, u, prefix)
70-
else:
71-
outfile = '%s/%s.zip' % (u, prefix)
72-
s3.upload_file('export', outfile, filename, public=True, content_type='application/zip')
73-
return '%s%s' % (settings.EXPORT_ROOT, outfile)
64+
outfile = '%s/%s.zip' % (u, prefix)
65+
s3.upload_file('export', outfile, filename, public=True, content_type='application/zip')
66+
return '%s%s' % (settings.EXPORT_ROOT, outfile)
7467

7568

7669
@task(acks_late=True)
@@ -309,4 +302,4 @@ def make_valid_filename(zip_entry):
309302
'reason': str(e)
310303
}
311304
}, user=project.owner)
312-
raise
305+
raise

utils/s3.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,38 +70,24 @@ def __getitem__(self, item):
7070
_buckets = BucketHolder()
7171

7272

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
8473
def read_file(bucket_name, path):
8574
bucket = _buckets[bucket_name]
8675
key = bucket.get_key(path)
8776
return key.get_contents_as_string()
8877

8978

90-
@_requires_aws
9179
def read_file_to_filesystem(bucket_name, path, destination):
9280
bucket = _buckets[bucket_name]
9381
key = bucket.get_key(path)
9482
key.get_contents_to_filename(destination)
9583

9684

97-
@_requires_aws
9885
def delete_file(bucket_name, path):
9986
bucket = _buckets[bucket_name]
10087
key = bucket.get_key(path)
10188
key.delete()
10289

10390

104-
@_requires_aws
10591
def save_file(bucket_name, path, value, public=False, content_type='application/octet-stream'):
10692
bucket = _buckets[bucket_name]
10793
key = Key(bucket)
@@ -115,7 +101,6 @@ def save_file(bucket_name, path, value, public=False, content_type='application/
115101
key.set_contents_from_string(value, policy=policy, headers={'Content-Type': content_type})
116102

117103

118-
@_requires_aws
119104
def upload_file(bucket_name, dest_path, src_path, public=False, content_type='application/octet-stream',
120105
download_filename=None):
121106
bucket = _buckets[bucket_name]
@@ -137,7 +122,6 @@ def upload_file(bucket_name, dest_path, src_path, public=False, content_type='ap
137122
key.set_contents_from_filename(src_path, policy=policy, headers=headers)
138123

139124

140-
@_requires_aws
141125
def get_signed_url(bucket_name, path, headers=None):
142126
bucket = _buckets[bucket_name]
143127
key = bucket.get_key(path)

0 commit comments

Comments
 (0)