-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
112 lines (87 loc) · 3.51 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
import distutils.core
import distutils.util
import os.path
import setuptools.command.install
import subprocess
class InstallSystemdUnit(distutils.core.Command):
description = "install systemd unit file"
user_options = [
('install-systemd-unit=', None,
"systemd unit installation directory"),
('root=', None,
"install everything relative to this alternate root directory"),
('force', 'f', "force installation (overwrite existing files)"),
]
boolean_options = ['force']
unit_file = 'amdgpu-tweakd.service'
def initialize_options(self):
self.outfiles = []
self.install_systemd_unit = None
self.root = None
self.force = 0
def finalize_options(self):
self.set_undefined_options('install',
('root', 'root'),
('force', 'force'))
if self.install_systemd_unit is None:
self.install_systemd_unit = self.detect_systemd_dir()
def run(self):
if not self.install_systemd_unit:
self.warn("Skipping systemd unit installation")
return
self.mkpath(self.install_systemd_unit)
out_file = os.path.join(self.install_systemd_unit,
os.path.basename(self.unit_file))
self.make_file([self.unit_file], out_file,
self.write_unit_file, (self.unit_file, out_file))
self.outfiles.append(out_file)
def detect_systemd_dir(self):
try:
system_unit_dir = subprocess.check_output(
['pkg-config', '--variable=systemdsystemunitdir', 'systemd'],
universal_newlines=True
).strip()
except subprocess.CalledProcessError as ex:
self.warn("Can't detect systemd system unit dir: " + str(ex))
return
if self.root is None:
return system_unit_dir
return distutils.util.change_root(self.root, system_unit_dir)
def write_unit_file(self, template_path, out_path):
with open(template_path, 'rt') as template_file:
template = template_file.read()
install_scripts = self.get_finalized_command("install_scripts").install_dir
if self.root is not None and install_scripts.startswith(self.root):
install_scripts = '/' + install_scripts[len(self.root):]
template = template.format(install_scripts=install_scripts)
with open(out_path, 'wt') as out_file:
out_file.write(template)
def get_inputs(self):
return [self.unit_file]
def get_outputs(self):
return self.outfiles
class Install(setuptools.command.install.install):
sub_commands = setuptools.command.install.install.sub_commands + [('install_systemd_unit', lambda _: True)]
setuptools.setup(
name='amdgpu-tweakd',
packages=setuptools.find_packages(),
entry_points={
'console_scripts': [
'amdgpu-tweakd=amdgpu_tweakd.daemon:main',
'amdgpu-unlock-overdrive=amdgpu_tweakd.overdrive_unlock:main'
],
},
install_requires=['jeepney>=0.4', 'pyudev>=0.20'],
setup_requires=['setuptools-scm'],
python_requires='>=3.5',
use_scm_version=True,
cmdclass = {
'install_systemd_unit': InstallSystemdUnit,
'install': Install
},
author='Aleksandr Mezin',
author_email='mezin.alexander@gmail.com',
description='amdgpu fan speed control and power limit tweak',
license='GPL3',
url='https://github.com/amezin/amdgpu-tweakd'
)