Skip to content

Commit 7ba60cb

Browse files
committed
Fix for issue #212
1 parent fe507ac commit 7ba60cb

23 files changed

+802
-673
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ env*/*
2323
pyenv*
2424
*.loop
2525
*.spec
26+
venv/
27+
.venv/

s_tui/about_menu.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,31 @@
4343
\n\
4444
"""
4545

46-
ABOUT_MESSAGE += "s-tui " + __version__ +\
47-
" Released under GNU GPLv2 "
46+
ABOUT_MESSAGE += "s-tui " + __version__ + " Released under GNU GPLv2 "
4847

4948
MESSAGE_LEN = 20
5049

5150

5251
class AboutMenu:
53-
"""Displays the About message menu """
52+
"""Displays the About message menu"""
53+
5454
MAX_TITLE_LEN = 50
5555

5656
def __init__(self, return_fn):
57-
5857
self.return_fn = return_fn
5958

6059
self.about_message = ABOUT_MESSAGE
6160

6261
self.time_out_ctrl = urwid.Text(self.about_message)
6362

64-
cancel_button = urwid.Button('Exit', on_press=self.on_cancel)
65-
cancel_button._label.align = 'center'
63+
cancel_button = urwid.Button("Exit", on_press=self.on_cancel)
64+
cancel_button._label.align = "center"
6665

6766
if_buttons = urwid.Columns([cancel_button])
6867

69-
title = urwid.Text(('bold text', u" About Menu \n"), 'center')
68+
title = urwid.Text(("bold text", " About Menu \n"), "center")
7069

71-
self.titles = [title,
72-
self.time_out_ctrl,
73-
if_buttons]
70+
self.titles = [title, self.time_out_ctrl, if_buttons]
7471

7572
self.main_window = urwid.LineBox(ViListBox(self.titles))
7673

s_tui/help_menu.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,32 @@
5252

5353

5454
class HelpMenu:
55-
""" HelpMenu is a widget containing instructions on usage of s-tui"""
55+
"""HelpMenu is a widget containing instructions on usage of s-tui"""
56+
5657
MAX_TITLE_LEN = 90
5758

5859
def __init__(self, return_fn):
59-
6060
self.return_fn = return_fn
6161

6262
self.help_message = HELP_MESSAGE
6363

6464
self.time_out_ctrl = urwid.Text(self.help_message)
6565

66-
cancel_button = urwid.Button(('Exit'), on_press=self.on_cancel)
67-
cancel_button._label.align = 'center'
66+
cancel_button = urwid.Button(("Exit"), on_press=self.on_cancel)
67+
cancel_button._label.align = "center"
6868

6969
if_buttons = urwid.Columns([cancel_button])
7070

71-
title = urwid.Text(('bold text', u" Help Menu \n"), 'center')
71+
title = urwid.Text(("bold text", " Help Menu \n"), "center")
7272

73-
self.titles = [title,
74-
self.time_out_ctrl,
75-
if_buttons]
73+
self.titles = [title, self.time_out_ctrl, if_buttons]
7674

7775
self.main_window = urwid.LineBox(ViListBox(self.titles))
7876

7977
def get_size(self):
80-
""" returns size of HelpMenu"""
78+
"""returns size of HelpMenu"""
8179
return MESSAGE_LEN + 3, self.MAX_TITLE_LEN
8280

8381
def on_cancel(self, w):
84-
""" Returns to original widget"""
82+
"""Returns to original widget"""
8583
self.return_fn()

s_tui/helper_functions.py

+39-33
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
from collections import OrderedDict
3232

33-
__version__ = "1.1.4"
33+
__version__ = "1.1.5"
3434

3535
_DEFAULT = object()
3636
PY3 = sys.version_info[0] == 3
@@ -46,24 +46,28 @@
4646

4747

4848
def get_processor_name():
49-
""" Returns the processor name in the system """
49+
"""Returns the processor name in the system"""
5050
if platform.system() == "Linux":
5151
with open("/proc/cpuinfo", "rb") as cpuinfo:
5252
all_info = cpuinfo.readlines()
5353
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)
5656
elif platform.system() == "FreeBSD":
5757
cmd = ["sysctl", "-n", "hw.model"]
5858
process = subprocess.Popen(
59-
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
59+
cmd,
60+
stdout=subprocess.PIPE,
61+
stderr=subprocess.PIPE,
6062
)
6163
str_value = process.stdout.read()
6264
return str_value
6365
elif platform.system() == "Darwin":
64-
cmd = ['sysctl', '-n', 'machdep.cpu.brand_string']
66+
cmd = ["sysctl", "-n", "machdep.cpu.brand_string"]
6567
process = subprocess.Popen(
66-
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
68+
cmd,
69+
stdout=subprocess.PIPE,
70+
stderr=subprocess.PIPE,
6771
)
6872
str_value = process.stdout.read()
6973
return str_value
@@ -72,25 +76,25 @@ def get_processor_name():
7276

7377

7478
def kill_child_processes(parent_proc):
75-
""" Kills a process and all its children """
79+
"""Kills a process and all its children"""
7680
logging.debug("Killing stress process")
7781
try:
7882
for proc in parent_proc.children(recursive=True):
79-
logging.debug('Killing %s', proc)
83+
logging.debug("Killing %s", proc)
8084
proc.kill()
8185
parent_proc.kill()
8286
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")
8589

8690

8791
def output_to_csv(sources, csv_writeable_file):
8892
"""Print statistics to csv file"""
8993
file_exists = os.path.isfile(csv_writeable_file)
9094

91-
with open(csv_writeable_file, 'a') as csvfile:
95+
with open(csv_writeable_file, "a") as csvfile:
9296
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")})
9498
summaries = [val for key, val in sources.items()]
9599
for summarie in summaries:
96100
update_dict = dict()
@@ -139,11 +143,11 @@ def get_user_config_dir():
139143
"""
140144
Return the path to the user s-tui config directory
141145
"""
142-
user_home = os.getenv('XDG_CONFIG_HOME')
146+
user_home = os.getenv("XDG_CONFIG_HOME")
143147
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"))
145149
else:
146-
config_path = os.path.join(user_home, 's-tui')
150+
config_path = os.path.join(user_home, "s-tui")
147151

148152
return config_path
149153

@@ -152,9 +156,9 @@ def get_config_dir():
152156
"""
153157
Return the path to the user home config directory
154158
"""
155-
user_home = os.getenv('XDG_CONFIG_HOME')
159+
user_home = os.getenv("XDG_CONFIG_HOME")
156160
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"))
158162
else:
159163
config_path = user_home
160164

@@ -165,12 +169,13 @@ def get_user_config_file():
165169
"""
166170
Return the path to the user s-tui config directory
167171
"""
168-
user_home = os.getenv('XDG_CONFIG_HOME')
172+
user_home = os.getenv("XDG_CONFIG_HOME")
169173
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+
)
172177
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")
174179

175180
return config_path
176181

@@ -212,32 +217,33 @@ def make_user_config_dir():
212217
if not user_config_dir_exists():
213218
try:
214219
os.mkdir(config_path)
215-
os.mkdir(os.path.join(config_path, 'hooks.d'))
220+
os.mkdir(os.path.join(config_path, "hooks.d"))
216221
except OSError:
217222
return None
218223

219224
return config_path
220225

221226

222227
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
227232
return "%02d:%02d:%02d" % (hours, minutes, seconds)
228233

229234

230235
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":
233238
return True
234-
if string == 'False':
239+
if string == "False":
235240
return False
236241
raise ValueError
237242

238243

239244
def which(program):
240-
""" Find the path of an executable """
245+
"""Find the path of an executable"""
246+
241247
def is_exe(fpath):
242248
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
243249

@@ -264,8 +270,8 @@ def _open_text(fname, **kwargs):
264270
On Python 2 this is just an alias for open(name, 'rt').
265271
"""
266272
if PY3:
267-
kwargs.setdefault('encoding', ENCODING)
268-
kwargs.setdefault('errors', ENCODING_ERRS)
273+
kwargs.setdefault("encoding", ENCODING)
274+
kwargs.setdefault("errors", ENCODING_ERRS)
269275
return open(fname, "rt", **kwargs)
270276

271277

0 commit comments

Comments
 (0)