local.py 1.0 KB

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