__main__.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import argparse
  2. from importlib import import_module
  3. import logging
  4. import os
  5. import sys
  6. __all__ = ['main']
  7. def main():
  8. '''Entry point for the CLI
  9. '''
  10. # Binary dependencies
  11. binaries = ('appimagetool', 'patchelf')
  12. # Parse arguments
  13. parser = argparse.ArgumentParser(
  14. prog='python-appimage',
  15. description='Bundle a Python installation into an AppImage')
  16. subparsers = parser.add_subparsers(title='command',
  17. help='Build or install command',
  18. dest='command')
  19. parser.add_argument('-q', '--quiet', help='disable logging',
  20. dest='verbosity', action='store_const', const=logging.ERROR)
  21. parser.add_argument('-v', '--verbose', help='print extra information',
  22. dest='verbosity', action='store_const', const=logging.DEBUG)
  23. install_parser = subparsers.add_parser('install',
  24. description='Install binary dependencies')
  25. install_parser.add_argument('binary', nargs='+',
  26. choices=binaries, help='one or more binary name')
  27. local_parser = subparsers.add_parser('local',
  28. description='Bundle a local Python installation')
  29. local_parser.add_argument('-d', '--destination',
  30. help='AppImage destination')
  31. local_parser.add_argument('-p', '--python', help='python executable')
  32. manylinux_parser = subparsers.add_parser('manylinux',
  33. description='Bundle a manylinux Python installation using docker')
  34. manylinux_parser.add_argument('tag',
  35. help='manylinux image tag (e.g. 2010_x86_64)')
  36. manylinux_parser.add_argument('abi',
  37. help='python ABI (e.g. cp37-cp37m)')
  38. manylinux_parser.add_argument('--contained', help=argparse.SUPPRESS,
  39. action='store_true', default=False)
  40. which_parser = subparsers.add_parser('which',
  41. description='Locate a binary dependency')
  42. which_parser.add_argument('binary', choices=binaries,
  43. help='name of the binary to locate')
  44. args = parser.parse_args()
  45. # Configure the verbosity
  46. if args.verbosity:
  47. logging.getLogger().setLevel(args.verbosity)
  48. # Call the requested command
  49. command = import_module('.commands.' +
  50. args.command, package=__package__)
  51. command.execute(*command._unpack_args(args))
  52. if __name__ == "__main__":
  53. main()