deps.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 False
  25. appimage = 'appimagetool-{0:}.AppImage'.format(_ARCH)
  26. baseurl = 'https://github.com/AppImage/appimagetool/releases/download/continuous'
  27. log('INSTALL', 'appimagetool from %s', baseurl)
  28. make_tree(os.path.dirname(APPIMAGETOOL))
  29. urlretrieve(os.path.join(baseurl, appimage), APPIMAGETOOL)
  30. os.chmod(APPIMAGETOOL, stat.S_IRWXU)
  31. return True
  32. # Installers for dependencies
  33. def ensure_excludelist():
  34. '''Fetch the AppImage excludelist from the web if not available locally
  35. '''
  36. if os.path.exists(EXCLUDELIST):
  37. return
  38. baseurl = 'https://raw.githubusercontent.com/probonopd/AppImages/master'
  39. log('INSTALL', 'excludelist from %s', baseurl)
  40. urlretrieve(baseurl + '/excludelist', EXCLUDELIST)
  41. mode = os.stat(EXCLUDELIST)[stat.ST_MODE]
  42. os.chmod(EXCLUDELIST, mode | stat.S_IWGRP | stat.S_IWOTH)
  43. def ensure_patchelf():
  44. '''Fetch PatchELF from the web if not available locally
  45. '''
  46. if os.path.exists(PATCHELF):
  47. return False
  48. iarch = 'i386' if _ARCH == 'i686' else _ARCH
  49. appimage = 'patchelf-{0:}.AppImage'.format(iarch)
  50. baseurl = 'https://github.com/niess/patchelf.appimage/releases/download'
  51. log('INSTALL', 'patchelf from %s', baseurl)
  52. dirname = os.path.dirname(PATCHELF)
  53. patchelf = dirname + '/patchelf'
  54. make_tree(dirname)
  55. with TemporaryDirectory() as tmpdir:
  56. urlretrieve(os.path.join(baseurl, 'rolling', appimage), appimage)
  57. os.chmod(appimage, stat.S_IRWXU)
  58. system(('./' + appimage, '--appimage-extract'))
  59. copy_file('squashfs-root/usr/bin/patchelf', patchelf)
  60. os.chmod(patchelf, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
  61. return True