11import uuid
22import json
3- import shutil
4- import os
5- import os .path
63from django .conf import settings
74from django .db import models
85from ide .models .project import Project
@@ -40,19 +37,10 @@ class BuildResult(IdeModel):
4037 finished = models .DateTimeField (blank = True , null = True )
4138
4239 def _get_dir (self ):
43- if settings .AWS_ENABLED :
44- return '%s/' % self .uuid
45- else :
46- path = '%s%s/%s/%s/' % (settings .MEDIA_ROOT , self .uuid [0 ], self .uuid [1 ], self .uuid )
47- if not os .path .exists (path ):
48- os .makedirs (path )
49- return path
40+ return '%s/' % self .uuid
5041
5142 def get_url (self ):
52- if settings .AWS_ENABLED :
53- return "%s%s/" % (settings .MEDIA_URL , self .uuid )
54- else :
55- return '%s%s/%s/%s/' % (settings .MEDIA_URL , self .uuid [0 ], self .uuid [1 ], self .uuid )
43+ return "%s%s/" % (settings .MEDIA_URL , self .uuid )
5644
5745 def get_pbw_filename (self ):
5846 return '%swatchface.pbw' % self ._get_dir ()
@@ -79,39 +67,20 @@ def get_simplyjs_url(self):
7967 return '%ssimply.js' % self .get_url ()
8068
8169 def save_build_log (self , text ):
82- if not settings .AWS_ENABLED :
83- with open (self .build_log , 'w' ) as f :
84- f .write (text )
85- else :
86- s3 .save_file ('builds' , self .build_log , text , public = True , content_type = 'text/plain' )
70+ s3 .save_file ('builds' , self .build_log , text , public = True , content_type = 'text/plain' )
8771
8872 def read_build_log (self ):
89- if not settings .AWS_ENABLED :
90- with open (self .build_log , 'r' ) as f :
91- return f .read ()
92- else :
93- return s3 .read_file ('builds' , self .build_log )
73+ return s3 .read_file ('builds' , self .build_log )
9474
9575 def save_debug_info (self , json_info , platform , kind ):
9676 text = json .dumps (json_info )
97- if not settings .AWS_ENABLED :
98- with open (self .get_debug_info_filename (platform , kind ), 'w' ) as f :
99- f .write (text )
100- else :
101- s3 .save_file ('builds' , self .get_debug_info_filename (platform , kind ), text , public = True , content_type = 'application/json' )
77+ s3 .save_file ('builds' , self .get_debug_info_filename (platform , kind ), text , public = True , content_type = 'application/json' )
10278
10379 def save_pbw (self , pbw_path ):
104- if not settings .AWS_ENABLED :
105- shutil .move (pbw_path , self .pbw )
106- else :
107- s3 .upload_file ('builds' , self .pbw , pbw_path , public = True , download_filename = '%s.pbw' % self .project .app_short_name .replace ('/' ,'-' ))
80+ s3 .upload_file ('builds' , self .pbw , pbw_path , public = True , download_filename = '%s.pbw' % self .project .app_short_name .replace ('/' ,'-' ))
10881
10982 def save_simplyjs (self , javascript ):
110- if not settings .AWS_ENABLED :
111- with open (self .simplyjs , 'w' ) as f :
112- f .write (javascript )
113- else :
114- s3 .save_file ('builds' , self .simplyjs , javascript , public = True , content_type = 'text/javascript' )
83+ s3 .save_file ('builds' , self .simplyjs , javascript , public = True , content_type = 'text/javascript' )
11584
11685 pbw = property (get_pbw_filename )
11786 build_log = property (get_build_log )
0 commit comments