Manylinux downloader and extractor

This commit is contained in:
Valentin Niess
2025-05-19 17:13:29 +02:00
parent 08ee36fc45
commit 1fdb439e70
7 changed files with 581 additions and 15 deletions

View File

@@ -9,28 +9,30 @@ from .tmp import TemporaryDirectory
from .url import urlretrieve
__all__ = ['APPIMAGETOOL', 'EXCLUDELIST', 'PATCHELF', 'PREFIX',
'ensure_appimagetool', 'ensure_excludelist', 'ensure_patchelf']
_ARCH = platform.machine()
_CACHE_DIR = os.path.expanduser('~/.cache/python-appimage')
PREFIX = os.path.abspath(os.path.dirname(__file__) + '/..')
'''Package installation prefix'''
APPIMAGETOOL_DIR = os.path.expanduser('~/.local/bin')
APPIMAGETOOL_DIR = os.path.join(_CACHE_DIR, 'bin')
'''Location of the appimagetool binary'''
APPIMAGETOOL_VERSION = '12'
'''Version of the appimagetool binary'''
EXCLUDELIST = PREFIX + '/data/excludelist'
EXCLUDELIST = os.path.join(_CACHE_DIR, 'share/excludelist')
'''AppImage exclusion list'''
PATCHELF = os.path.expanduser('~/.local/bin/patchelf')
PATCHELF = os.path.join(_CACHE_DIR, 'bin/patchelf')
'''Location of the PatchELF binary'''
PATCHELF_VERSION = '0.14.3'
'''Version of the patchelf binary'''
def ensure_appimagetool(dry=False):
'''Fetch appimagetool from the web if not available locally
'''
@@ -91,19 +93,18 @@ def ensure_patchelf():
if os.path.exists(PATCHELF):
return False
iarch = 'i386' if _ARCH == 'i686' else _ARCH
appimage = 'patchelf-{0:}.AppImage'.format(iarch)
baseurl = 'https://github.com/niess/patchelf.appimage/releases/download'
tgz = '-'.join(('patchelf', _PATCHELF_VERSION, _ARCH)) + '.tar.gz'
baseurl = 'https://github.com/NixOS/patchelf'
log('INSTALL', 'patchelf from %s', baseurl)
dirname = os.path.dirname(PATCHELF)
patchelf = dirname + '/patchelf'
make_tree(dirname)
with TemporaryDirectory() as tmpdir:
urlretrieve(os.path.join(baseurl, 'rolling', appimage), appimage)
os.chmod(appimage, stat.S_IRWXU)
system(('./' + appimage, '--appimage-extract'))
copy_file('squashfs-root/usr/bin/patchelf', patchelf)
urlretrieve(os.path.join(baseurl, 'releases', 'download',
_PATCHELF_VERSION, tgz), tgz)
system(('tar', 'xzf', tgz))
copy_file('bin/patchelf', patchelf)
os.chmod(patchelf, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
return True

View File

@@ -32,6 +32,10 @@ def urlretrieve(url, filename=None):
else:
debug('DOWNLOAD', '%s as %s', url, filename)
parent_directory = os.path.dirname(filename)
if not os.path.exists(parent_directory):
os.makedirs(parent_directory)
if _urlretrieve is None:
data = urllib2.urlopen(url).read()
with open(filename, 'w') as f: