-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·133 lines (108 loc) · 3.46 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"""setup GOTCHA_TTY
"""
__updated__ = "2022-10-14 16:42:41"
import os
import sys
from configparser import ConfigParser
from typing import Any, List
from subprocess import check_call
from pkg_resources import parse_requirements
from setuptools import setup, Command
from setuptools.command.install import install
import subprocess
NAME = "gotcha"
VERSION = None
# # root privileges
# if os.geteuid() != 0:
# print("\n\n\t*** root privileges required for this software. ***\n")
# sys.exit(1)
here = os.path.abspath(os.path.dirname(__file__))
# Load the package's __version__.py module as a dictionary.
about = {}
if not VERSION:
SLUG = NAME.lower().replace("-", "_").replace(" ", "_")
with open(os.path.join(here, SLUG, "__version__.py"), encoding="utf-8") as f:
exec(f.read(), about) # pylint: disable=exec-used
else:
about["__version__"] = VERSION
# get the long description from the README.rst
with open(os.path.join(here, "README.rst"), encoding="utf-8") as f:
long_description = f.read()
class ListDependenciesCommand(Command):
"""A custom command to list dependencies"""
description = "list package dependencies"
user_options: List[Any] = []
def initialize_options(self):
"""initialize_options"""
def finalize_options(self):
"""finalize_options"""
def run(self):
"""run"""
cfg = ConfigParser()
cfg.read("setup.cfg")
requirements = cfg["options"]["install_requires"]
print(requirements)
class PyInstallerCommand(Command):
"""A custom command to run PyInstaller to build standalone executable."""
description = "run PyInstaller on gotcha entrypoint"
user_options: List[Any] = []
def initialize_options(self):
"""initialize_options"""
def finalize_options(self):
"""finalize_options"""
def run(self):
"""run"""
cfg = ConfigParser()
cfg.read("setup.cfg")
command = [
"pyinstaller",
"--additional-hooks-dir",
"pyinstaller_hooks",
"--clean",
"--onefile",
"--name",
"gotcha",
]
setup_cfg = cfg["options"]["install_requires"]
requirements = parse_requirements(setup_cfg)
for _r in requirements:
command.extend(["--hidden-import", _r.key])
command.append("gotcha/__main__.py")
print(" ".join(command))
check_call(command)
def compile_and_install_software():
"""Used the subprocess module to compile/install the C software."""
# compile & install the process hider
subprocess.check_call('sudo make build', cwd='./preload/', shell=True)
class CustomInstall(install):
"""Custom handler for the 'install' command."""
def run(self):
compile_and_install_software()
super().run()
setup(
name="ttyGotcha",
version=about["__version__"],
cmdclass={
"dependencies": ListDependenciesCommand,
"pyinstaller": PyInstallerCommand,
'preload': CustomInstall,
},
description="SSH-TTY control Interface",
long_description=long_description,
author="Marcos Caputo",
author_email="caputo.marcos@gmail.com",
url="https://github.com/caputomarcos/gotcha",
packages=[
"gotcha",
],
license="MIT",
install_requires=[
],
entry_points={
"console_scripts": [
"gotcha = gotcha:__main__.main",
]
},
python_requires=">=3.10.7",
include_package_data=True,
)