Skip to content

Commit

Permalink
Fix for issue #212
Browse files Browse the repository at this point in the history
  • Loading branch information
amanusk committed Jan 26, 2024
1 parent fe507ac commit 7ba60cb
Show file tree
Hide file tree
Showing 23 changed files with 802 additions and 673 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ env*/*
pyenv*
*.loop
*.spec
venv/
.venv/
17 changes: 7 additions & 10 deletions s_tui/about_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,31 @@
\n\
"""

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

MESSAGE_LEN = 20


class AboutMenu:
"""Displays the About message menu """
"""Displays the About message menu"""

MAX_TITLE_LEN = 50

def __init__(self, return_fn):

self.return_fn = return_fn

self.about_message = ABOUT_MESSAGE

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

cancel_button = urwid.Button('Exit', on_press=self.on_cancel)
cancel_button._label.align = 'center'
cancel_button = urwid.Button("Exit", on_press=self.on_cancel)
cancel_button._label.align = "center"

if_buttons = urwid.Columns([cancel_button])

title = urwid.Text(('bold text', u" About Menu \n"), 'center')
title = urwid.Text(("bold text", " About Menu \n"), "center")

self.titles = [title,
self.time_out_ctrl,
if_buttons]
self.titles = [title, self.time_out_ctrl, if_buttons]

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

Expand Down
18 changes: 8 additions & 10 deletions s_tui/help_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,32 @@


class HelpMenu:
""" HelpMenu is a widget containing instructions on usage of s-tui"""
"""HelpMenu is a widget containing instructions on usage of s-tui"""

MAX_TITLE_LEN = 90

def __init__(self, return_fn):

self.return_fn = return_fn

self.help_message = HELP_MESSAGE

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

cancel_button = urwid.Button(('Exit'), on_press=self.on_cancel)
cancel_button._label.align = 'center'
cancel_button = urwid.Button(("Exit"), on_press=self.on_cancel)
cancel_button._label.align = "center"

if_buttons = urwid.Columns([cancel_button])

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

self.titles = [title,
self.time_out_ctrl,
if_buttons]
self.titles = [title, self.time_out_ctrl, if_buttons]

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

def get_size(self):
""" returns size of HelpMenu"""
"""returns size of HelpMenu"""
return MESSAGE_LEN + 3, self.MAX_TITLE_LEN

def on_cancel(self, w):
""" Returns to original widget"""
"""Returns to original widget"""
self.return_fn()
72 changes: 39 additions & 33 deletions s_tui/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from collections import OrderedDict

__version__ = "1.1.4"
__version__ = "1.1.5"

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


def get_processor_name():
""" Returns the processor name in the system """
"""Returns the processor name in the system"""
if platform.system() == "Linux":
with open("/proc/cpuinfo", "rb") as cpuinfo:
all_info = cpuinfo.readlines()
for line in all_info:
if b'model name' in line:
return re.sub(b'.*model name.*:', b'', line, 1)
if b"model name" in line:
return re.sub(b".*model name.*:", b"", line, 1)
elif platform.system() == "FreeBSD":
cmd = ["sysctl", "-n", "hw.model"]
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
str_value = process.stdout.read()
return str_value
elif platform.system() == "Darwin":
cmd = ['sysctl', '-n', 'machdep.cpu.brand_string']
cmd = ["sysctl", "-n", "machdep.cpu.brand_string"]
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
str_value = process.stdout.read()
return str_value
Expand All @@ -72,25 +76,25 @@ def get_processor_name():


def kill_child_processes(parent_proc):
""" Kills a process and all its children """
"""Kills a process and all its children"""
logging.debug("Killing stress process")
try:
for proc in parent_proc.children(recursive=True):
logging.debug('Killing %s', proc)
logging.debug("Killing %s", proc)
proc.kill()
parent_proc.kill()
except AttributeError:
logging.debug('No such process')
logging.debug('Could not kill process')
logging.debug("No such process")
logging.debug("Could not kill process")


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

with open(csv_writeable_file, 'a') as csvfile:
with open(csv_writeable_file, "a") as csvfile:
csv_dict = OrderedDict()
csv_dict.update({'Time': time.strftime("%Y-%m-%d_%H:%M:%S")})
csv_dict.update({"Time": time.strftime("%Y-%m-%d_%H:%M:%S")})
summaries = [val for key, val in sources.items()]
for summarie in summaries:
update_dict = dict()
Expand Down Expand Up @@ -139,11 +143,11 @@ def get_user_config_dir():
"""
Return the path to the user s-tui config directory
"""
user_home = os.getenv('XDG_CONFIG_HOME')
user_home = os.getenv("XDG_CONFIG_HOME")
if user_home is None or not user_home:
config_path = os.path.expanduser(os.path.join('~', '.config', 's-tui'))
config_path = os.path.expanduser(os.path.join("~", ".config", "s-tui"))
else:
config_path = os.path.join(user_home, 's-tui')
config_path = os.path.join(user_home, "s-tui")

return config_path

Expand All @@ -152,9 +156,9 @@ def get_config_dir():
"""
Return the path to the user home config directory
"""
user_home = os.getenv('XDG_CONFIG_HOME')
user_home = os.getenv("XDG_CONFIG_HOME")
if user_home is None or not user_home:
config_path = os.path.expanduser(os.path.join('~', '.config'))
config_path = os.path.expanduser(os.path.join("~", ".config"))
else:
config_path = user_home

Expand All @@ -165,12 +169,13 @@ def get_user_config_file():
"""
Return the path to the user s-tui config directory
"""
user_home = os.getenv('XDG_CONFIG_HOME')
user_home = os.getenv("XDG_CONFIG_HOME")
if user_home is None or not user_home:
config_path = os.path.expanduser(os.path.join('~', '.config',
's-tui', 's-tui.conf'))
config_path = os.path.expanduser(
os.path.join("~", ".config", "s-tui", "s-tui.conf")
)
else:
config_path = os.path.join(user_home, 's-tui', 's-tui.conf')
config_path = os.path.join(user_home, "s-tui", "s-tui.conf")

return config_path

Expand Down Expand Up @@ -212,32 +217,33 @@ def make_user_config_dir():
if not user_config_dir_exists():
try:
os.mkdir(config_path)
os.mkdir(os.path.join(config_path, 'hooks.d'))
os.mkdir(os.path.join(config_path, "hooks.d"))
except OSError:
return None

return config_path


def seconds_to_text(secs):
""" Converts seconds to a string of hours:minutes:seconds """
hours = (secs)//3600
minutes = (secs - hours*3600)//60
seconds = secs - hours*3600 - minutes*60
"""Converts seconds to a string of hours:minutes:seconds"""
hours = (secs) // 3600
minutes = (secs - hours * 3600) // 60
seconds = secs - hours * 3600 - minutes * 60
return "%02d:%02d:%02d" % (hours, minutes, seconds)


def str_to_bool(string):
""" Converts a string to a boolean """
if string == 'True':
"""Converts a string to a boolean"""
if string == "True":
return True
if string == 'False':
if string == "False":
return False
raise ValueError


def which(program):
""" Find the path of an executable """
"""Find the path of an executable"""

def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

Expand All @@ -264,8 +270,8 @@ def _open_text(fname, **kwargs):
On Python 2 this is just an alias for open(name, 'rt').
"""
if PY3:
kwargs.setdefault('encoding', ENCODING)
kwargs.setdefault('errors', ENCODING_ERRS)
kwargs.setdefault("encoding", ENCODING)
kwargs.setdefault("errors", ENCODING_ERRS)
return open(fname, "rt", **kwargs)


Expand Down
Loading

0 comments on commit 7ba60cb

Please sign in to comment.