diff --git a/tools.py b/tools.py index f92719a..6436ec2 100644 --- a/tools.py +++ b/tools.py @@ -32,7 +32,7 @@ import lscolors import termstr -_CACHE_PATH = ".vigil" +CACHE_PATH = ".vigil" class Status(enum.IntEnum): @@ -626,8 +626,7 @@ class Result: self.path = path self.tool = tool self._open_func = gzip.open if is_stored_compressed else open - 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.is_completed = False self.is_placeholder = True @@ -657,9 +656,9 @@ class Result: def run(self, log, appearance_changed_event, worker, runner): self.is_placeholder = False - tool_name = _tool_name_colored(self.tool, self.path) - path_colored = _path_colored(self.path) - log.log_message(["Running ", tool_name, " on ", path_colored, "..."]) + tool_name = tool_name_colored(self.tool, self.path) + path = path_colored(self.path) + log.log_message(["Running ", tool_name, " on ", path, "..."]) self.set_status(Status.running) if runner.is_already_paused: runner.is_already_paused = False @@ -673,7 +672,7 @@ class Result: appearance_changed_event.set() self.is_completed = True log.log_message( - ["Finished running ", tool_name, " on ", path_colored, ". ", + ["Finished running ", tool_name, " on ", path, ". ", status_to_str(new_status, self.entry.summary.is_status_simple), " %s secs" % round(end_time - start_time, 2)]) @@ -750,10 +749,6 @@ def tools_for_path(path): return _generic_tools() + extra_tools -def _get_python_traceback_lexer(): - return pygments.lexers.PythonTracebackLexer() - - def run_tool_no_error(path, tool): try: status, result = tool(path) @@ -761,7 +756,7 @@ def run_tool_no_error(path, tool): status, result = Status.timed_out, fill3.Text("Timed out") except: status, result = Status.error, _syntax_highlight( - traceback.format_exc(), _get_python_traceback_lexer(), + traceback.format_exc(), pygments.lexers.PythonTracebackLexer(), pygments.styles.get_style_by_name("native")) return status, result @@ -787,7 +782,7 @@ def _charstyle_of_path(path): @functools.lru_cache(maxsize=100) -def _path_colored(path): +def path_colored(path): char_style = _charstyle_of_path(path) path = path[2:] dirname, basename = os.path.split(path) @@ -800,7 +795,7 @@ def _path_colored(path): @functools.lru_cache(maxsize=100) -def _tool_name_colored(tool, path): +def tool_name_colored(tool, path): char_style = (termstr.CharStyle(is_bold=True) if tool in _generic_tools() else _charstyle_of_path(path)) return termstr.TermStr(tool.__name__, char_style) diff --git a/vigil b/vigil index f6d432e..5e09732 100755 --- a/vigil +++ b/vigil @@ -134,7 +134,7 @@ class Entry(collections.UserList): if self.highlighted is not None: self.widget[self.highlighted] = self._get_cursor() new_appearance = self.widget.appearance_min() - path = tools._path_colored(self.path) + path = tools.path_colored(self.path) padding = " " * (self.summary._max_path_length - len(path) + 1) new_appearance[0] = path + padding + new_appearance[0] self.appearance_cache = appearance = new_appearance @@ -423,9 +423,9 @@ class Summary: selection = self.get_selection() if selection.status not in {tools.Status.running, tools.Status.paused, tools.Status.pending}: - tool_name = tools._tool_name_colored( + tool_name = tools.tool_name_colored( selection.tool, selection.path) - path_colored = tools._path_colored(selection.path) + path_colored = tools.path_colored(selection.path) log.log_message([_in_green("Refreshing "), tool_name, _in_green(" result of "), path_colored, _in_green("...")]) @@ -439,7 +439,7 @@ class Log: _GREY_BOLD_STYLE = termstr.CharStyle(termstr.Color.grey_100, is_bold=True) _GREEN_STYLE = termstr.CharStyle(termstr.Color.green) - _LOG_PATH = os.path.join(tools._CACHE_PATH, "log") + _LOG_PATH = os.path.join(tools.CACHE_PATH, "log") def __init__(self, appearance_changed_event): self._appearance_changed_event = appearance_changed_event @@ -681,7 +681,7 @@ class Screen: "See option -e.") else: path = self._summary.get_selection().path - path_colored = tools._path_colored(path) + path_colored = tools.path_colored(path) self._log.log_message([_in_green("Editing "), path_colored, _in_green(' with command: "%s"...' % self.editor_command)]) @@ -790,9 +790,9 @@ class Screen: view = self._listing.widget.view view.position = widget.scroll_position view.widget = widget.result - tool_name = tools._tool_name_colored(widget.tool, widget.path) + tool_name = tools.tool_name_colored(widget.tool, widget.path) self._listing.title = ( - tools._path_colored(widget.path) + " ─── " + tool_name + " " + + tools.path_colored(widget.path) + " ─── " + tool_name + " " + tools.status_to_str(widget.status, self._summary.is_status_simple)) incomplete = self._summary.result_total - self._summary.completed_total progress_bar_size = max(0, width * incomplete // @@ -930,7 +930,7 @@ def main(root_path, worker_count=None, is_sandboxed=True, editor_command=None, appearance_changed_event = threading.Event() is_first_run = True try: - pickle_path = os.path.join(tools._CACHE_PATH, "summary.pickle") + pickle_path = os.path.join(tools.CACHE_PATH, "summary.pickle") with gzip.open(pickle_path, "rb") as file_: screen = pickle.load(file_) except FileNotFoundError: @@ -1038,7 +1038,7 @@ def _chdir(path): def _manage_cache(root_path): - cache_path = os.path.join(root_path, tools._CACHE_PATH) + cache_path = os.path.join(root_path, tools.CACHE_PATH) timestamp_path = os.path.join(cache_path, "creation_time") if os.path.exists(cache_path) and \ os.stat(__file__).st_mtime > os.stat(timestamp_path).st_mtime: diff --git a/worker.py b/worker.py index abef5e1..a738c3e 100755 --- a/worker.py +++ b/worker.py @@ -27,7 +27,7 @@ class Worker: [__file__], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: - cache_path = os.path.join(os.getcwd(), tools._CACHE_PATH) + cache_path = os.path.join(os.getcwd(), tools.CACHE_PATH) self.cache_mount = sandbox.mount_point + cache_path subprocess.check_call(["sudo", "mount", "--bind", cache_path, self.cache_mount]) diff --git a/worker_test.py b/worker_test.py index 8ff7404..e3a4240 100755 --- a/worker_test.py +++ b/worker_test.py @@ -20,7 +20,7 @@ class WorkerTestCase(unittest.TestCase): self.temp_dir = tempfile.mkdtemp() self.original_working_dir = os.getcwd() os.chdir(self.temp_dir) - os.mkdir(tools._CACHE_PATH) + os.mkdir(tools.CACHE_PATH) open("foo", "w").close() def tearDown(self): @@ -30,7 +30,7 @@ class WorkerTestCase(unittest.TestCase): def _test_worker(self, sandbox): status = worker.Worker(sandbox).run_tool("foo", tools.metadata) self.assertEqual(status, tools.Status.normal) - result_path = os.path.join(tools._CACHE_PATH, "foo-metadata") + result_path = os.path.join(tools.CACHE_PATH, "foo-metadata") self.assertTrue(os.path.exists(result_path)) def test_run_job_without_sandbox(self):