diff --git a/tools.py b/tools.py index 08b022e..6284a9c 100644 --- a/tools.py +++ b/tools.py @@ -6,6 +6,7 @@ import ast import contextlib import dis +import enum import functools import hashlib import io @@ -31,7 +32,7 @@ import gut import termstr -class Status: +class Status(enum.IntEnum): ok = 1 problem = 2 diff --git a/vigil b/vigil index 24b78bc..67272ae 100755 --- a/vigil +++ b/vigil @@ -54,6 +54,7 @@ Keys: import asyncio import collections import contextlib +import enum import functools import gzip import multiprocessing @@ -129,7 +130,7 @@ def dump_pickle_safe(object_, path, protocol=pickle.HIGHEST_PROTOCOL, def status_to_str(status, is_status_simple): - if isinstance(status, int): # is a status enumeration + if isinstance(status, enum.Enum): dict_ = (tools._STATUS_TO_TERMSTR_SIMPLE if is_status_simple else tools._STATUS_TO_TERMSTR) return dict_[status] @@ -233,8 +234,8 @@ class Entry(collections.UserList): status_color = tools._STATUS_COLORS.get( result_selected.status, None) fg_color = (termstr.Color.white - if (status_color is None - or (sum(status_color) / 3) < (255 / 2)) + if (status_color is None or + (sum(status_color) / 3) < (255 / 2)) else termstr.Color.black) return fill3.Text(termstr.TermStr("●", termstr.CharStyle( fg_color=fg_color, bg_color=status_color))) @@ -1147,8 +1148,11 @@ def manage_cache(root_path): open(timestamp_path, "w").close() -def process_arguments(): +def check_arguments(): arguments = docopt.docopt(__doc__.replace("*", ""), help=False) + if arguments["--help"]: + print(_get_help_text()) + sys.exit(0) try: worker_count = (int(arguments["--workers"]) if arguments["--workers"] is not None else multiprocessing.cpu_count() * 2) @@ -1158,10 +1162,6 @@ def process_arguments(): if worker_count == 0: print("There must be at least one worker.") sys.exit(1) - show_help = arguments["--help"] - if show_help: - print(_get_help_text()) - sys.exit(0) root_path = os.path.abspath(arguments[""]) if not os.path.exists(root_path): print("File does not exist:", root_path) @@ -1176,7 +1176,7 @@ def process_arguments(): if __name__ == "__main__": - root_path, worker_count, is_sandboxed, editor_command = process_arguments() + root_path, worker_count, is_sandboxed, editor_command = check_arguments() if is_sandboxed: subprocess.call(["sudo", "-p", "Vigil needs sudo to create the filesy" "stem sandbox... [sudo] password for %u: ", "true"]) diff --git a/worker.py b/worker.py index ae51071..5d79f43 100755 --- a/worker.py +++ b/worker.py @@ -40,7 +40,7 @@ class Worker: self.process.stdin.write(("%s\n%s\n" % (tool.__qualname__, path)).encode("utf-8")) self.process.stdin.flush() - return int(self.process.stdout.readline()) + return tools.Status(int(self.process.stdout.readline())) def pause(self): os.kill(self.child_pid, signal.SIGSTOP) @@ -56,7 +56,7 @@ def main(): tool = getattr(tools, tool_name) result = vigil.Result(path, tool) status, result.result = tools.run_tool_no_error(path, tool) - print(status, flush=True) + print(status.value, flush=True) if __name__ == "__main__":