5
5
6
6
7
7
import os .path
8
- import commands
8
+ import subprocess
9
9
import logging
10
10
11
11
try :
17
17
18
18
def show_log (txt ):
19
19
if DEBUG == True :
20
- print "[IX1B ]"+ txt
20
+ print ( "[IX2 ]"+ txt )
21
21
return
22
22
23
23
def exec_cmd (cmd , show ):
24
24
logging .info ('Run :' + cmd )
25
- status , output = commands . getstatusoutput ( cmd )
26
- show_log ( cmd + "with result:" + str ( status ) )
27
- show_log ( " output:"+ output )
28
- if status :
29
- logging .info (' Failed :' + cmd )
25
+ try :
26
+ output = subprocess . check_output ( cmd , shell = True )
27
+ show_log ( cmd + " output:"+ str ( output ) )
28
+ except subprocess . CalledProcessError as e :
29
+ logging .info (" Failed :" + cmd )
30
30
if show :
31
- print (' Failed :' + cmd )
32
- return status , output
31
+ print (" Failed :" + cmd + "returncode = {}, err msg: {}" . format ( e . returncode , e . output ) )
32
+ return output
33
33
34
34
def my_log (txt ):
35
35
if DEBUG == True :
36
- print "[QUANTA DBG]: " + txt
36
+ print ( "[QUANTA DBG]: " + txt )
37
37
return
38
38
39
39
def log_os_system (cmd , show ):
40
40
logging .info ('Run :' + cmd )
41
41
status = 1
42
42
output = ""
43
- status , output = commands .getstatusoutput (cmd )
44
- my_log (cmd + "with result:" + str (status ))
45
- my_log ("cmd:" + cmd )
46
- my_log (" output:" + output )
47
- if status :
43
+ try :
44
+ output = subprocess .check_output (cmd , shell = True )
45
+ my_log (cmd + "output:" + str (output ))
46
+ except subprocess .CalledProcessError as e :
48
47
logging .info ('Failed :' + cmd )
49
48
if show :
50
- print (' Failed :' + cmd )
51
- return status , output
49
+ print (" Failed :" + cmd + "returncode = {}, err msg: {}" . format ( e . returncode , e . output ) )
50
+ return output
52
51
53
52
def gpio16_exist ():
54
- ret , ls = log_os_system ("ls /sys/class/gpio/ | grep gpio16" , 0 )
53
+ ls = log_os_system ("ls /sys/class/gpio/ | grep gpio16" , 0 )
55
54
logging .info ('mods:' + ls )
56
55
if len (ls ) == 0 :
57
56
return False
58
57
59
58
def gpio17_exist ():
60
- ret , ls = log_os_system ("ls /sys/class/gpio/ | grep gpio17" , 0 )
59
+ ls = log_os_system ("ls /sys/class/gpio/ | grep gpio17" , 0 )
61
60
logging .info ('mods:' + ls )
62
61
if len (ls ) == 0 :
63
62
return False
64
63
65
64
def gpio19_exist ():
66
- ret , ls = log_os_system ("ls /sys/class/gpio/ | grep gpio19" , 0 )
65
+ ls = log_os_system ("ls /sys/class/gpio/ | grep gpio19" , 0 )
67
66
logging .info ('mods:' + ls )
68
67
if len (ls ) == 0 :
69
68
return False
70
69
71
70
def gpio20_exist ():
72
- ret , ls = log_os_system ("ls /sys/class/gpio/ | grep gpio20" , 0 )
71
+ ls = log_os_system ("ls /sys/class/gpio/ | grep gpio20" , 0 )
73
72
logging .info ('mods:' + ls )
74
73
if len (ls ) == 0 :
75
74
return False
@@ -86,20 +85,20 @@ def __init__(self):
86
85
PsuBase .__init__ (self )
87
86
88
87
if gpio16_exist () == False :
89
- status , output = exec_cmd ("echo 16 > /sys/class/gpio/export " , 1 )
90
- status , output = exec_cmd ("echo in > /sys/class/gpio/gpio16/direction " , 1 )
88
+ output = exec_cmd ("echo 16 > /sys/class/gpio/export " , 1 )
89
+ output = exec_cmd ("echo in > /sys/class/gpio/gpio16/direction " , 1 )
91
90
92
91
if gpio17_exist () == False :
93
- status , output = exec_cmd ("echo 17 > /sys/class/gpio/export " , 1 )
94
- status , output = exec_cmd ("echo in > /sys/class/gpio/gpio17/direction " , 1 )
92
+ output = exec_cmd ("echo 17 > /sys/class/gpio/export " , 1 )
93
+ output = exec_cmd ("echo in > /sys/class/gpio/gpio17/direction " , 1 )
95
94
96
95
if gpio19_exist () == False :
97
- status , output = exec_cmd ("echo 19 > /sys/class/gpio/export " , 1 )
98
- status , output = exec_cmd ("echo in > /sys/class/gpio/gpio19/direction " , 1 )
96
+ output = exec_cmd ("echo 19 > /sys/class/gpio/export " , 1 )
97
+ output = exec_cmd ("echo in > /sys/class/gpio/gpio19/direction " , 1 )
99
98
100
99
if gpio20_exist () == False :
101
- status , output = exec_cmd ("echo 20 > /sys/class/gpio/export " , 1 )
102
- status , output = exec_cmd ("echo in > /sys/class/gpio/gpio20/direction " , 1 )
100
+ output = exec_cmd ("echo 20 > /sys/class/gpio/export " , 1 )
101
+ output = exec_cmd ("echo in > /sys/class/gpio/gpio20/direction " , 1 )
103
102
104
103
# Get sysfs attribute
105
104
def get_attr_value (self , attr_path ):
0 commit comments