From 6fb58fdd9c8cbdc13bd69f1a9779344a26e2485b Mon Sep 17 00:00:00 2001 From: Pawel Marczewski Date: Thu, 23 Jan 2020 14:25:54 +0100 Subject: [PATCH] Install faster console scripts for Python code Same as in qubes-core-admin. --- setup.py | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 323262c..a382728 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,40 @@ # vim: fileencoding=utf-8 +import os + import setuptools +import setuptools.command.install +import re + + +CONSOLE_SCRIPTS = [ + ('qubes-firewall', 'qubesagent.firewall'), + ('qubes-vmexec', 'qubesagent.vmexec'), +] + + +# create simple scripts that run much faster than "console entry points" +class CustomInstall(setuptools.command.install.install): + def run(self): + bin = os.path.join(self.root, "usr/bin") + try: + os.makedirs(bin) + except: + pass + for file, pkg in CONSOLE_SCRIPTS: + path = os.path.join(bin, file) + with open(path, "w") as f: + f.write( +"""#!/usr/bin/python3 +from {} import main +import sys +if __name__ == '__main__': + sys.exit(main()) +""".format(pkg)) + + os.chmod(path, 0o755) + setuptools.command.install.install.run(self) + if __name__ == '__main__': setuptools.setup( @@ -14,10 +48,7 @@ if __name__ == '__main__': packages=('qubesagent',), - entry_points={ - 'console_scripts': [ - 'qubes-firewall = qubesagent.firewall:main', - 'qubes-vmexec = qubesagent.vmexec:main', - ], - } + cmdclass={ + 'install': CustomInstall, + }, )