From a7a9545d6764b193d7479180dcb784e4237d17a6 Mon Sep 17 00:00:00 2001 From: Daniel Bosk Date: Mon, 11 Mar 2024 08:50:58 +0100 Subject: [PATCH] Adds all alternative for submission --open option --- src/canvaslms/cli/submissions.nw | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/canvaslms/cli/submissions.nw b/src/canvaslms/cli/submissions.nw index 717e441..615572c 100644 --- a/src/canvaslms/cli/submissions.nw +++ b/src/canvaslms/cli/submissions.nw @@ -201,6 +201,8 @@ for submission in submission_list: if args.open == "open": <> + elif args.open == "all": + <> if <>: <> @@ -225,13 +227,16 @@ submission_parser.add_argument("-o", "--output-dir", "If specified, do not print to stdout.") @ -We also have the open option, that has a choice of two alternatives. +We also have the open option, that has a choice of a few alternatives. <>= submission_parser.add_argument("--open", required=False, - nargs="?", default=None, const="open", choices=["open"]+choices_for_shells, + nargs="?", default=None, const="open", + choices=["open", "all"]+choices_for_shells, help="Open the directory containing the files using " "the default file manager (`open`). " "With `open`, the pager will be used to display the output as usual. " + "With `all`, all files (not the directory containing them) will be " + "opened in the default application for the file type. " <> "Default: %(const)s") <>= @@ -319,6 +324,13 @@ open files while reading the stdout output using a pager. subprocess.run(["open", tmpdir/subdir]) @ +If we instead want to open all files contained in the directory, we can need to +iterate all the files and open them one by one. +<>= +for file in (tmpdir/subdir).iterdir(): + subprocess.run(["open", file]) +@ + We can also spawn a shell in the directory so that the user can work with the files, for instance run the Python code in the case of a Python lab submission. Now, we could spawn a sub-shell of the user's shell,