deps.py 3.1 KB

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