Skip to content

Commit

Permalink
Manual Refactorings (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
danparizher authored Apr 1, 2023
1 parent 67196e6 commit 122a7dc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 31 deletions.
13 changes: 3 additions & 10 deletions pop-stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,13 @@ def get_num_lines(self, file_path):

def parse_log(self):
# Identify all log files and total number of log lines
total_log_lines = 0
for logfile in glob.glob(self.logfile):
total_log_lines += self.get_num_lines(logfile)

total_log_lines = sum(self.get_num_lines(logfile) for logfile in glob.glob(self.logfile))
progress = tqdm(total=total_log_lines, leave=True, unit=" lines", unit_scale=True)
for logfile in glob.glob(self.logfile):
with open(logfile, "rt") as infile:
for line in infile:
# Grab the lines we're interested in
regex = REGEX.match(line)
if regex:
if regex := REGEX.match(line):
if self.period and self.get_date() not in regex.group(1):
continue

Expand All @@ -81,10 +77,7 @@ def print_stats(self):
# Parse our log file if we haven't done that yet
self.parse_log()

total = 0
for k, v in self.data.items():
total += v[1]

total = sum(v[1] for k, v in self.data.items())
print(f"Average node pop times (out of {total} pops in total)")
for k, v in self.data.items():
print(f"{k.split(':')[0]:15} {round(v[0]/v[1], 2)} secs {v[1]:-8} jobs from this node")
Expand Down
5 changes: 2 additions & 3 deletions style.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@

if args.debug:
for process in lint_processes:
VERSION_COMMAND = process[0] + " --version"
VERSION_COMMAND = f"{process[0]} --version"
subprocess.run(VERSION_COMMAND, shell=True, check=True)
print()

for process_args in lint_processes:
process_args.extend(src)

COMMAND = "python -s -m "
COMMAND += " ".join(process_args)
COMMAND = "python -s -m " + " ".join(process_args)
print(f"\nRunning {COMMAND}")
try:
subprocess.run(COMMAND, shell=True, check=True)
Expand Down
20 changes: 7 additions & 13 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
# Helper class to access dictionaries
class DotDict(dict):
def __getattr__(self, attr):
if attr in self:
return self[attr]
return None
return self[attr] if attr in self else None

def __setattr__(self, attr, value):
self[attr] = value
Expand Down Expand Up @@ -200,21 +198,17 @@ def __init__(self):
self.app = None

def _label(self, name):
if name in WebUI.INFO:
return WebUI.INFO[name]["label"]
return None
return WebUI.INFO[name]["label"] if name in WebUI.INFO else None

def _info(self, name):
if name in WebUI.INFO:
return f"{WebUI.INFO[name]['info']} [{name}]"
return None
return f"{WebUI.INFO[name]['info']} [{name}]" if name in WebUI.INFO else None

# Label to config item name
def _cfg(self, label):
for key, value in WebUI.INFO.items():
if value["label"] == label:
return key
return None
return next(
(key for key, value in WebUI.INFO.items() if value["label"] == label),
None,
)

def reload_config(self):
# Sanity check, to ensure Tazlin doesn't give me a hard time
Expand Down
10 changes: 5 additions & 5 deletions worker/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def print_log(self):
colour = TerminalUI.COLOUR_WHITE
elif cat == "ERROR":
colour = TerminalUI.COLOUR_RED
elif cat == "INIT" or cat == "INIT_OK":
elif cat in ["INIT", "INIT_OK"]:
colour = TerminalUI.COLOUR_MAGENTA
elif cat == "WARNING":
colour = TerminalUI.COLOUR_YELLOW
Expand Down Expand Up @@ -644,10 +644,10 @@ def load_worker_id(self):
return None
if r.ok:
worker_json = r.json()
for item in worker_json:
if item["name"] == self.worker_name:
return item["id"]
return None
return next(
(item["id"] for item in worker_json if item["name"] == self.worker_name),
None,
)
return None

def set_maintenance_mode(self, enabled):
Expand Down

0 comments on commit 122a7dc

Please sign in to comment.