-
Notifications
You must be signed in to change notification settings - Fork 7
Description
This is a proposal originally brought up by @retzkek in #472, that we decided in the jobsub project meeting to relegate to a possible future issue. The proposal is as follows (quoting @retzkek):
Also I'd like us to consider (not necessarily implement here) a refactor of jobsub to the common subcommand pattern, e.g. jobsub_submit ... becomes jobsub submit ... (with a compatibility alias), which would make sure that the list of (sub-)commands and their descriptions don't stray from what's actually implemented, and would help ensure uniformity between them. Maybe we include the wrapped condor commands too, e.g. jobsub condor_q ....
@marcmengel sketched out how such a proposal might be implemented in #472 as well:
"So, looking at the master "jobsub" command idea again... If we took the existing
main() functions in the the 4 main jobsub scripts
jobsub_cmd
jobsub_fetchlog
jobsub_history
jobsub_submit
(the rest are all symlinks...)
and split them into 2 parts -- 1 that adds arguments to the parser, and 1 that
implements the script logic, we could then have standalone scripts which
would be pretty much:
if __name__ == '__main__':
parser = this_command_get_parser(parser=argparser.ArgumentParser())
parser.set_default('command',os.path.basename(sys.argv[0]))
arglist, passthru = parser.parse_known_args()
this_command_main(arglist, passthru)
But we could build, in "jobsub", a big sub-command parser by
calling the this_command_get_parser() for whichever commands,
and passing the subparser into it like:
if __name__ == '__main__':
top_parser = argparser.ArgumentParser()
for sc in ('submit', 'submit_dag')
sub_parser = josub_submit_get_parser( parser=top_parser.subcommand(sc))
sub_parser.set_default('command', f"jobsub_{sc}")
sub_parser.set_default('func', jobsub_submit_main)
for sc in ('q','hold','release','rm','wait'):
sub_parser = jobsub_cmd_get_parser( parser=to_parser.subcommand(sc))
sub_parser.set_default('command', f"jobsub_{sc}")
sub_parser.set_default('func', josub_cmd_main)
sub_parser = jobsub_fethclog_get_parser( parser = top_parser.subcommand('fetchlog")`
sub_parser.setdefault('command', 'jobsub_fetchlog')
sub_paser.set_default('func', jobsub_fetchlog_main)
...
Then we just parse the top level, pull out the "func" and call it with the argument
parser and any unparsed args..."
We will mark this as a "future" enhancement, since it's not clear the benefit this will give us, for the amount of work required. But we wanted to capture the discussion in case that calculation changes in the future.