1
0

build.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import os
  2. import re
  3. import subprocess
  4. import sys
  5. from ..utils.compat import decode
  6. from ..utils.deps import APPIMAGETOOL, ensure_appimagetool
  7. from ..utils.docker import docker_run
  8. from ..utils.fs import copy_tree
  9. from ..utils.log import debug, log
  10. from ..utils.tmp import TemporaryDirectory
  11. __all__ = ['build_appimage']
  12. def build_appimage(appdir=None, destination=None):
  13. '''Build an AppImage from an AppDir
  14. '''
  15. if appdir is None:
  16. appdir = 'AppDir'
  17. log('BUILD', appdir)
  18. ensure_appimagetool()
  19. cmd = [APPIMAGETOOL, '--no-appstream', appdir]
  20. if destination is not None:
  21. cmd.append(destination)
  22. cmd = ' '.join(cmd)
  23. debug('SYSTEM', cmd)
  24. p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
  25. stderr=subprocess.STDOUT)
  26. appimage_pattern = re.compile('should be packaged as ([^ ]+[.]AppImage)')
  27. stdout, appimage = [], None
  28. while True:
  29. out = decode(p.stdout.readline())
  30. stdout.append(out)
  31. if out == '' and p.poll() is not None:
  32. break
  33. elif out:
  34. out = out.replace('%', '%%')[:-1]
  35. for line in out.split(os.linesep):
  36. if line.startswith('WARNING'):
  37. log('WARNING', line[9:])
  38. elif line.startswith('Error'):
  39. raise RuntimeError(line)
  40. else:
  41. if destination is None:
  42. match = appimage_pattern.search(line)
  43. if match is not None:
  44. destination = match.group(1)
  45. debug('APPIMAGE', line)
  46. rc = p.poll()
  47. if rc != 0 and not os.path.exists(destination):
  48. print(''.join(stdout))
  49. sys.stdout.flush()
  50. raise RuntimeError('Could not build AppImage')