setup.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # vim: fileencoding=utf-8
  2. import os
  3. import setuptools
  4. import setuptools.command.install
  5. import sys
  6. exclude=[]
  7. if sys.version_info[0:2] < (3, 5):
  8. exclude += ['qubesadmin.backup', 'qubesadmin.tests.backup']
  9. exclude += ['qubesadmin.tools', 'qubesadmin.tests.tools']
  10. exclude += ['qubesadmin.events']
  11. # don't import: import * is unreliable and there is no need, since this is
  12. # compile time and we have source files
  13. def get_console_scripts():
  14. if sys.version_info[0:2] >= (3, 4):
  15. for filename in os.listdir('./qubesadmin/tools'):
  16. basename, ext = os.path.splitext(os.path.basename(filename))
  17. if basename in ['__init__', 'dochelpers', 'xcffibhelpers']\
  18. or ext != '.py':
  19. continue
  20. yield basename.replace('_', '-'), 'qubesadmin.tools.{}'.format(
  21. basename)
  22. # create simple scripts that run much faster than "console entry points"
  23. class CustomInstall(setuptools.command.install.install):
  24. def run(self):
  25. bin = os.path.join(self.root, "usr/bin")
  26. try:
  27. os.makedirs(bin)
  28. except:
  29. pass
  30. for file, pkg in get_console_scripts():
  31. path = os.path.join(bin, file)
  32. with open(path, "w") as f:
  33. f.write(
  34. """#!/usr/bin/python3
  35. from {} import main
  36. import sys
  37. if __name__ == '__main__':
  38. sys.exit(main())
  39. """.format(pkg))
  40. os.chmod(path, 0o755)
  41. setuptools.command.install.install.run(self)
  42. if __name__ == '__main__':
  43. setuptools.setup(
  44. name='qubesadmin',
  45. version=open('version').read().strip(),
  46. author='Invisible Things Lab',
  47. author_email='marmarek@invisiblethingslab.com',
  48. description='Qubes Admin API package',
  49. license='LGPL2.1+',
  50. url='https://www.qubes-os.org/',
  51. packages=setuptools.find_packages(exclude=exclude),
  52. package_data={
  53. 'qubesadmin.tests.backup': ['*.xml'],
  54. },
  55. cmdclass={
  56. 'install': CustomInstall
  57. },
  58. )