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