mirror of
https://github.com/niess/python-appimage.git
synced 2025-07-21 21:01:15 +02:00
Get images to the cache
This commit is contained in:
@@ -51,6 +51,13 @@ def main():
|
||||
cache_clean_parser.add_argument('-a', '--all', action='store_true',
|
||||
help='remove all image(s) data')
|
||||
|
||||
cache_get_parser = cache_subparsers.add_parser('get',
|
||||
description='Download image(s) to the cache')
|
||||
cache_get_parser.add_argument('tags', nargs='+',
|
||||
help='manylinux image tag(s) (e.g. 2014_x86_64)')
|
||||
cache_get_parser.add_argument('-e', '--extract', action='store_true',
|
||||
help='extract compressed image data')
|
||||
|
||||
cache_list_parser = cache_subparsers.add_parser('list',
|
||||
description='List cached image(s)')
|
||||
|
||||
@@ -66,11 +73,13 @@ def main():
|
||||
build_local_parser.add_argument('-p', '--python', help='python executable')
|
||||
|
||||
build_manylinux_parser = build_subparsers.add_parser('manylinux',
|
||||
description='Bundle a manylinux Python installation using docker')
|
||||
description='Bundle a manylinux Python installation')
|
||||
build_manylinux_parser.add_argument('tag',
|
||||
help='manylinux image tag (e.g. 2010_x86_64)')
|
||||
build_manylinux_parser.add_argument('abi',
|
||||
help='python ABI (e.g. cp37-cp37m)')
|
||||
build_manylinux_parser.add_argument('-c', '--clean',
|
||||
help='compress the image after extraction', action='store_true')
|
||||
|
||||
build_app_parser = build_subparsers.add_parser('app',
|
||||
description='Build a Python application using a base AppImage')
|
||||
|
@@ -13,14 +13,14 @@ __all__ = ['execute']
|
||||
def _unpack_args(args):
|
||||
'''Unpack command line arguments
|
||||
'''
|
||||
return args.tag, args.abi
|
||||
return args.tag, args.abi, args.clean
|
||||
|
||||
|
||||
def execute(tag, abi):
|
||||
def execute(tag, abi, clean):
|
||||
'''Build a Python AppImage using a Manylinux image
|
||||
'''
|
||||
|
||||
image = ensure_image(tag)
|
||||
image = ensure_image(tag, clean=clean)
|
||||
|
||||
pwd = os.getcwd()
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
|
18
python_appimage/commands/cache/get.py
vendored
Normal file
18
python_appimage/commands/cache/get.py
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
from ...manylinux import ensure_image
|
||||
|
||||
|
||||
__all__ = ['execute']
|
||||
|
||||
|
||||
def _unpack_args(args):
|
||||
'''Unpack command line arguments
|
||||
'''
|
||||
return (args.tags, args.extract)
|
||||
|
||||
|
||||
def execute(images, extract):
|
||||
'''Download image(s) to the cache
|
||||
'''
|
||||
|
||||
for image in images:
|
||||
ensure_image(image, extract=extract)
|
@@ -9,8 +9,8 @@ __all__ = ['Arch', 'Downloader', 'ensure_image', 'ImageExtractor', 'LinuxTag',
|
||||
'PythonExtractor', 'PythonImpl', 'PythonVersion']
|
||||
|
||||
|
||||
def ensure_image(tag):
|
||||
'''Extract a manylinux image to the cache'''
|
||||
def ensure_image(tag, *, clean=False, extract=True):
|
||||
'''Download a manylinux image to the cache'''
|
||||
|
||||
try:
|
||||
tag, image_tag = tag.rsplit(':', 1)
|
||||
@@ -24,14 +24,21 @@ def ensure_image(tag):
|
||||
downloader = Downloader(tag=tag, arch=arch)
|
||||
downloader.download(tag=image_tag)
|
||||
|
||||
image_extractor = ImageExtractor(
|
||||
prefix = downloader.default_destination(),
|
||||
tag = image_tag
|
||||
)
|
||||
image_extractor.extract()
|
||||
if extract:
|
||||
image_extractor = ImageExtractor(
|
||||
prefix = downloader.default_destination(),
|
||||
tag = image_tag
|
||||
)
|
||||
image_extractor.extract(clean=clean)
|
||||
|
||||
return SimpleNamespace(
|
||||
arch = arch,
|
||||
tag = tag,
|
||||
path = image_extractor.default_destination(),
|
||||
)
|
||||
return SimpleNamespace(
|
||||
arch = arch,
|
||||
tag = tag,
|
||||
path = image_extractor.default_destination(),
|
||||
)
|
||||
else:
|
||||
return SimpleNamespace(
|
||||
arch = arch,
|
||||
tag = tag,
|
||||
path = downloader.default_destination(),
|
||||
)
|
||||
|
@@ -335,16 +335,16 @@ class ImageExtractor:
|
||||
return self.prefix / f'extracted/{self.tag}'
|
||||
|
||||
|
||||
def extract(self, destination: Optional[Path]=None, *, cleanup=False):
|
||||
def extract(self, destination: Optional[Path]=None, *, clean=False):
|
||||
'''Extract Manylinux image.'''
|
||||
|
||||
if destination is None:
|
||||
destination = self.default_destination()
|
||||
|
||||
if cleanup:
|
||||
def cleanup(destination):
|
||||
if clean:
|
||||
def clean(destination):
|
||||
shutil.rmtree(destination, ignore_errors=True)
|
||||
atexit.register(cleanup, destination)
|
||||
atexit.register(clean, destination)
|
||||
|
||||
log('EXTRACT', f'{self.prefix.name}:{self.tag}')
|
||||
|
||||
|
Reference in New Issue
Block a user