Skip to content

Commit

Permalink
Adds all alternative for submission --open option
Browse files Browse the repository at this point in the history
  • Loading branch information
dbosk committed Mar 11, 2024
1 parent ad429c3 commit a7a9545
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/canvaslms/cli/submissions.nw
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ for submission in submission_list:

if args.open == "open":
<<open [[tmpdir/subdir]] for the user>>
elif args.open == "all":
<<open all files in [[tmpdir/subdir]] for the user>>

if <<condition that [[args.open]] tells us to spawn a shell>>:
<<spawn shell in [[tmpdir/subdir]] for the user>>
Expand All @@ -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.
<<add submission command options>>=
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. "
<<help strings for open shell options>>
"Default: %(const)s")
<<condition that [[args.open]] tells us to spawn a shell>>=
Expand Down Expand Up @@ -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.
<<open all files in [[tmpdir/subdir]] for the user>>=
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,
Expand Down

0 comments on commit a7a9545

Please sign in to comment.