setup.py 2.0 KB

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