30
30
31
31
from collections import OrderedDict
32
32
33
- __version__ = "1.1.4 "
33
+ __version__ = "1.1.5 "
34
34
35
35
_DEFAULT = object ()
36
36
PY3 = sys .version_info [0 ] == 3
46
46
47
47
48
48
def get_processor_name ():
49
- """ Returns the processor name in the system """
49
+ """Returns the processor name in the system"""
50
50
if platform .system () == "Linux" :
51
51
with open ("/proc/cpuinfo" , "rb" ) as cpuinfo :
52
52
all_info = cpuinfo .readlines ()
53
53
for line in all_info :
54
- if b' model name' in line :
55
- return re .sub (b' .*model name.*:' , b'' , line , 1 )
54
+ if b" model name" in line :
55
+ return re .sub (b" .*model name.*:" , b"" , line , 1 )
56
56
elif platform .system () == "FreeBSD" :
57
57
cmd = ["sysctl" , "-n" , "hw.model" ]
58
58
process = subprocess .Popen (
59
- cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
59
+ cmd ,
60
+ stdout = subprocess .PIPE ,
61
+ stderr = subprocess .PIPE ,
60
62
)
61
63
str_value = process .stdout .read ()
62
64
return str_value
63
65
elif platform .system () == "Darwin" :
64
- cmd = [' sysctl' , '-n' , ' machdep.cpu.brand_string' ]
66
+ cmd = [" sysctl" , "-n" , " machdep.cpu.brand_string" ]
65
67
process = subprocess .Popen (
66
- cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
68
+ cmd ,
69
+ stdout = subprocess .PIPE ,
70
+ stderr = subprocess .PIPE ,
67
71
)
68
72
str_value = process .stdout .read ()
69
73
return str_value
@@ -72,25 +76,25 @@ def get_processor_name():
72
76
73
77
74
78
def kill_child_processes (parent_proc ):
75
- """ Kills a process and all its children """
79
+ """Kills a process and all its children"""
76
80
logging .debug ("Killing stress process" )
77
81
try :
78
82
for proc in parent_proc .children (recursive = True ):
79
- logging .debug (' Killing %s' , proc )
83
+ logging .debug (" Killing %s" , proc )
80
84
proc .kill ()
81
85
parent_proc .kill ()
82
86
except AttributeError :
83
- logging .debug (' No such process' )
84
- logging .debug (' Could not kill process' )
87
+ logging .debug (" No such process" )
88
+ logging .debug (" Could not kill process" )
85
89
86
90
87
91
def output_to_csv (sources , csv_writeable_file ):
88
92
"""Print statistics to csv file"""
89
93
file_exists = os .path .isfile (csv_writeable_file )
90
94
91
- with open (csv_writeable_file , 'a' ) as csvfile :
95
+ with open (csv_writeable_file , "a" ) as csvfile :
92
96
csv_dict = OrderedDict ()
93
- csv_dict .update ({' Time' : time .strftime ("%Y-%m-%d_%H:%M:%S" )})
97
+ csv_dict .update ({" Time" : time .strftime ("%Y-%m-%d_%H:%M:%S" )})
94
98
summaries = [val for key , val in sources .items ()]
95
99
for summarie in summaries :
96
100
update_dict = dict ()
@@ -139,11 +143,11 @@ def get_user_config_dir():
139
143
"""
140
144
Return the path to the user s-tui config directory
141
145
"""
142
- user_home = os .getenv (' XDG_CONFIG_HOME' )
146
+ user_home = os .getenv (" XDG_CONFIG_HOME" )
143
147
if user_home is None or not user_home :
144
- config_path = os .path .expanduser (os .path .join ('~' , ' .config' , ' s-tui' ))
148
+ config_path = os .path .expanduser (os .path .join ("~" , " .config" , " s-tui" ))
145
149
else :
146
- config_path = os .path .join (user_home , ' s-tui' )
150
+ config_path = os .path .join (user_home , " s-tui" )
147
151
148
152
return config_path
149
153
@@ -152,9 +156,9 @@ def get_config_dir():
152
156
"""
153
157
Return the path to the user home config directory
154
158
"""
155
- user_home = os .getenv (' XDG_CONFIG_HOME' )
159
+ user_home = os .getenv (" XDG_CONFIG_HOME" )
156
160
if user_home is None or not user_home :
157
- config_path = os .path .expanduser (os .path .join ('~' , ' .config' ))
161
+ config_path = os .path .expanduser (os .path .join ("~" , " .config" ))
158
162
else :
159
163
config_path = user_home
160
164
@@ -165,12 +169,13 @@ def get_user_config_file():
165
169
"""
166
170
Return the path to the user s-tui config directory
167
171
"""
168
- user_home = os .getenv (' XDG_CONFIG_HOME' )
172
+ user_home = os .getenv (" XDG_CONFIG_HOME" )
169
173
if user_home is None or not user_home :
170
- config_path = os .path .expanduser (os .path .join ('~' , '.config' ,
171
- 's-tui' , 's-tui.conf' ))
174
+ config_path = os .path .expanduser (
175
+ os .path .join ("~" , ".config" , "s-tui" , "s-tui.conf" )
176
+ )
172
177
else :
173
- config_path = os .path .join (user_home , ' s-tui' , ' s-tui.conf' )
178
+ config_path = os .path .join (user_home , " s-tui" , " s-tui.conf" )
174
179
175
180
return config_path
176
181
@@ -212,32 +217,33 @@ def make_user_config_dir():
212
217
if not user_config_dir_exists ():
213
218
try :
214
219
os .mkdir (config_path )
215
- os .mkdir (os .path .join (config_path , ' hooks.d' ))
220
+ os .mkdir (os .path .join (config_path , " hooks.d" ))
216
221
except OSError :
217
222
return None
218
223
219
224
return config_path
220
225
221
226
222
227
def seconds_to_text (secs ):
223
- """ Converts seconds to a string of hours:minutes:seconds """
224
- hours = (secs )// 3600
225
- minutes = (secs - hours * 3600 )// 60
226
- seconds = secs - hours * 3600 - minutes * 60
228
+ """Converts seconds to a string of hours:minutes:seconds"""
229
+ hours = (secs ) // 3600
230
+ minutes = (secs - hours * 3600 ) // 60
231
+ seconds = secs - hours * 3600 - minutes * 60
227
232
return "%02d:%02d:%02d" % (hours , minutes , seconds )
228
233
229
234
230
235
def str_to_bool (string ):
231
- """ Converts a string to a boolean """
232
- if string == ' True' :
236
+ """Converts a string to a boolean"""
237
+ if string == " True" :
233
238
return True
234
- if string == ' False' :
239
+ if string == " False" :
235
240
return False
236
241
raise ValueError
237
242
238
243
239
244
def which (program ):
240
- """ Find the path of an executable """
245
+ """Find the path of an executable"""
246
+
241
247
def is_exe (fpath ):
242
248
return os .path .isfile (fpath ) and os .access (fpath , os .X_OK )
243
249
@@ -264,8 +270,8 @@ def _open_text(fname, **kwargs):
264
270
On Python 2 this is just an alias for open(name, 'rt').
265
271
"""
266
272
if PY3 :
267
- kwargs .setdefault (' encoding' , ENCODING )
268
- kwargs .setdefault (' errors' , ENCODING_ERRS )
273
+ kwargs .setdefault (" encoding" , ENCODING )
274
+ kwargs .setdefault (" errors" , ENCODING_ERRS )
269
275
return open (fname , "rt" , ** kwargs )
270
276
271
277
0 commit comments