deps.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/AppImageKit/releases/' \
  27. 'download/12'
  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. return True
  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 False
  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'
  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. return True