Coding style.

This commit is contained in:
Andrew Hamilton 2019-04-30 21:33:17 +10:00
parent 9c9a0b5e5f
commit aec31c199e
2 changed files with 19 additions and 12 deletions

View file

@ -467,8 +467,7 @@ class Summary:
return return
def refresh_result(self, result): def refresh_result(self, result):
if result.status not in {tools.Status.running, tools.Status.paused, if result.is_completed:
tools.Status.pending}:
result.reset() result.reset()
self.closest_placeholder_generator = None self.closest_placeholder_generator = None
self._jobs_added_event.set() self._jobs_added_event.set()
@ -480,6 +479,13 @@ class Summary:
if result.tool == tool: if result.tool == tool:
self.refresh_result(result) self.refresh_result(result)
def clear_running(self):
for row in self._column:
for result in row:
if result.status in [tools.Status.running,
tools.Status.paused]:
self.refresh_result(result)
def as_html(self): def as_html(self):
html_parts = [] html_parts = []
styles = set() styles = set()
@ -1030,6 +1036,7 @@ def load_state(pickle_path, jobs_added_event, appearance_changed_event,
summary = screen._summary summary = screen._summary
summary._jobs_added_event = jobs_added_event summary._jobs_added_event = jobs_added_event
summary._root_path = root_path summary._root_path = root_path
summary.clear_running()
log = screen._log log = screen._log
log._appearance_changed_event = appearance_changed_event log._appearance_changed_event = appearance_changed_event
return summary, screen, log, is_first_run return summary, screen, log, is_first_run

View file

@ -524,12 +524,9 @@ for tool_name, tool_toml in tools_toml.items():
############################# #############################
LOG_PATH = os.path.join(os.getcwd(), "eris.log")
def log_error(message=None): def log_error(message=None):
message = traceback.format_exc() if message is None else message + "\n" message = traceback.format_exc() if message is None else message + "\n"
with open(LOG_PATH, "a") as log_file: with open("/tmp/eris.log", "a") as log_file:
log_file.write(message) log_file.write(message)
@ -578,20 +575,22 @@ def status_to_str(status):
class Result: class Result:
COMPLETED_STATUSES = {
Status.ok, Status.problem, Status.normal, Status.error,
Status.not_applicable, Status.timed_out}
def __init__(self, path, tool): def __init__(self, path, tool):
self.path = path self.path = path
self.tool = tool self.tool = tool
self.pickle_path = os.path.join(CACHE_PATH, path + "-" + tool.__name__) self.pickle_path = os.path.join(CACHE_PATH, path + "-" + tool.__name__)
self.scroll_position = (0, 0) self.scroll_position = (0, 0)
self.is_completed = False
self.is_placeholder = True
self.status = Status.pending self.status = Status.pending
@property @property
@lru_cache_with_eviction(maxsize=50) @lru_cache_with_eviction(maxsize=50)
def result(self): def result(self):
unknown_label = fill3.Text("?") unknown_label = fill3.Text("?")
if self.is_placeholder: if self.status == Status.pending:
return unknown_label return unknown_label
try: try:
with gzip.open(self.pickle_path, "rb") as pickle_file: with gzip.open(self.pickle_path, "rb") as pickle_file:
@ -609,8 +608,11 @@ class Result:
self.status = status self.status = status
self.entry.appearance_cache = None self.entry.appearance_cache = None
@property
def is_completed(self):
return self.status in Result.COMPLETED_STATUSES
async def run(self, log, appearance_changed_event, runner): async def run(self, log, appearance_changed_event, runner):
self.is_placeholder = False
tool_name = tool_name_colored(self.tool, self.path) tool_name = tool_name_colored(self.tool, self.path)
path = path_colored(self.path) path = path_colored(self.path)
log.log_message(["Running ", tool_name, " on ", path, "..."]) log.log_message(["Running ", tool_name, " on ", path, "..."])
@ -625,14 +627,12 @@ class Result:
end_time = time.time() end_time = time.time()
self.set_status(new_status) self.set_status(new_status)
appearance_changed_event.set() appearance_changed_event.set()
self.is_completed = True
log.log_message( log.log_message(
["Finished running ", tool_name, " on ", path, ". ", ["Finished running ", tool_name, " on ", path, ". ",
status_to_str(new_status), status_to_str(new_status),
f" {round(end_time - start_time, 2)} secs"]) f" {round(end_time - start_time, 2)} secs"])
def reset(self): def reset(self):
self.is_placeholder = True
self.set_status(Status.pending) self.set_status(Status.pending)
def appearance_min(self): def appearance_min(self):