-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
76 lines (64 loc) · 2.13 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------
# setup
# created 24.12.2023
# Thomas Kaulke, kaulketh@gmail.com
# https://github.com/kaulketh
# -----------------------------------------------------------
import platform
import subprocess
import sys
from setuptools import setup, find_packages
from setuptools.command.install import install
class InstallService(install):
FILE_NAME = 'fan_control.service'
FILE_CONTENT = '''
[Unit]
Description=Fan control service
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/fan_control/main.py
[Install]
WantedBy=multi-user.target
'''
def run(self):
install.run(self)
if platform.system() == 'Linux':
try:
with open(f'/etc/systemd/system/{InstallService.FILE_NAME}',
'w') as service_file:
service_file.write(InstallService.FILE_CONTENT)
subprocess.run(['systemctl', 'daemon-reload'])
subprocess.run(
['systemctl', 'enable', InstallService.FILE_NAME],
check=True)
sys.stdout.write(
f'Service "{InstallService.FILE_NAME}" enabled successfully.\n')
except subprocess.CalledProcessError as e:
sys.stderr.write(f'Failed to enable service: {e}\n')
setup(
name='simple-pi-fan-control',
version='1.0',
packages=find_packages(exclude=[]),
author='Thomas Kaulke',
author_email='kaulketh@gmail.com',
description='The program reads the CPU+GPU temperature and switches GPIO channel.',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
url='https://github.com/kaulketh/simple-pi-fan-control',
license=open('LICENSE.md').read(),
classifiers=[
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
],
install_requires=[
'RPi.GPIO'
],
cmdclass={
'install': InstallService,
}
)
if __name__ == '__main__':
setup()