Skip to content

Commit 7eafbde

Browse files
committed
Changes to build-server for new AppRun
1 parent fea2c3f commit 7eafbde

File tree

1 file changed

+58
-43
lines changed

1 file changed

+58
-43
lines changed

installer/build-server.py

+58-43
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import os
2929
import sys
3030

31-
PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) # Primary openshot folder
32-
3331
import datetime
3432
import platform
3533
import shutil
@@ -44,6 +42,8 @@
4442
from requests.auth import HTTPBasicAuth
4543
from requests import post
4644

45+
PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) # Primary openshot folder
46+
4747
# Access info class (for version info)
4848
sys.path.append(os.path.join(PATH, 'src', 'classes'))
4949
import info
@@ -82,7 +82,7 @@ def output(line):
8282

8383
def run_command(command, working_dir=None):
8484
"""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
8686
output("Running %s... (%s)" % (short_command, working_dir))
8787
p = subprocess.Popen(command, shell=True, cwd=working_dir,
8888
stdout=subprocess.PIPE,
@@ -147,6 +147,7 @@ def zulip_upload_log(log, title, comment=None):
147147
log = open(log_path, "a")
148148
print(resp)
149149

150+
150151
def get_release(repo, tag_name):
151152
"""Fetch the GitHub release tagged with the given tag and return it
152153
@param repo: github3 repository object
@@ -156,41 +157,49 @@ def get_release(repo, tag_name):
156157
if release.tag_name == tag_name:
157158
return release
158159

160+
159161
def upload(file_path, github_release):
160162
"""Upload a file to GitHub (retry 3 times)"""
163+
if not s3_connection:
164+
return None
165+
161166
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)
186190

187191
return url
188192

193+
189194
def parse_version_info(version_path):
190195
"""Parse version info from gitlab artifacts"""
191196
# Get name of version file
192197
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}
194203

195204
if os.path.exists(version_path):
196205
with open(version_path, "r") as f:
@@ -221,7 +230,7 @@ def parse_version_info(version_path):
221230
gh = login(github_user, github_pass)
222231
repo = gh.repository("OpenShot", "openshot-qt")
223232

224-
if len(sys.argv) >=9:
233+
if len(sys.argv) >= 9:
225234
windows_32bit = False
226235
if sys.argv[8] == 'True':
227236
windows_32bit = True
@@ -314,30 +323,36 @@ def parse_version_info(version_path):
314323
exe_dir = exe_path
315324
break
316325

317-
# Create AppDir folder
318326
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)
325330

326331
# Create AppRun file
327332
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)
329335

330-
# Copy some installation-related files
336+
# Install program icon
331337
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+
333343
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+
335350
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"))
337352

338353
# Copy the entire frozen app
339354
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"))
341356

342357
# Copy .desktop file, replacing Exec= commandline
343358
desk_in = os.path.join(PATH, "xdg", "org.openshot.OpenShot.desktop")
@@ -355,7 +370,7 @@ def parse_version_info(version_path):
355370
desktop_wrapper = os.path.join(app_dir_path, "usr", "bin", "openshot-qt.wrapper")
356371
shutil.copyfile("/home/ubuntu/apps/AppImageKit/desktopintegration", desktop_wrapper)
357372

358-
# Change permission of AppRun (and desktop.wrapper) file (add execute permission)
373+
# Add execute bit to file mode for AppRun and scripts
359374
st = os.stat(app_run_path)
360375
os.chmod(app_run_path, st.st_mode | stat.S_IEXEC)
361376
os.chmod(desktop_wrapper, st.st_mode | stat.S_IEXEC)

0 commit comments

Comments
 (0)