local.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import glob
  2. import os
  3. import shutil
  4. from .build import build_appimage
  5. from .relocate import relocate_python
  6. from .tmp import TemporaryDirectory
  7. __all__ = ['build']
  8. def _unpack_args(args):
  9. '''Unpack command line arguments
  10. '''
  11. return args.python, args.destination
  12. def build(python=None, destination=None):
  13. '''Build a Python AppImage using a local installation
  14. '''
  15. pwd = os.getcwd()
  16. with TemporaryDirectory() as tmpdir:
  17. relocate_python(python)
  18. dirname, pattern = None, None
  19. if destination is not None:
  20. dirname, destination = os.path.split(destination)
  21. pattern = destination
  22. if pattern is None:
  23. pattern = 'python*.AppImage'
  24. build_appimage(destination=destination)
  25. appimage = glob.glob(pattern)[0]
  26. if dirname is None:
  27. dirname = pwd
  28. else:
  29. os.chdir(pwd)
  30. dirname = os.path.abspath(dirname)
  31. os.chdir(tmpdir)
  32. shutil.move(appimage, os.path.join(dirname, appimage))