28
28
import os
29
29
import sys
30
30
31
- PATH = os .path .dirname (os .path .dirname (os .path .realpath (__file__ ))) # Primary openshot folder
32
-
33
31
import datetime
34
32
import platform
35
33
import shutil
44
42
from requests .auth import HTTPBasicAuth
45
43
from requests import post
46
44
45
+ PATH = os .path .dirname (os .path .dirname (os .path .realpath (__file__ ))) # Primary openshot folder
46
+
47
47
# Access info class (for version info)
48
48
sys .path .append (os .path .join (PATH , 'src' , 'classes' ))
49
49
import info
@@ -82,7 +82,7 @@ def output(line):
82
82
83
83
def run_command (command , working_dir = None ):
84
84
"""Utility function to return output from command line"""
85
- short_command = command .split ('" ' )[0 ] # We don't need to print args
85
+ short_command = command .split ('" ' )[0 ] # We don't need to print args
86
86
output ("Running %s... (%s)" % (short_command , working_dir ))
87
87
p = subprocess .Popen (command , shell = True , cwd = working_dir ,
88
88
stdout = subprocess .PIPE ,
@@ -147,6 +147,7 @@ def zulip_upload_log(log, title, comment=None):
147
147
log = open (log_path , "a" )
148
148
print (resp )
149
149
150
+
150
151
def get_release (repo , tag_name ):
151
152
"""Fetch the GitHub release tagged with the given tag and return it
152
153
@param repo: github3 repository object
@@ -156,41 +157,49 @@ def get_release(repo, tag_name):
156
157
if release .tag_name == tag_name :
157
158
return release
158
159
160
+
159
161
def upload (file_path , github_release ):
160
162
"""Upload a file to GitHub (retry 3 times)"""
163
+ if not s3_connection :
164
+ return None
165
+
161
166
url = None
162
- if s3_connection :
163
- folder_path , file_name = os .path .split (file_path )
164
-
165
- # Check if this asset is already uploaded
166
- for asset in github_release .assets :
167
- if asset .name == file_name :
168
- raise Exception ('Duplicate asset already uploaded: %s (%s)' % (file_path , asset .to_json ()["browser_download_url" ]))
169
-
170
- for attempt in range (3 ):
171
- try :
172
- # Attempt the upload
173
- with open (file_path , "rb" ) as f :
174
- # Upload to GitHub
175
- asset = github_release .upload_asset ("application/octet-stream" , file_name , f )
176
- url = asset .to_json ()["browser_download_url" ]
177
- # Successfully uploaded!
178
- break
179
- except Exception as ex :
180
- # Quietly fail, and try again
181
- if attempt < 2 :
182
- output ("Upload failed... trying again" )
183
- else :
184
- # Throw loud exception
185
- raise Exception ('Upload failed. Verify that this file is not already uploaded: %s' % file_path , ex )
167
+ file_name = os .path .basename (file_path )
168
+
169
+ # Check if this asset is already uploaded
170
+ for asset in github_release .assets :
171
+ if asset .name == file_name :
172
+ raise Exception ('Duplicate asset already uploaded: %s (%s)' % (file_path , asset .to_json ()["browser_download_url" ]))
173
+
174
+ for attempt in range (3 ):
175
+ try :
176
+ # Attempt the upload
177
+ with open (file_path , "rb" ) as f :
178
+ # Upload to GitHub
179
+ asset = github_release .upload_asset ("application/octet-stream" , file_name , f )
180
+ url = asset .to_json ()["browser_download_url" ]
181
+ # Successfully uploaded!
182
+ break
183
+ except Exception as ex :
184
+ # Quietly fail, and try again
185
+ if attempt < 2 :
186
+ output ("Upload failed... trying again" )
187
+ else :
188
+ # Throw loud exception
189
+ raise Exception ('Upload failed. Verify that this file is not already uploaded: %s' % file_path , ex )
186
190
187
191
return url
188
192
193
+
189
194
def parse_version_info (version_path ):
190
195
"""Parse version info from gitlab artifacts"""
191
196
# Get name of version file
192
197
version_name = os .path .split (version_path )[1 ]
193
- version_info [version_name ] = {"CI_PROJECT_NAME" : None , "CI_COMMIT_REF_NAME" : None , "CI_COMMIT_SHA" : None , "CI_JOB_ID" : None }
198
+ version_info [version_name ] = {
199
+ "CI_PROJECT_NAME" : None ,
200
+ "CI_COMMIT_REF_NAME" : None ,
201
+ "CI_COMMIT_SHA" : None ,
202
+ "CI_JOB_ID" : None }
194
203
195
204
if os .path .exists (version_path ):
196
205
with open (version_path , "r" ) as f :
@@ -221,7 +230,7 @@ def parse_version_info(version_path):
221
230
gh = login (github_user , github_pass )
222
231
repo = gh .repository ("OpenShot" , "openshot-qt" )
223
232
224
- if len (sys .argv ) >= 9 :
233
+ if len (sys .argv ) >= 9 :
225
234
windows_32bit = False
226
235
if sys .argv [8 ] == 'True' :
227
236
windows_32bit = True
@@ -314,30 +323,36 @@ def parse_version_info(version_path):
314
323
exe_dir = exe_path
315
324
break
316
325
317
- # Create AppDir folder
318
326
app_dir_path = os .path .join (PATH , "build" , "OpenShot.AppDir" )
319
- os .mkdir (app_dir_path )
320
- os .mkdir (os .path .join (app_dir_path , "usr" ))
321
- os .mkdir (os .path .join (app_dir_path , "usr" , "share" ))
322
- os .mkdir (os .path .join (app_dir_path , "usr" , "share" , "pixmaps" ))
323
- os .mkdir (os .path .join (app_dir_path , "usr" , "share" , "mime" ))
324
- os .mkdir (os .path .join (app_dir_path , "usr" , "share" , "mime" , "packages" ))
327
+
328
+ # Recursively create AppDir /usr folder
329
+ os .makedirs (os .path .join (app_dir_path , "usr" ), exist_ok = True )
325
330
326
331
# Create AppRun file
327
332
app_run_path = os .path .join (app_dir_path , "AppRun" )
328
- shutil .copyfile ("/home/ubuntu/apps/AppImageKit/AppRun" , app_run_path )
333
+ # XXX: Temporary: Use new AppRun binary in project repo
334
+ shutil .copyfile (os .path .join (PATH , "installer" , "AppRun.64" ), app_run_path )
329
335
330
- # Copy some installation-related files
336
+ # Install program icon
331
337
shutil .copyfile (os .path .join (PATH , "xdg" , "openshot-qt.svg" ),
332
- os .path .join (app_dir_path , "openshot-qt.svg" ))
338
+ os .path .join (app_dir_path , "openshot-qt.svg" ))
339
+
340
+ dest = os .path .join (app_dir_path , "usr" , "share" , "pixmaps" )
341
+ os .makedirs (dest , exist_ok = True )
342
+
333
343
shutil .copyfile (os .path .join (PATH , "xdg" , "openshot-qt.svg" ),
334
- os .path .join (app_dir_path , "usr" , "share" , "pixmaps" , "openshot-qt.svg" ))
344
+ os .path .join (dest , "openshot-qt.svg" ))
345
+
346
+ # Install MIME handler
347
+ dest = os .path .join (app_dir_path , "usr" , "share" , "mime" , "packages" )
348
+ os .makedirs (dest , exist_ok = True )
349
+
335
350
shutil .copyfile (os .path .join (PATH , "xdg" , "org.openshot.OpenShot.xml" ),
336
- os .path .join (app_dir_path , "usr" , "share" , "mime" , "packages" , "org.openshot.OpenShot.xml" ))
351
+ os .path .join (dest , "org.openshot.OpenShot.xml" ))
337
352
338
353
# Copy the entire frozen app
339
354
shutil .copytree (os .path .join (PATH , "build" , exe_dir ),
340
- os .path .join (app_dir_path , "usr" , "bin" ))
355
+ os .path .join (app_dir_path , "usr" , "bin" ))
341
356
342
357
# Copy .desktop file, replacing Exec= commandline
343
358
desk_in = os .path .join (PATH , "xdg" , "org.openshot.OpenShot.desktop" )
@@ -355,7 +370,7 @@ def parse_version_info(version_path):
355
370
desktop_wrapper = os .path .join (app_dir_path , "usr" , "bin" , "openshot-qt.wrapper" )
356
371
shutil .copyfile ("/home/ubuntu/apps/AppImageKit/desktopintegration" , desktop_wrapper )
357
372
358
- # Change permission of AppRun (and desktop.wrapper) file (add execute permission)
373
+ # Add execute bit to file mode for AppRun and scripts
359
374
st = os .stat (app_run_path )
360
375
os .chmod (app_run_path , st .st_mode | stat .S_IEXEC )
361
376
os .chmod (desktop_wrapper , st .st_mode | stat .S_IEXEC )
0 commit comments