You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
parser.add_argument('-v', '--version', action="store_true",
help=f"show version {version}")
(Many original top-level args have been commented out)
subcommands
parser.description = textwrap.dedent(
'Py4AMI: create, manipulate, use CProject \n'
'----------------------------------------\n\n'
'Py4AMI is the largest collection of functionality in the AMI system.'
'It contains executable code and libraries to manage complex documents.\n'
'A key structure is the corpus (CProject directory) which contains a list of subdirectories '
'(CTrees) which themselves contain many different document features (text, tables, images, graphics.\n'
'Py4AMI can create, fill, manipulate, transform many of the components including PDF, HTML, TXT, images, CSV.\n'
'\n'
'The subcommands:\n\n'
' DICT <options> # create/edit/search dictionaries\n'
' GUI <options> # run tkinter GUI (prototype)\n'
' HTML <options> # create/edit HTML\n'
' PDF <options> # convert PDF into HTML and images\n'
' PROJECT <options> # create and transform a corpus of documents\n'
'\n'
'After installation, run \n'
' py4ami <subcommand> <options>\n'
'\n'
'\nExamples (# foo is a comment):\n'
' py4ami # runs help\n'
' py4ami -h # runs help\n'
' py4ami PDF -h # runs PDF help\n'
' py4ami PDF --makehtml --infile foo.pdf --outdir bar/ # converts PDF to HTML\n'
' py4ami PROJECT --project foodir/ # converts all PDF in foodir to CTrees\n'
'\n'
'----------------------------------------\n\n'
)
processing args
Note that arguments can have values substituted
def parse_and_run_args(self, arglist):
"""runs cmds and makes substitutions (${...} then runs workflow
:param arglist:
"""
# no args, create help
if not arglist:
self.logger.warning("No args, running --help")
arglist = ["--help"]
parser = self.create_arg_parser()
self.args = self.make_substitutions_create_arg_tuples(arglist, parser)
self.logger.debug("ARGS before substitution: " + str(self.args))
# this may be redundant
self.substitute_args()
self.logger.debug(f"self.args {self.args}")
self.add_single_str_to_list()
self.logger.debug("ARGS after substitution: " + str(self.args))
self.set_loglevel_from_args()
self.run_arguments()
subparsers
def run_arguments(self):
""" parse and expland arguments then ru options for
Currently:
* examples
* project
* tests
There will be more here
"""
# print(f"RUN ARGUMENTS on {self} {self.args}")
# path workflow
self.wikipedia_lookup = WikidataLookup()
self.logger.debug(f"commandline args {self.args}")
subparser_type = self.args.get("command")
logging.debug(f" COMMAND: {subparser_type} {self.args}")
# if "func" in self.args:
# f_func = self.args["func"]
# print(f"FUNC {f_func}")
# aa = f_func()
# print(f"aa {aa}")
# messy - we need to use polymorphism
if not subparser_type:
abstract_args = None
elif subparser_type == "DICT":
abstract_args = AmiDictArgs()
elif subparser_type == "GUI":
abstract_args = GUIArgs()
elif subparser_type == "HTML":
abstract_args = HTMLArgs()
elif subparser_type == "PDF":
abstract_args = PDFArgs()
elif subparser_type == "PROJECT":
abstract_args = ProjectArgs()
if abstract_args:
abstract_args.parse_and_process1(self.args)
else:
self.run_core_mathods()
core methods
(Currently help and version
if self.VERSION in self.args and self.args[self.VERSION] is not None:
self.print_version()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
To add new arguments, edit
py4ami/pyamix.py
argparser
arguments
The only common arguments are
-h
and version:(Many original top-level args have been commented out)
subcommands
processing args
Note that arguments can have values substituted
subparsers
core methods
(Currently help and version
Beta Was this translation helpful? Give feedback.
All reactions