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