3 """ Helper wrapper to argparse.ArgumentParser for use in athena
5 The user's options are separated from athena's command line arguments by a
6 single '-' character when athena is called.
12 from AthenaCommon.AthArgumentParser import AthArgumentParser
13 parser = AthArgumentParser()
14 parser.add_argument("-a", "--arg", action="store", help="Argument")
16 args = parser.parse_args()
24 from subprocess
import Popen, PIPE
28 from __main__
import opts
32 """ Parse user commandline arguments in a job option. """
34 def __init__(self, jo_name=None, prog=None, print_caller_help=True, **kwargs):
40 The name of the calling job option, used to format the help
41 text. Will attempt to deduce it if possible
43 The start of the usage message, usually can be deduced
45 Whether or not to print the help text from the calling program
48 All other keyword arguments are forwarded to the base class
58 for frame
in inspect.stack():
61 fname = inspect.getfile(frame[0])
64 script
for script
in opts.scripts
if fname.endswith(script)
71 jo_name =
"User job option"
72 prog =
"{0} {1} [{0} options] -".
format(os.path.basename(caller), jo_name)
75 caller_help, _ = Popen(
76 [caller,
"--help"], stdout=PIPE, stderr=PIPE
79 caller_help = caller_help.decode(
"utf-8")
80 if caller.endswith(
"athena.py"):
83 caller_help = caller_help.split(
"\n", 3)[3]
85 os.path.basename(caller), caller_help
89 super().
__init__(prog=prog, **kwargs)
93 help=
"Any remaining scripts to be run by athena after this job option. Mainly used to run the 'post' script on the grid.",
97 """ Add a new argument
99 The difference between this and the base class is that it disallows
100 adding positional arguments which are reserved by athena for job
101 options. In particular, even if user code uses only one job option
102 (which is common) pathena will add more when running on the grid
104 if not args
or len(args)
and args[0][0]
not in self.prefix_chars:
106 "Positional arguments are not allowed! Defining them could mess up grid running!"
111 """ Override the base class to use the leftover athena argumnets by
115 args = opts.user_opts
119 """ Override the base class to use the leftover athena argumnets by
123 args = opts.user_opts