mirror of
https://github.com/niess/python-appimage.git
synced 2026-03-13 20:00:19 +01:00
Add install command & reorganize
This commit is contained in:
@@ -11,24 +11,34 @@ __all__ = ['main']
|
||||
def main():
|
||||
# Parse arguments
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Bundle a Python install into an AppImage')
|
||||
subparsers = parser.add_subparsers(title='builder',
|
||||
help='Appimage builder',
|
||||
dest='builder')
|
||||
prog='python-appimage',
|
||||
description='Bundle a Python installation into an AppImage')
|
||||
subparsers = parser.add_subparsers(title='command',
|
||||
help='Build or install command',
|
||||
dest='command')
|
||||
|
||||
parser.add_argument('-q', '--quiet', help='disable logging',
|
||||
dest='verbosity', action='store_const', const=logging.ERROR)
|
||||
parser.add_argument('-v', '--verbose', help='print extra information',
|
||||
dest='verbosity', action='store_const', const=logging.DEBUG)
|
||||
|
||||
local_parser = subparsers.add_parser('local')
|
||||
install_parser = subparsers.add_parser('install',
|
||||
description='Install binary dependencies')
|
||||
install_parser.add_argument('binary', nargs='+',
|
||||
choices=('appimagetool', 'patchelf'), help='one or more binary name')
|
||||
|
||||
local_parser = subparsers.add_parser('local',
|
||||
description='Bundle a local Python installation')
|
||||
local_parser.add_argument('-d', '--destination',
|
||||
help='AppImage destination')
|
||||
local_parser.add_argument('-p', '--python', help='python executable')
|
||||
|
||||
manylinux_parser = subparsers.add_parser('manylinux')
|
||||
manylinux_parser.add_argument('tag', help='manylinux image tag')
|
||||
manylinux_parser.add_argument('abi', help='python ABI')
|
||||
manylinux_parser = subparsers.add_parser('manylinux',
|
||||
description='Bundle a manylinux Python installation using docker')
|
||||
manylinux_parser.add_argument('tag',
|
||||
help='manylinux image tag (e.g. 2010_x86_64)')
|
||||
manylinux_parser.add_argument('abi',
|
||||
help='python ABI (e.g. cp37-cp37m)')
|
||||
|
||||
manylinux_parser.add_argument('--contained', help=argparse.SUPPRESS,
|
||||
action='store_true', default=False)
|
||||
@@ -39,9 +49,10 @@ def main():
|
||||
if args.verbosity:
|
||||
logging.getLogger().setLevel(args.verbosity)
|
||||
|
||||
# Call the AppImage builder
|
||||
builder = import_module('.builders.' + args.builder, package=__package__)
|
||||
builder.build(*builder._unpack_args(args))
|
||||
# Call the requested command
|
||||
command = import_module('.commands.' +
|
||||
args.command, package=__package__)
|
||||
command.execute(*command._unpack_args(args))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
26
python_appimage/commands/install.py
Normal file
26
python_appimage/commands/install.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
|
||||
from ..utils import deps
|
||||
from ..utils.log import log
|
||||
|
||||
|
||||
|
||||
|
||||
__all__ = ['execute']
|
||||
|
||||
|
||||
def _unpack_args(args):
|
||||
'''Unpack command line arguments
|
||||
'''
|
||||
return args.binary
|
||||
|
||||
|
||||
def execute(*args):
|
||||
'''Install the requested dependencies
|
||||
'''
|
||||
bindir = os.path.dirname(deps.PATCHELF)
|
||||
for binary in args:
|
||||
installed = getattr(deps, 'ensure_' + binary)()
|
||||
words = 'has been' if installed else 'already'
|
||||
log('INSTALL',
|
||||
'{:} {:} installed in {:}'.format(binary, words, bindir))
|
||||
@@ -2,11 +2,11 @@ import glob
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from ..actions import build_appimage, relocate_python
|
||||
from ..appimage import build_appimage, relocate_python
|
||||
from ..utils.tmp import TemporaryDirectory
|
||||
|
||||
|
||||
__all__ = ['build']
|
||||
__all__ = ['execute']
|
||||
|
||||
|
||||
def _unpack_args(args):
|
||||
@@ -15,7 +15,7 @@ def _unpack_args(args):
|
||||
return args.python, args.destination
|
||||
|
||||
|
||||
def build(python=None, destination=None):
|
||||
def execute(python=None, destination=None):
|
||||
'''Build a Python AppImage using a local installation
|
||||
'''
|
||||
pwd = os.getcwd()
|
||||
@@ -4,13 +4,13 @@ import platform
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from ..actions import build_appimage, relocate_python
|
||||
from ..appimage import build_appimage, relocate_python
|
||||
from ..utils.docker import docker_run
|
||||
from ..utils.fs import copy_tree
|
||||
from ..utils.tmp import TemporaryDirectory
|
||||
|
||||
|
||||
__all__ = ['build']
|
||||
__all__ = ['execute']
|
||||
|
||||
|
||||
def _unpack_args(args):
|
||||
@@ -31,7 +31,7 @@ def _get_appimage_name(abi, tag):
|
||||
fullversion, abi, tag)
|
||||
|
||||
|
||||
def build(tag, abi, contained=False):
|
||||
def execute(tag, abi, contained=False):
|
||||
'''Build a Python AppImage using a manylinux docker image
|
||||
'''
|
||||
|
||||
@@ -33,7 +33,7 @@ def ensure_appimagetool():
|
||||
'''Fetch appimagetool from the web if not available locally
|
||||
'''
|
||||
if os.path.exists(APPIMAGETOOL):
|
||||
return
|
||||
return False
|
||||
|
||||
appimage = 'appimagetool-{0:}.AppImage'.format(_ARCH)
|
||||
baseurl = 'https://github.com/AppImage/AppImageKit/releases/' \
|
||||
@@ -53,6 +53,8 @@ def ensure_appimagetool():
|
||||
if not os.path.exists(APPIMAGETOOL):
|
||||
os.symlink(appdir_name + '/AppRun', APPIMAGETOOL)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
# Installers for dependencies
|
||||
def ensure_excludelist():
|
||||
@@ -72,7 +74,7 @@ def ensure_patchelf():
|
||||
'''Fetch PatchELF from the web if not available locally
|
||||
'''
|
||||
if os.path.exists(PATCHELF):
|
||||
return
|
||||
return False
|
||||
|
||||
iarch = 'i386' if _ARCH == 'i686' else _ARCH
|
||||
appimage = 'patchelf-{0:}.AppImage'.format(iarch)
|
||||
@@ -88,3 +90,5 @@ def ensure_patchelf():
|
||||
system('./' + appimage, '--appimage-extract')
|
||||
copy_file('squashfs-root/usr/bin/patchelf', patchelf)
|
||||
os.chmod(patchelf, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user