ulif.openoffice.options
– Options and Arguments¶
Components to configure processors.
-
class
ulif.openoffice.options.
Argument
(short_name, long_name=None, **kw)¶ An argument is a set of args and keywords for argparsers.
Contains of a short_name, an optional long_name and any keywords. Typical use would be:
Argument('-myproc', '--my-option', choices=[1, 2, 3])
When used with
ulif.openoffice.processor.BaseProcessor
or derived classes, please make sure that option names start with a dash (short options) and a double dash (long options). Furthermore each option (whether long or short) should begin with the processor prefix:-myproc-myopt, --myproc-myoption
for example to avoid clashes with other processors options.-
default_string
¶ Get a string representation of the default value.
-
-
exception
ulif.openoffice.options.
ArgumentParserError
¶ An error raised if argument parsing fails.
-
class
ulif.openoffice.options.
ExceptionalArgumentParser
(prog=None, usage=None, description=None, epilog=None, version=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True)¶ An argument parser that raises exceptions instead of sys.exiting.
The regular
argparse.ArgumentParser
does sys.exit() if parsing of arguments fails and prints output to stdout.This parser instead raises an
ArgumentParserError
so it is better usable in libraries.
-
class
ulif.openoffice.options.
Options
(val_dict=None, string_dict=None)¶ Options are dicts that automatically set processor options.
Different to regular dicts, Options can be constructed with a dict of values or a dict of string-values (or both; in this case real values have precedence over string-values).
string_dict values (if passed in) are set via an argparse ArgumentParser. To override any processor option’s default value, the key must be eqal to the respective processor option’s short name (without leading dash). For example you could override the –oocp-output-format option by passing in
string_dict={'oocp-out-fmt': 'pdf'}
. Please note that here the key contains dashes instead of underscores.The values of string_dict dicts are expected to be strings, for example as sent by web forms. As string_dicts are fed to an argparse.ArgumentParser instance, they allow only keys available as short name of any existing and registered processor.
val_dict values (if passed in) are set as such. I.e. ‘True’ will be set as the string ‘True’ and not as the boolean value True. To override any processor option’s default value, the key must be equal to the respective processor option long name, with dashes turned to underscores and no leading dash. For example you could override the –oocp-output-format option by passing in
val_dict={'oocp_output_format': 'pdf'}
.-
avail_procs
¶ A dict of registered processors.
Keys are the processor names (normally equal to their respective prefix). Values are the classes implementing the respective processor.
-
get_arg_parser
(parser=None)¶ Get a parser instance populated with options from processors.
The argument parser will be set up with the options (arguments) of all registered processors, looking up their args attribute.
By default we create a new
ExceptionalArgumentParser
instance. But you can also pass in your own parser instance which will then be populated as described above.
-
string_keys
¶ Get a list of acceptable keys for string_dicts.
Acceptable string keys are the short names of options defined by processors without the leading dot. For instance the OOCPProcessor provides an option
-oocp-host
. The respective string key for this option therefore would be:oocp-host
.Currently available options provided by core processors:
>>> Options().string_keys ['css-cleaner-min', 'html-cleaner-fix-head-nums', 'html-cleaner-fix-img-links', 'html-cleaner-fix-sd-fields', 'meta-procord', 'oocp-host', 'oocp-out-fmt', 'oocp-pdf-tagged', 'oocp-pdf-version', 'oocp-port']
So, you can create an Options dict with overridden defaults for instance by passing in something like
string_dict={'oocp-out-fmt': 'pdf'}
.
-
-
ulif.openoffice.options.
RE_LONG_NAME
= <_sre.SRE_Pattern object>¶ Regular expression to check long argument names like
--option
.
-
ulif.openoffice.options.
RE_SHORT_NAME
= <_sre.SRE_Pattern object>¶ Regular expression to check short argument names like
-opt
.