forked from fossasia/pslab-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
103 lines (83 loc) · 2.27 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
from distutils.cmd import Command
from distutils.util import execute
import os
import platform
import shutil
from subprocess import call
import warnings
from setuptools import setup, find_packages
from setuptools.command.develop import develop
from setuptools.command.install import install
def udev_reload_rules():
call(["udevadm", "control", "--reload-rules"])
def udev_trigger():
call( # nosec
[
"udevadm",
"trigger",
"--subsystem-match=usb",
"--attr-match=idVendor=04d8",
"--action=add",
]
)
def install_udev_rules():
shutil.copy("99-pslab.rules", "/lib/udev/rules.d")
execute(udev_reload_rules, [], "Reloading udev rules")
execute(udev_trigger, [], "Triggering udev rules")
def check_root():
return os.geteuid() == 0
class CustomInstall(install):
def run(self):
install.run(self)
self.run_command("udev")
class CustomDevelop(develop):
def run(self):
develop.run(self)
try:
self.run_command("udev")
except OSError as e:
warnings.warn(e)
class InstallUdevRules(Command):
description = "install udev rules (requires root privileges)."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
if platform.system() == "Linux":
if check_root():
install_udev_rules()
else:
msg = "You must have root privileges to install udev rules."
raise OSError(msg)
setup(
name="PSL",
version="1.1.0",
description="Pocket Science Lab by FOSSASIA",
author="FOSSASIA PSLab Developers",
author_email="[email protected]",
url="https://pslab.io/",
install_requires=["numpy>=1.16.3."],
packages=find_packages(exclude=("tests",)),
package_data={
"": [
"*.css",
"*.png",
"*.gif",
"*.html",
"*.css",
"*.js",
"*.png",
"*.jpg",
"*.jpeg",
"*.htm",
"99-pslab.rules",
]
},
cmdclass={
"develop": CustomDevelop,
"install": CustomInstall,
"udev": InstallUdevRules,
},
)