forked from motom001/DoorPi
-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
executable file
·45 lines (36 loc) · 1.29 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
#!/usr/bin/env python3
"""DoorPi Setup"""
import pathlib
import sys
import setuptools.command.install
BASE_PATH = pathlib.Path(__file__).resolve().parent
ETC = "/etc" if sys.prefix == "/usr" else "etc"
class InstallHook(setuptools.command.install.install):
"""Hook for ``install`` command that processes template files (*.in)"""
def run(self):
datapath = BASE_PATH / "data"
package = self.distribution.metadata.name.lower()
substkeys = {
"package": package,
"project": self.distribution.metadata.name,
"prefix": self.prefix,
"cfgdir": pathlib.Path(
self.prefix if sys.prefix == "/usr" else "", "etc", package
),
}
for file in datapath.iterdir():
if file.suffix != ".in":
continue
content = file.read_text()
for key, val in substkeys.items():
content = content.replace(f"!!{key}!!", str(val))
file.with_suffix("").write_text(content)
super().run()
setuptools.setup(
cmdclass={"install": InstallHook},
data_files=[
# init script and systemd service
(f"{ETC}/init.d", ["data/doorpi.sh"]),
("lib/systemd/system", ["data/doorpi.service", "data/doorpi.socket"]),
],
)