mirror of
https://github.com/niess/python-appimage.git
synced 2026-03-14 04:10:15 +01:00
List command for manylinux images
This commit is contained in:
@@ -75,6 +75,11 @@ def main():
|
||||
action='store_true',
|
||||
default=False)
|
||||
|
||||
list_parser = subparsers.add_parser('list',
|
||||
description='List Python versions installed in a manylinux image')
|
||||
list_parser.add_argument('tag',
|
||||
help='manylinux image tag (e.g. 2010_x86_64)')
|
||||
|
||||
which_parser = subparsers.add_parser('which',
|
||||
description='Locate a binary dependency')
|
||||
which_parser.add_argument('binary', choices=binaries,
|
||||
|
||||
41
python_appimage/commands/list.py
Normal file
41
python_appimage/commands/list.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import os
|
||||
|
||||
from ..utils.docker import docker_run
|
||||
from ..utils.log import log
|
||||
from ..utils.tmp import TemporaryDirectory
|
||||
|
||||
|
||||
__all__ = ['execute']
|
||||
|
||||
|
||||
def _unpack_args(args):
|
||||
'''Unpack command line arguments
|
||||
'''
|
||||
return (args.tag,)
|
||||
|
||||
|
||||
def execute(tag):
|
||||
'''List python versions installed in a manylinux image
|
||||
'''
|
||||
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
script = (
|
||||
'for dir in $(ls /opt/python | grep "^cp[0-9]"); do',
|
||||
' version=$(/opt/python/$dir/bin/python -c "import sys; ' \
|
||||
'sys.stdout.write(sys.version.split()[0])")',
|
||||
' echo "$dir $version"',
|
||||
'done',
|
||||
)
|
||||
if tag.startswith('2_'):
|
||||
image = 'manylinux_' + tag
|
||||
else:
|
||||
image = 'manylinux' + tag
|
||||
result = docker_run(
|
||||
'quay.io/pypa/' + image,
|
||||
script,
|
||||
capture = True
|
||||
)
|
||||
for line in result.split(os.linesep):
|
||||
if line:
|
||||
log('LIST', "{1:7} -> /opt/python/{0:}".format(
|
||||
*line.split()))
|
||||
@@ -4,11 +4,12 @@ import stat
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from .compat import decode
|
||||
from .log import log
|
||||
from .system import system
|
||||
|
||||
|
||||
def docker_run(image, extra_cmds):
|
||||
def docker_run(image, extra_cmds, capture=False):
|
||||
'''Execute commands within a docker container
|
||||
'''
|
||||
|
||||
@@ -42,10 +43,16 @@ def docker_run(image, extra_cmds):
|
||||
'type=bind,source={:},target=/pwd'.format(os.getcwd()),
|
||||
image, '/bin/bash', bash_arg))
|
||||
|
||||
if capture:
|
||||
opts = {'stderr': subprocess.PIPE, 'stdout': subprocess.PIPE}
|
||||
else:
|
||||
opts = {}
|
||||
log('RUN', image)
|
||||
p = subprocess.Popen(cmd, shell=True)
|
||||
p.communicate()
|
||||
p = subprocess.Popen(cmd, shell=True, **opts)
|
||||
r = p.communicate()
|
||||
if p.returncode != 0:
|
||||
if p.returncode == 139:
|
||||
sys.stderr.write("segmentation fault when running Docker (139)\n")
|
||||
sys.exit(p.returncode)
|
||||
if capture:
|
||||
return decode(r[0])
|
||||
|
||||
Reference in New Issue
Block a user