setup.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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'] or ext != '.py':
  18. continue
  19. yield basename.replace('_', '-'), 'qubesadmin.tools.{}'.format(basename)
  20. # create simple scripts that run much faster than "console entry points"
  21. class CustomInstall(setuptools.command.install.install):
  22. def run(self):
  23. bin = os.path.join(self.root, "usr/bin")
  24. try:
  25. os.makedirs(bin)
  26. except:
  27. pass
  28. for file, pkg in get_console_scripts():
  29. path = os.path.join(bin, file)
  30. with open(path, "w") as f:
  31. f.write(
  32. """#!/usr/bin/python3
  33. from {} import main
  34. import sys
  35. if __name__ == '__main__':
  36. sys.exit(main())
  37. """.format(pkg))
  38. os.chmod(path, 0o755)
  39. setuptools.command.install.install.run(self)
  40. if __name__ == '__main__':
  41. setuptools.setup(
  42. name='qubesadmin',
  43. version=open('version').read().strip(),
  44. author='Invisible Things Lab',
  45. author_email='marmarek@invisiblethingslab.com',
  46. description='Qubes Admin API package',
  47. license='LGPL2.1+',
  48. url='https://www.qubes-os.org/',
  49. packages=setuptools.find_packages(exclude=exclude),
  50. package_data={
  51. 'qubesadmin.tests.backup': ['*.xml'],
  52. },
  53. cmdclass={
  54. 'install': CustomInstall
  55. },
  56. )