Added a command-line option to run without a filesystem sandbox.

This commit is contained in:
Andrew Hamilton 2016-01-29 19:46:41 +00:00
parent fee10f1343
commit fb831607e4
2 changed files with 28 additions and 18 deletions

View file

@ -13,13 +13,14 @@
 │  │
 │  │
│Usage:  │ │Usage:  │
│ vigil <root_path>  │ │ vigil [options] <root_path>  │
 │  │
│Example:  │ │Example:  │
│ # vigil my_project  │ │ # vigil my_project  │
 │  │
│Options:  │ │Options:  │
│ -h, --help Show this screen and ex │ │ -h --help Show this screen │
│ -n --no-sandbox Don't prevent ch │
 │  │
│Keys:  │ │Keys:  │
h - Show the help screen. (toggle)  │ h - Show the help screen. (toggle)  │
@ -27,14 +28,13 @@
D, C, J, K, F, V or page up, page d │ D, C, J, K, F, V or page up, page d │
│ Scroll the result pane.  │ │ Scroll the result pane.  │
t - Turn the result pane to portrai │ t - Turn the result pane to portrai │
l - Show the activity log. (toggle)  l - Show the activity log. (toggle)
n - Move to the next issue.   n - Move to the next issue.
N - Move to the next issue of the c │ N - Move to the next issue of the c │
o - Order files by type, or by dire │ o - Order files by type, or by dire │
p - Pause work. (toggle) │ p - Pause work. (toggle) │
s - Change the appearance of result │ s - Change the appearance of result │
q - Quit. │ q - Quit. │
│ │ │ │
│Statuses: │
  │   │
└──────────────────────────────────────┘ └──────────────────────────────────────┘

36
vigil
View file

@ -19,13 +19,14 @@ The reports are cached in a directory ".vigil" under the target directory.
Usage: Usage:
vigil <root_path> vigil [options] <root_path>
Example: Example:
# vigil my_project # vigil my_project
Options: Options:
-h, --help Show this screen and exit. -h --help Show this screen and exit.
-n --no-sandbox Don't prevent changes to the filesystem.
Keys: Keys:
*h - Show the help screen. (toggle) *h - Show the help screen. (toggle)
@ -944,7 +945,7 @@ def update_screen(main_widget, appearance_changed_event):
fill3.patch_screen(main_widget) fill3.patch_screen(main_widget)
def main(root_path, is_being_tested=False): def main(root_path, is_sandboxed=True, is_being_tested=False):
global _UPDATE_THREAD_STOPPED global _UPDATE_THREAD_STOPPED
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
jobs_added_event = threading.Event() jobs_added_event = threading.Event()
@ -978,13 +979,19 @@ def main(root_path, is_being_tested=False):
watch_manager_fd = add_watch_manager_to_mainloop( watch_manager_fd = add_watch_manager_to_mainloop(
root_path, loop, on_filesystem_change, is_path_excluded) root_path, loop, on_filesystem_change, is_path_excluded)
screen.runners = runners = [] screen.runners = runners = []
sandbox_temp_dir = tempfile.mkdtemp() if is_sandboxed:
sandbox = sandbox_fs.SandboxFs(sandbox_temp_dir) sandbox_temp_dir = tempfile.mkdtemp()
sandbox = sandbox_fs.SandboxFs(sandbox_temp_dir)
else:
sandbox = None
def start_runners(): def start_runners():
log.log_message("Making filesystem sandbox...") if is_sandboxed:
sandbox.mount() log.log_message("Making filesystem sandbox...")
log.log_message("Sandbox made.") sandbox.mount()
log.log_message("Sandbox made.")
else:
log.log_message("Running without the filesystem sandbox...")
log.log_message("Starting workers...") log.log_message("Starting workers...")
worker_total = multiprocessing.cpu_count() * 2 worker_total = multiprocessing.cpu_count() * 2
for index in range(worker_total): for index in range(worker_total):
@ -1032,8 +1039,9 @@ def main(root_path, is_being_tested=False):
open_compressed = functools.partial(gzip.open, compresslevel=1) open_compressed = functools.partial(gzip.open, compresslevel=1)
dump_pickle_safe(screen, pickle_path, open=open_compressed) dump_pickle_safe(screen, pickle_path, open=open_compressed)
finally: finally:
sandbox.umount() if is_sandboxed:
os.rmdir(sandbox_temp_dir) sandbox.umount()
os.rmdir(sandbox_temp_dir)
loop.remove_reader(watch_manager_fd) loop.remove_reader(watch_manager_fd)
@ -1063,9 +1071,11 @@ def manage_cache(root_path):
if __name__ == "__main__": if __name__ == "__main__":
arguments = docopt.docopt(__doc__.replace("*", "")) arguments = docopt.docopt(__doc__.replace("*", ""))
root_path = os.path.abspath(arguments["<root_path>"]) root_path = os.path.abspath(arguments["<root_path>"])
subprocess.call(["sudo", "-p", "Vigil needs sudo to create the filesy" is_sandboxed = not arguments["--no-sandbox"]
"stem sandbox... [sudo] password for %u: ", "true"]) if is_sandboxed:
subprocess.call(["sudo", "-p", "Vigil needs sudo to create the filesy"
"stem sandbox... [sudo] password for %u: ", "true"])
with terminal.console_title("vigil: " + os.path.basename(root_path)): with terminal.console_title("vigil: " + os.path.basename(root_path)):
manage_cache(root_path) manage_cache(root_path)
with chdir(root_path): # FIX: Don't change directory if possible. with chdir(root_path): # FIX: Don't change directory if possible.
main(root_path) main(root_path, is_sandboxed)