1
- #!/usr/bin/env python
2
- from __future__ import print_function
3
-
1
+ from distutils .cmd import Command
2
+ from distutils .util import execute
4
3
import os
4
+ import platform
5
5
import shutil
6
- from distutils .util import execute
7
6
from subprocess import call
7
+ import warnings
8
8
9
9
from setuptools import setup , find_packages
10
+ from setuptools .command .develop import develop
10
11
from setuptools .command .install import install
11
12
12
13
@@ -15,20 +16,21 @@ def udev_reload_rules():
15
16
16
17
17
18
def udev_trigger ():
18
- call (["udevadm" , "trigger" , "--subsystem-match=usb" , "--attr-match=idVendor=04d8" , "--action=add" ])
19
+ call (
20
+ [
21
+ "udevadm" ,
22
+ "trigger" ,
23
+ "--subsystem-match=usb" ,
24
+ "--attr-match=idVendor=04d8" ,
25
+ "--action=add" ,
26
+ ]
27
+ )
19
28
20
29
21
- def install_udev_rules (raise_exception ):
22
- if check_root ():
23
- shutil .copy ('99-pslab.rules' , '/etc/udev/rules.d' )
24
- execute (udev_reload_rules , [], "Reloading udev rules" )
25
- execute (udev_trigger , [], "Triggering udev rules" )
26
- else :
27
- msg = "You must have root privileges to install udev rules. Run 'sudo python setup.py install'"
28
- if raise_exception :
29
- raise OSError (msg )
30
- else :
31
- print (msg )
30
+ def install_udev_rules ():
31
+ shutil .copy ("99-pslab.rules" , "/lib/udev/rules.d" )
32
+ execute (udev_reload_rules , [], "Reloading udev rules" )
33
+ execute (udev_trigger , [], "Triggering udev rules" )
32
34
33
35
34
36
def check_root ():
@@ -37,22 +39,65 @@ def check_root():
37
39
38
40
class CustomInstall (install ):
39
41
def run (self ):
40
- if not hasattr (self , "root" ):
41
- install_udev_rules (True )
42
- elif self .root is not None :
43
- if 'debian' not in self .root :
44
- install_udev_rules (True )
45
42
install .run (self )
43
+ self .run_command ("udev" )
44
+
45
+
46
+ class CustomDevelop (develop ):
47
+ def run (self ):
48
+ develop .run (self )
49
+ try :
50
+ self .run_command ("udev" )
51
+ except OSError as e :
52
+ warnings .warn (e )
53
+
54
+
55
+ class InstallUdevRules (Command ):
56
+ description = "install udev rules (requires root privileges)."
57
+ user_options = []
58
+
59
+ def initialize_options (self ):
60
+ pass
61
+
62
+ def finalize_options (self ):
63
+ pass
64
+
65
+ def run (self ):
66
+ if platform .system () == "Linux" :
67
+ if check_root ():
68
+ install_udev_rules ()
69
+ else :
70
+ msg = "You must have root privileges to install udev rules."
71
+ raise OSError (msg )
46
72
47
73
48
- setup (name = 'PSL' ,
49
- version = '1.1.0' ,
50
- description = 'Pocket Science Lab by FOSSASIA' ,
51
- author = 'FOSSASIA PSLab Developers' ,
52
- author_email = 'pslab-fossasia@googlegroups.com' ,
53
- url = 'https://pslab.io/' ,
54
- install_requires = ['numpy>=1.16.3.' , 'pyqtgraph>=0.9.10' ],
55
- packages = find_packages (),
56
- package_data = {'' : ['*.css' , '*.png' , '*.gif' , '*.html' , '*.css' , '*.js' , '*.png' , '*.jpg' , '*.jpeg' , '*.htm' ,
57
- '99-pslab.rules' ]},
58
- cmdclass = {'install' : CustomInstall })
74
+ setup (
75
+ name = "PSL" ,
76
+ version = "1.1.0" ,
77
+ description = "Pocket Science Lab by FOSSASIA" ,
78
+ author = "FOSSASIA PSLab Developers" ,
79
+ author_email = "pslab-fossasia@googlegroups.com" ,
80
+ url = "https://pslab.io/" ,
81
+ install_requires = ["numpy>=1.16.3." ],
82
+ packages = find_packages (),
83
+ package_data = {
84
+ "" : [
85
+ "*.css" ,
86
+ "*.png" ,
87
+ "*.gif" ,
88
+ "*.html" ,
89
+ "*.css" ,
90
+ "*.js" ,
91
+ "*.png" ,
92
+ "*.jpg" ,
93
+ "*.jpeg" ,
94
+ "*.htm" ,
95
+ "99-pslab.rules" ,
96
+ ]
97
+ },
98
+ cmdclass = {
99
+ "develop" : CustomDevelop ,
100
+ "install" : CustomInstall ,
101
+ "udev" : InstallUdevRules ,
102
+ },
103
+ )
0 commit comments