1
0

deps.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import os
  2. import platform
  3. import stat
  4. from .fs import copy_file, copy_tree, make_tree
  5. from .log import log
  6. from .system import system
  7. from .tmp import TemporaryDirectory
  8. from .url import urlretrieve
  9. __all__ = ['APPIMAGETOOL', 'EXCLUDELIST', 'PATCHELF', 'PREFIX',
  10. 'ensure_appimagetool', 'ensure_excludelist', 'ensure_patchelf']
  11. _ARCH = platform.machine()
  12. PREFIX = os.path.abspath(os.path.dirname(__file__) + '/..')
  13. '''Package installation prefix'''
  14. APPIMAGETOOL = os.path.expanduser('~/.local/bin/appimagetool')
  15. '''Location of the appimagetool binary'''
  16. EXCLUDELIST = PREFIX + '/data/excludelist'
  17. '''AppImage exclusion list'''
  18. PATCHELF = os.path.expanduser('~/.local/bin/patchelf')
  19. '''Location of the PatchELF binary'''
  20. def ensure_appimagetool():
  21. '''Fetch appimagetool from the web if not available locally
  22. '''
  23. if os.path.exists(APPIMAGETOOL):
  24. return
  25. appimage = 'appimagetool-{0:}.AppImage'.format(_ARCH)
  26. baseurl = 'https://github.com/AppImage/AppImageKit/releases/' \
  27. 'download/continuous'
  28. log('INSTALL', 'appimagetool from %s', baseurl)
  29. appdir_name = '.appimagetool.appdir'.format(_ARCH)
  30. appdir = os.path.join(os.path.dirname(APPIMAGETOOL), appdir_name)
  31. if not os.path.exists(appdir):
  32. make_tree(os.path.dirname(appdir))
  33. with TemporaryDirectory() as tmpdir:
  34. urlretrieve(os.path.join(baseurl, appimage), appimage)
  35. os.chmod(appimage, stat.S_IRWXU)
  36. system('./' + appimage, '--appimage-extract')
  37. copy_tree('squashfs-root', appdir)
  38. if not os.path.exists(APPIMAGETOOL):
  39. os.symlink(appdir_name + '/AppRun', APPIMAGETOOL)
  40. # Installers for dependencies
  41. def ensure_excludelist():
  42. '''Fetch the AppImage excludelist from the web if not available locally
  43. '''
  44. if os.path.exists(EXCLUDELIST):
  45. return
  46. baseurl = 'https://raw.githubusercontent.com/probonopd/AppImages/master'
  47. log('INSTALL', 'excludelist from %s', baseurl)
  48. urlretrieve(baseurl + '/excludelist', EXCLUDELIST)
  49. mode = os.stat(EXCLUDELIST)[stat.ST_MODE]
  50. os.chmod(EXCLUDELIST, mode | stat.S_IWGRP | stat.S_IWOTH)
  51. def ensure_patchelf():
  52. '''Fetch PatchELF from the web if not available locally
  53. '''
  54. if os.path.exists(PATCHELF):
  55. return
  56. iarch = 'i386' if _ARCH == 'i686' else _ARCH
  57. appimage = 'patchelf-{0:}.AppImage'.format(iarch)
  58. baseurl = 'https://github.com/niess/patchelf.appimage/releases/download'
  59. log('INSTALL', 'patchelf from %s', baseurl)
  60. dirname = os.path.dirname(PATCHELF)
  61. patchelf = dirname + '/patchelf'
  62. make_tree(dirname)
  63. with TemporaryDirectory() as tmpdir:
  64. urlretrieve(os.path.join(baseurl, 'rolling', appimage), appimage)
  65. os.chmod(appimage, stat.S_IRWXU)
  66. system('./' + appimage, '--appimage-extract')
  67. copy_file('squashfs-root/usr/bin/patchelf', patchelf)
  68. os.chmod(patchelf, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)