Coding style.
Make tools.Status into an enumeration.
This commit is contained in:
parent
2d370ea9a0
commit
e8411269ca
3 changed files with 13 additions and 12 deletions
3
tools.py
3
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
|
||||
|
|
|
|||
18
vigil
18
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["<directory>"])
|
||||
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"])
|
||||
|
|
|
|||
|
|
@ -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__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue