From 72a52b6f344c7918445dad20e5a41358b3eb46ac Mon Sep 17 00:00:00 2001 From: Valentin Niess Date: Mon, 10 Feb 2025 18:31:05 +0100 Subject: [PATCH] Select appimagetool version --- python_appimage/__main__.py | 6 +++++ python_appimage/appimage/build.py | 9 ++++--- python_appimage/utils/deps.py | 43 ++++++++++++++++++++++++------- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/python_appimage/__main__.py b/python_appimage/__main__.py index 62458d0..a6491ca 100644 --- a/python_appimage/__main__.py +++ b/python_appimage/__main__.py @@ -27,6 +27,8 @@ def main(): help='Command to execute', dest='command') + parser.add_argument('-a', '--appimagetool-version', + help='set appimagetool version') parser.add_argument('-q', '--quiet', help='disable logging', dest='verbosity', action='store_const', const='ERROR') parser.add_argument('-v', '--verbose', help='print extra information', @@ -98,6 +100,10 @@ def main(): from .utils import log log.set_level(args.verbosity) + if args.appimagetool_version: + from .utils import deps + deps.APPIMAGETOOL_VERSION = args.appimagetool_version + # check if no arguments are passed if args.command is None: parser.print_help() diff --git a/python_appimage/appimage/build.py b/python_appimage/appimage/build.py index a57ed0d..2538125 100644 --- a/python_appimage/appimage/build.py +++ b/python_appimage/appimage/build.py @@ -5,7 +5,7 @@ import subprocess import sys from ..utils.compat import decode -from ..utils.deps import APPIMAGETOOL, ensure_appimagetool +from ..utils.deps import ensure_appimagetool from ..utils.docker import docker_run from ..utils.fs import copy_tree from ..utils.log import debug, log @@ -22,10 +22,10 @@ def build_appimage(appdir=None, destination=None): appdir = 'AppDir' log('BUILD', appdir) - ensure_appimagetool() + appimagetool = ensure_appimagetool() arch = platform.machine() - cmd = ['ARCH=' + arch, APPIMAGETOOL, '--no-appstream', appdir] + cmd = ['ARCH=' + arch, appimagetool, '--no-appstream', appdir] if destination is not None: cmd.append(destination) cmd = ' '.join(cmd) @@ -45,7 +45,8 @@ def build_appimage(appdir=None, destination=None): elif out: out = out.replace('%', '%%')[:-1] for line in out.split(os.linesep): - if line.startswith('WARNING'): + if line.startswith('WARNING') and \ + not line[9:].startswith('zsyncmake command is missing'): log('WARNING', line[9:]) elif line.startswith('Error'): raise RuntimeError(line) diff --git a/python_appimage/utils/deps.py b/python_appimage/utils/deps.py index bba9790..e36e9b2 100644 --- a/python_appimage/utils/deps.py +++ b/python_appimage/utils/deps.py @@ -19,31 +19,56 @@ _ARCH = platform.machine() PREFIX = os.path.abspath(os.path.dirname(__file__) + '/..') '''Package installation prefix''' -APPIMAGETOOL = os.path.expanduser('~/.local/bin/appimagetool') +APPIMAGETOOL_DIR = os.path.expanduser('~/.local/bin') '''Location of the appimagetool binary''' +APPIMAGETOOL_VERSION = '12' +'''Version of the appimagetool binary''' + EXCLUDELIST = PREFIX + '/data/excludelist' '''AppImage exclusion list''' PATCHELF = os.path.expanduser('~/.local/bin/patchelf') '''Location of the PatchELF binary''' - def ensure_appimagetool(): '''Fetch appimagetool from the web if not available locally ''' - if os.path.exists(APPIMAGETOOL): - return False + if APPIMAGETOOL_VERSION == '12': + appimagetool_name = 'appimagetool' + else: + appimagetool_name = 'appimagetool-' + APPIMAGETOOL_VERSION + appimagetool = os.path.join(APPIMAGETOOL_DIR, appimagetool_name) + appdir_name = '.'.join(('', appimagetool_name, 'appdir', _ARCH)) + appdir = os.path.join(APPIMAGETOOL_DIR, appdir_name) + apprun = os.path.join(appdir, 'AppRun') + + if os.path.exists(apprun): + return apprun appimage = 'appimagetool-{0:}.AppImage'.format(_ARCH) - baseurl = 'https://github.com/AppImage/appimagetool/releases/download/continuous' + + if APPIMAGETOOL_VERSION in map(str, range(1, 14)): + repository = 'AppImageKit' + else: + repository = 'appimagetool' + baseurl = os.path.join( + 'https://github.com/AppImage', + repository, + 'releases/download', + APPIMAGETOOL_VERSION + ) log('INSTALL', 'appimagetool from %s', baseurl) - make_tree(os.path.dirname(APPIMAGETOOL)) - urlretrieve(os.path.join(baseurl, appimage), APPIMAGETOOL) - os.chmod(APPIMAGETOOL, stat.S_IRWXU) + if not os.path.exists(appdir): + make_tree(os.path.dirname(appdir)) + with TemporaryDirectory() as tmpdir: + urlretrieve(os.path.join(baseurl, appimage), appimage) + os.chmod(appimage, stat.S_IRWXU) + system(('./' + appimage, '--appimage-extract')) + copy_tree('squashfs-root', appdir) - return True + return apprun # Installers for dependencies