Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #212 #213

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.8, 3.9, '3.10', 3.11]

steps:
- uses: actions/checkout@v1
Expand Down
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
Loading