Skip to main content

Argument parser and checker.

Project description

Module Param

Deals with command-line parameters


Copyright (c) 2022 Ing. Rainer Pietsch r.pietsch@pcs-at.com

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

This module handles the most often used command-line parameter types:
    boolean switch
    integer
    float
    file
    dir
    path
    text
    counter

additionally this module handles the generation and display of help-messages and licence informations. Another functionallity is the export of parameters and the import of settings.

let's view an example (my native language is German, so I use this with translation):


from pcs_argpass.Param import Param, Translation_de_DE
from pcs_argpass.GPL3 import LGPL_Preamble_DE, GPL3_2007, LGPL_Preamble, LGPL3_2007

MyParam:Optional[Param] = None              # to produce an error if not initialized!

Def_LogMqtt = {                             # This is the declaration of the command-line
                                            # options
    'Help':                                 # This is the key value for this Option
                                            # must be str and of couse unique
        {
        's': 'h',                           # the short option for this (e.g. -h)
                                            # if more characters are given all of
                                            # them are matched.
        'l': 'help',                        # the long option(s) (e.g. --help). Long
                                            # options can be abbrevated to minimal 2
                                            # characters as long as the abbrevation 
                                            # is unique within all long options,
                                            # so also --he or --hel is supported. If this
                                            # entry is a list or tuple then any of this
                                            # entries match.
        'm': 'H',                           # The modus for this option (see details
                                            # in "SetDef" function)
                                            # 'H' means this is one of the "help" 
                                            # entries. Since "Help" is a "special" case
                                            # as also "Export" os "Licence" are it is
                                            # possible to have more than one such entry
                                            # in the definition
        'd': 'Show this text and quit.'     # the help-text for this option. Can of
                                            # course be also multi-line.
        },
    'MqttBroker':
        {
        's': 'm',
        'l': 'mqttbroker',
        'm': 't',                           # this is a text-entry
        'r': True,                          # it is required
        'o': True,                          # it needs an parameter ("-m" allone makes
                                            # no sense, must be "-m 10.11.12.13" or
                                            # --mqtt=10.11.12.13)
        'v': 'localhost',                   # the default value used if this is not on the
                                            # command-line
        'd': 'Address of MQTT-Broker',
        },
    'MqttPort':
        {
        's': 'p',
        'l': 'port',
        'm': 'i',                           # This is an integer
        'l': 1024,                          # lower limit. The entered value must
                                            # be >= this value
                                            # (works also for float and str)
        'u': 32766,                         # upper limit. The entered value must
                                            # be <= this value
        'r': True,
        'o': True,
        'v': 1883,
        'd': 'Port of MQTT-Broker',
        },
    'Topic':
        {
        's': 't',
        'l': 'topic',
        'm': 't',                           # also a text entry
        'o': True,
        'M': True,                          # but allow multiple occurences.
                                            # The variable in the resulting
                                            # dictionary is a list!
        'v': [],
        'd': 'Topic to dump',
        },
    'OutFile':
        {
        's': 'f',
        'l': 'file',
        'm': 'p',                           # this is a path, not a file, because
                                            # a file (mode = f) must exist. File is
                                            # used for input-files, path for non
                                            # existing output (file or dir). It is 
                                            # only tested if the format is valid
                                            # on this operating system.
        'o': True,
        'd': 'Output path',
        }
    'License':
        {
        's': '§l',                          # here we have 2 possible short options
        'l': 'license',
        'm': '§',                           # This will show the "short" license
        'd': 'Show license and exit'
        },
    'GPL':
        {
        's': 'g',
        'l': ('gpl','GPL','Gpl'),           # here all of this entries are valid
                                            # on the command-line
        'm': 'L',                           # This will show the complete license
                                            # in this example realy a lot of text.
        'd': 'Show complete license and exit'
        },
}

Version = "1.0.0"
try:                                            # catch illegal definitions
    MyParam = Param(Def=Def_LogMqtt,
                    Desc="dump MQTT-Topics to file",
                    AllParams=True,
                    Version=Version,
                    translation=Translation_de_DE,
                    License=("""
Copyright (c) 2022 <your name>
""" + LGPL_Preamble_DE,
                        LGPL_Preamble,
                        LGPL3_2007,
                        GPL3_2007),
                    )

    if not MyParam.Process():                   # This does the "REAL" processing of
                                                # the command-line args. return True
                                                # if everything is done and the program
                                                # should exit (e.g. Help etc.)
# do your Work here. You can use the Param-class like a normal dictionary,
# so this is perfectly legal    
        if len(MyParam['Topic']) == 0:          # no topics given
            MyParam['Topic'].append('#')        # use "ALL" topics
        for l in MyParam.ParamStr().splitlines():   # this function returns the
                                                # complete parameters entered
            print(l)
# try start this program with "-h" and next time with "-§" or "-L"
# try start it with illegal parameters and look what happens.            

except Param.ParamError as RunExc:
    print(f"{RunExc }",file=sys.stderr)
    sys.exit(1)
sys.exit(0)

Classes

Param(*, Def: dict = {}, Args: Optional[list] = None, Chk=None, Desc: str = '', AddPar: str = '', AllParams: bool = True, UserPars: Optional[dict] = None, UserModes: Optional[dict] = None, ErrorOnUnknown: bool = True, HelpType: int = 0, Children: dict = {}, translation: dict = {}, Version: str = '', License: Union[str, tuple, list, dict, ForwardRef(None)] = None) : Main class and also the result-dictionary

normally imported as

from pcs_argpass.Param import Param, Translation_??_??

This class can be used to create recursive sub-parameter classes.
All children inherit the settings of their parents.
    Args:
        Def (dict, optional): See SetDef(). Defaults to {}.
        Args ([type], optional): See SetArgs(). Defaults to None.
        Chk ([type], optional): See SetChk(). Defaults to None.
        Desc (str, optional): See SetDesc(). Defaults to "".
        AddPar (str, optional): See SetAddPar. Defaults to "".
        AllParams (Boolean, optional): See SetAllParams. Defaults to True.
        UserPars (dict, optional): See SetUserKeys. Defaults to None.
        UserModes (dict, optional): See SetUserKeys. Defaults to None.
        HelpType (int, optional): Type of helptext.
            0: No Type, no standard defaults
            1: No Type, all defaults
            2: Type, no standard defaults
            3: Type and all defaults
        ErrorOnUnknown (bool, optional): If True an error is raised if
            there are undefined options on the commandline, If False: no error is raised.
            UnusedArgs is always populated with all undefined args from the commandline.
            This error is raised only on the topmost Param-object (not on children)
            Defaults to True.
            So if set to False you can test the 'UnusedArgs' property after return
            of the 'Process'-function to get the list of undefined args and process
            this situation on your own.
        Children: (dict, optional): Dictionary of Child-definition for this class.
            { 'Name': {'Def': {}, 'Desc': str, 'AddPar': str, 'Children': {} }, .... }
            Name = The name of this child. Must be unique.
                    Is translated to lower case.
                    Can not bee "global" (this is the name of the root-class)
            Def = A definition dictionary like our own "Def" parameter,
            Children (optional) = dict of type Children, describes the grand-childer,
                    this can be done to any level.
            Desc (optional) = A string that describes this class
                    (like our own "Desc"-parameter).
            AddPar (optional) = String used as additional info
                    (like our own "AddPar"-parameter).
        Version: (str, optional): Version string for help-display
        License: (str,tuple,list,dictionary, optional): List of license-texts.
            Thie texts are displayed if a '§' or 'L' -type option is applied.
            If '§': only the first entry within this list is displayed,
            if 'L': all entries separated by a newline ('\n') are displayed.
            To help there is a separate module "GPL3" which includes the folowing entries:
                "GPL_Preamble" the suggested preamble (after the copyright notice)
                "GPL_Preamble_DE" the same preamble in German language.
                "LGPL_Preamble" the suggested preamble for the LGPL
                    (use after the copyright notice)
                "LGPL_Preamble_DE" the same preamble in German language.
                "LGPL3_2007" the additional terms of the Lesser GPL Version 3 from
                    June, 29th 2007, you shold append also the following
                    (GPL3_2007) if you use this license.
                "GPL3_2007" the complete text of the GPL Version 3 from June, 29th 2007
            you can use this by
                from pcs_argpass.GPL3 import GPL_Preamble, LGPL3_2007, GPL3_2007
            and in the constructor of Param par example with:
                MyParam = Param (
                    ....
                License=('''
Copyright (c) <date> <your name>
''' + GPL_Preamble_DE,
                        GPL_Preamble,
                        LGPL3_2007,
                        GPL3_2007),
                    ....
                    )
            but, of course you can use every other license text you want, as long as this
            license is compatible with the license of this module, whitch IS LGPL3.
        translation: (dict, optional): A dictionary used for translating error messages.
            There are 2 'Hidden' function to help debug the translations:
                _PrintInitTranslation() and
                _PrintActualTranslation()
            This function do exactly what they say: print the values out to stdout. You can
            use them to get the exact values used. The following default may not be accurate
            at all - do not rely on this info, print the dict yourselve.

            defaults to:
                {
                'PrefixError':
                    "Error in prefixed parameter {OptionName}",
                'JsonError':
                    "Import failed '{wMsg}' in {OptionPath} ({FullPath}) for parameter {OptionName}",
                'PathNoFile':
                    "The path '{OptionPath}' ({FullPath}) for parameter {OptionName} is not a file",
                'PathNoDir':
                    "The path '{OptionPath}' ({FullPath}) for parameter {OptionName} is not a directory",
                'PathNoPath':
                    "The path '{OptionPath}' ({FullPath}) for parameter {OptionName} is not valid on this filesystem",
                'LessLow':
                    "Value '{OptValue}' for parameter {ParKey} is less than lower limit ({LowLimit})",
                'HigherUp':
                    "Value '{OptValue}' for parameter {ParKey} is bigger than upper limit ({UppLimit})",
                'NoInt':
                    "Value '{OptValue}' for parameter {ParKey} is not a valid integer",
                'NoFloat':
                    "Value '{OptValue}' for parameter {ParKey} is not a valid floating point number",
                'NoBool':
                    "Value '{OptValue}' for parameter {ParKey} is not valid boolean (YyTtJj1NnFf0)",
                'OptionNotDefined':
                    "No action defined for {OptionName}",
                'OptionRequired':
                    "{DefArgName} ({ParList}) required but not given",
                'TypePath':
                    "path",
                'TypeInteger':
                    "integer",
                'TypeBool':
                    "bool",
                'TypeFloat':
                    "float",
                'TypeFile':
                    "file",
                'TypeDir':
                    "directory",
                'TypeCount':
                    "counter",
                'TypeHelp':
                    "help",
                'TypeImport':
                    "import",
                'TypeExport':
                    "export",
                'TypeGlobImport':
                    "global import",
                'TypeGlobExport':
                    "global export",
                'TypeStr':
                    "string",
                'HelpDefault':
                    "Default",
                'HelpValue':
                    "value",
                'HelpUsage':
                    "Usage:",
                'HelpVersion':
                    "Version:",
                'HelpOptions':
                    "Options:",
                'HelpOptionInline':
                    "[OPTIONS ...]",
                'OptionRequiresArgumentLong':
                    "option --{opt} requires argument",
                'OptionNeedNoArgs':
                    "option --{opt} must not have an argument",
                'OptionNotRecognizedLong':
                    "option --{opt} not recognized",
                'ParNoUniquePrefix':
                    "option --{opt} not a unique prefix",
                'OptionRequiresArgumentShort':
                    "option -{opt} requires argument",
                'OptionNotRecognizedShort':
                    "option -{opt} not recognized",
                'UndefinedOptionSingle':
                    "option {OptStr} not recognized",
                'UndefinedOptionMultiple':
                    "options {OptStr} not recognized",
                }

NOTE:   All long options can be abbreviated to at least 2 characters or to the
        length making them unique within the defined long options.
        Example:
            you define 'automatic', 'autonom' and 'testopt'
            at the commandline this can be abbreviated to
                PROG --autom --auton --te
            but not to
                PROG --au
            because this is not unique within the optionlist.

NOTE:   If children are used, the prefix-name is always optional, but if given, the option
        is ONLY recognized for this child. if there are the same long options for more
        then one child and NO prefix is given, this option is recognized by ALL children
        having this long option within their definition.
        Example:
            you define 'auto' within the root as 'MyOpt'
            you define 'auto' within the child 'alpha' as 'DoAuto'

            the commandline shald be
                PROG --auto=yes
            then BOTH options are set to 'yes' e.g. MyParam['MyOpt'] == 'yes' AND MyParam['DoAuto'] == 'yes'
            with the commandline
                PROG --alpha.auto=yes
            only MyParam['DoAuto'] == 'yes' and MyParam['MyOpt'] is either the default or not set depending on
            the definition of this option
            with the commandline
                PROG --alpha.auto=yes --global.auto=no
            MyParam['MyOpt'] == 'no' AND MyParam['DoAuto'] == 'yes'
            REMEMBER: 'global' is ALWAYS the name of the root Param-object!
        please inform yout users about this possibility if you use child-definitions!

### Class variables

`DeclarationError`
:   this exception is raised if there is an declaration error within the
    parameters of the class.
    NOTE:   This error messages are NEVER translated since they are not user
            initiated errors.

`GetoptError`
:   Eigene Fehlerklasse für OptionError

`ParamError`
:   This exception is raised if there is an error within the runtime-parameters.
    This is only raised within the "Process"-function.
    NOTE:   This errors are translated with the 'translation' dictionary. There
            is the initial state of this dict using 'en_US' texts.
            This module also provide a 'Translation_de_DE' entry giving a german
            translation of the error-messages.
            If you can provide translations to other languages send me this
            declarations to <r.pietsch@pcs-at.com> and I will add them to this
            module.

### Instance variables

`Child: dict`
:   return all the children of this instance
    
    Returns:
        dict[str, Param]: Dictionary of the children of this instance

`Definition: dict`
:   returns s copy of the definition
    
    Returns:
        dict: a definition dictionary

`FreeShortCommandLineParameter: str`
:   Helper for programmers. can be used before "Process".
    Shound not be used in production environment
    
    Returns:
        str: A formatted, sorted list of all unused (free to use) short options
            broken to 68 characters a line.

`FullPrefix: str`
:   Returns the full qualified prefix of this instance
    e.g.: global.alpha.gamma
    if alpha is a child of global and gamma (this instance) is a child of alpha

`GetExportDict`
:   Return the dictionary for exporting all parameters
    
    Returns:
        dict: The complete parameter dictionary

`LongOptsList: list`
:   Return copied list of long options
    
    Returns:
        list: List of long options

`OverviewCommandLineParameter`
:   Helper for programmers. can be used before "Process".
    Shound not be used in production environment
    
    Returns:
        str: A formatted string giving all information about
            command-line parameters, broken to 68 characters a line.

`ParDict: dict`
:   Return copied dict with references options -> parameter-names
    
    Returns:
        dict: {option: name, ...}

`Parents: str`
:   Returns the full qualified parents of this instance
    e.g.: global.alpha
    if alpha is a child of global and gamma (this instance) is a child of alpha

`PartPrefix: str`
:   Returns the full qualified prefix without global of this instance
    e.g.: alpha.gamma
    if alpha is a child of global and gamma (this instance) is a child of alpha

`Prefix: str`
:   Return the prefix of this class
    
    Returns:
        str: the prefix value

`ShortOptsList: list`
:   Return copied list of short options

`TestCommandLineParameter: str`
:   Helper for programmers. can be used before "Process".
    Helps to find problems with the command-line interface.
    Prevent missunderstandig the interface by the user.
    Shound not be used in production environment
    
    Returns:
        str: A formatted sting giving all informations about errors
            or possible problems within the definition(s).

`UnusedArgs: list`
:   Return list of not defined args from the commandline
    This list is for the current Param-object and all of the children
    of this Param-object.
    So under normal conditions it makes only sense on the root of
    all Param-objects.
    
    Example:
        root defines '-z'
        child defines '-a'
        commandline is "-a -z --test"
    
        UnusedArgs of child is ['-z','--test']
        UnusedArgs of root = ['--test']     which is the correct list of undefined args.
    
    Returns:
        list: list of undefined args (str)

`UsedLongCommandLineParameter: str`
:   Helper for programmers. can be used before "Process".
    Shound not be used in production environment
    
    Returns:
        str: A formatted, sorted list of all used long options
            broken to 68 characters a line.

`UsedShortCommandLineParameter: str`
:   Helper for programmers. can be used before "Process".
    Shound not be used in production environment
    
    Returns:
        str: A formatted, sorted list of all used short options
            broken to 68 characters a line.

### Methods

`AddChild(self, Prefix: str, Def: dict = {}, Description: str = '', Children: dict = {}, Version: str = '', License: list = [''], AddPar: str = '') ‑> None`
:   Add a child to a instance
    
    Args:
        Prefix (str): The unique name of this child. Will be translated to lower case.
                can not be 'global' (this is the name of the topmost parent)
        Def (dict, optional): Definition for this instance (look at the constructor). Defaults to {}.
        Description (str, optional): Description of this instance. Defaults to ''.
        Children (dict, optional): Dictionary of children to the new instance (look at constructor). Defaults to {}.
        AddPar (str, optional): Additional parameter string of this instance. Defaults to ''.
    
    Raises:
        self.DeclarationError: If a parameter is invalid

`GetCmdPar(self, Entry: str, dotted: bool = False, parents: bool = False) ‑> str`
:   Return the commandline-options for one entry
    
    Args:
        Entry (str): The entry we are looking for
        dotted (bool, optional): show prefix for long params.
        parents (bool, optional): show also options from parents. Set also "dotted" to True
    
    Returns:
        str: the command-line options for this entry. E.g. "-h, --help"

`GetRemainder(self) ‑> list`
:   Return list of additionel arguments on command-line
    
    Returns:
        list: List of additional arguments within runtime-arguments

`IsInherited(self, key: str) ‑> bool`
:   Check if key is from parent
    
    Args:
        key (str): Key to search for
    
    Returns:
        bool: True if key is inherited from parent

`IsOwnKey(self, key: str) ‑> bool`
:   Check if the key is from the own optionset
    
    Args:
        key (str): Key to search for
    
    Returns:
        bool: True if key is in the own optionset

`MyProgName(self) ‑> str`
:   Return the program-name
    
    Returns:
        str: Name of the executeable

`MyProgPath(self) ‑> str`
:   Return the program-path
    
    Returns:
        str: Path of the executeable

`MyPwd(self) ‑> str`
:   Return the directory at invocation of "Process"
    
    Returns:
        str: Directory at "Process"-time

`ParamStr(self, indent: int = 4, header: bool = True, allvalues: bool = True, dotted: bool = False, cmdpar: bool = True, parentopts: bool = False, recursive: bool = True) ‑> str`
:   Returns a string with formatted output of the
            processed parameters.
    
            Args:
                indent (int, optional): Number of leading spaces for children. Defaults to 4.
                        this value is multiplied with the generation. So grandchildren have
                        two times this number of leading spaces and children only one time
                        this number of spaces.
    
                header (bool, optional): If True a header with the name of the object are added. Defaults to True.
    
                allvalues (bool, optional): Outputs all avallable options for this child,
                        included the inherited options. Defaults to True.
    
                dotted (bool, optional): If True the names of the parameters are prefixed with the names
                        of their parents. Defaults to False.
    
                cmdpar (bool, optional): If True the commandline-options ere included in the output. Defaults to True.
    
                parentopts (bool, optional): If True and cmdpar is also True the commandline-options of the parents
                        are anso included in the output. Defaults to False.
    
                recursive (bool, optional): If True all descendants are include in the output,
                        else only the own parameters are included. Defaults to True.
    
            Returns:
                str: The formated string of the processed parameters
    
    
    Examples:
    ########################################################################################
    
            Assuming:
                the topmost level includes
                    "NoDaemon", "Quiet", "StdErr", and "Verbose"
                child "alpha" includes
                    "Count", "Text" and "Verbose"
                grandchild "alpha -> gamma" includes
                    "Xy"
                child "beta" includes
                    "Verbose"
    
            The largest format is like:
    ------------------------------------------------------------
    global
    ------------------------------------------------------------
    global                     -> NoDaemon (-d, --[global.]nodaemon)              : False
    global                     -> Quiet    (-q, --[global.]quiet)                 : False
    global                     -> StdErr   (-s, --[global.]console)               : False
    global                     -> Verbose  (-v, --[global.]verbose)               : 2
        ------------------------------------------------------------
        global.alpha
        ------------------------------------------------------------
        global.alpha           -> Count    (-c, --[alpha.]count, --[alpha.]Count) : 7
        global.alpha           -> NoDaemon (-d, --[global.]nodaemon)              : False
        global.alpha           -> Quiet    (-q, --[global.]quiet)                 : False
        global.alpha           -> StdErr   (-s, --[global.]console)               : False
        global.alpha           -> Text     (-t, --[alpha.]text, --[alpha.]Text)   : ''
        global.alpha           -> Verbose  (-v, --[alpha.]verbose)                : 2
            ------------------------------------------------------------
            global.alpha.gamma
            ------------------------------------------------------------
            global.alpha.gamma -> Count    (-c, --[alpha.]count, --[alpha.]Count) : 7
            global.alpha.gamma -> NoDaemon (-d, --[global.]nodaemon)              : False
            global.alpha.gamma -> Quiet    (-q, --[global.]quiet)                 : False
            global.alpha.gamma -> StdErr   (-s, --[global.]console)               : False
            global.alpha.gamma -> Text     (-t, --[alpha.]text, --[alpha.]Text)   : ''
            global.alpha.gamma -> Verbose  (-v, --[alpha.]verbose)                : 2
            global.alpha.gamma -> Xy       (-b, --[gamma.]bbbb)                   : False
        ------------------------------------------------------------
        global.beta
        ------------------------------------------------------------
        global.beta            -> NoDaemon (-d, --[global.]nodaemon)              : False
        global.beta            -> Quiet    (-q, --[global.]quiet)                 : False
        global.beta            -> StdErr   (-s, --[global.]console)               : False
        global.beta            -> Verbose  (-v, --[beta.]verbose)                 : 5
    
            The shortest format is like (recursive = True):
    
    global -> NoDaemon  : False
    global -> Quiet     : False
    global -> StdErr    : False
    global -> Verbose   : 2
    alpha  -> Count     : 7
    alpha  -> Text      : ''
    alpha  -> Verbose   : 2
    gamma  -> Xy        : False
    beta   -> Verbose   : 5
    
            The shortest format is like (recursive = False):
    
    global -> NoDaemon  : False
    global -> Quiet     : False
    global -> StdErr    : False
    global -> Verbose   : 2
    
    ########################################################################################

`Process(self) ‑> bool`
:   Process the runtime-arguments
    
    Raises:
        self.ParamError: if an error occures within a parameter
        RuntimeError: if an internal error occures

`SetAddPar(self, AddPar: str = '') ‑> None`
:   Description of additional parameters for usage-function.
    printed in first line after "OPTIONS"
    
    Args:
        AddPar (str, optional): The text or additional parameters. Defaults to "".
    
    Raises:
        TypeError: if AddPar is not a string

`SetAllParams(self, AllParams: bool = True) ‑> None`
:   Set the flag for All Params
    
    Args:
        AllParams (bool, optional): If True, all params are initialized,
        at least with None. If False params with no default and no setting on
        the commandline are not defined within the dictionary. Defaults to True.

`SetArgs(self, Args: Optional[list] = None) ‑> None`
:   Set the argument list to process
    if None: use sys.argv as the arguments
    
    Args:
        Args ([type], optional): Runtime Arguments. Defaults to None.
    
    Raises:
        TypeError: If Args is not a list

`SetChk(self, Chk=None)`
:   Set the check-function. Not implementet now
    
    Args:
        Chk ([type], optional): [description]. Defaults to None.
    
    Raises:
        TypeError: if function is not of the proper type

`SetDef(self, Def: dict = {}) ‑> None`
:   Set the definition for processing arguments
    
            Args:
                Def (dict, optional): A definition-dict. Defaults to {}.
    
            Raises:
                TypeError: on error within the definition
    
    Describes the definition for arg-parsing.
    Def-dict: a dictionary of dictionaries
            { 'Name1': {.. declaration ..},
            ...
            'Name2': {.. declaration ..}, }
            "NameN" is the index under which at runtime you get the values
                    within the resulting dictionary.
            The individual definitions look like:
                    {'s': 'a',
                    'l': 'longval',
                    'o': True,
                    'v': "LuLu",
                    'm': 't',
                    'd': 'Description',
                    'L': 'Low',
                    'U': 'Up',
                    'r': False },
            where:
                    m : Mode ->
                            't' = Text,
                            'b' = Bool,
                            'p' = Path,
                            'f' = Existing File,
                            'd' = Exist. Dir,
                            'i' = Integer,
                            'F' = Float,
                            'C' = Counter (start default as 0 and increment each time found)
                                    Special case: short option takes no argument,
                                    long option NEEDS argument
                                    short option increments the value,
                                    long option adds the argument to the value
                    The following are processed BEVOR all others:
                            'H' = Show help and exit
                            'x' = Import config-file as json (file must exist like "f")
                                      can be given more than once!
                            '<' = MultiImport config-file as json
                    The following are processed AFTER all others:
                            'X' = Export config as json to stdout und exit
                            '>' = MultiExport config as json to stdout und exit
                    r : Required -> True or False, False is default
                    s : Short Option(s) -> string or list or tuple of strings
                    l : Long Option(s) -> string or list or tuple of strings
                    o : Ein Parameter notendig -> True oder False, False is default
                    v : Default value -> if not given:
                          "" for Text,
                          False for Bool,
                          None for Path, File and Dir,
                          0 for Int und Counter,
                          0. for Float
                    L : Lower Limit, value >= L if present
                    U : Upper Limit, value <= U if present
                    d : Description for helptext
            The entries "m" and ("s" or "l") must be present, all others are optional.

`SetDesc(self, Desc: str = '') ‑> None`
:   Set the description of the program
    for usage-string
    
    Args:
        Desc (str, optional): A descriptive string for the Program.
        printed bevore the parameters. Defaults to "".
    
    Raises:
        TypeError: if Desc is not a string.

`SetTranslation(self, translation: dict, IsChild: bool = False) ‑> None`
:   Setzt eine neue Translationtable
    
    Args:
        translation (dict): Dictionary mit übersetzten Fehlermeldungen
        IsChild (bool, optional): True wenn wir eine untergeordnete Instanz sind. Defaults to False.

`SetUserKeys(self, UserPars: Optional[dict] = None, UserModes: Optional[dict] = None) ‑> None`
:   Set the key-table for the definition-dictionary
    
    Args:
        UserPars (dict, optional): ignored if None. Defaults to None.
        Dictionary of keys used within the definition-dictionary.
        All key-value pairs are optional.
        Only the keys from self.__WorkPars are valid.
        The value has to be a string. This string replaces the
        keysting for this key.
        After all changes are made the values within self.__WorkPars
        have to be unique!
        UserModes (dict, optional): ignored if None. Defaults to None.
        Dictionary of modes used within the definition-dictionary.
        All key-value pairs are optional.
        Only the keys from self.__WorkModes are valid.
        The value has to be a string. This string replaces the
        keysting for this key.
        After all changes are made the values within self.__WorkModes
        have to be unique!

`Usage(self) ‑> str`
:   Return the helptext
    
    Returns:
        str: The help-text

`items(self) ‑> list`
:   Return the items list including the items of all parents
    
    Returns:
        list: the items

`keys(self) ‑> list`
:   Return the keys list including the keys of all parentsof
    
    Returns:
        list: the keys list

`values(self) ‑> list`
:   Return the values list including the values of all parents
    
    Returns:
        list: the values

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pcs_argpass-1.11.160.220820150730.tar.gz (82.4 kB view details)

Uploaded Source

Built Distribution

pcs_argpass-1.11.160.220820150730-py3-none-any.whl (105.3 kB view details)

Uploaded Python 3

File details

Details for the file pcs_argpass-1.11.160.220820150730.tar.gz.

File metadata

File hashes

Hashes for pcs_argpass-1.11.160.220820150730.tar.gz
Algorithm Hash digest
SHA256 8a305a84a823f65d11e133e625e4b1c96d859c3a875633cdad62084478362d7b
MD5 8cd7c2acb100d62cf5ee02c4d30d766e
BLAKE2b-256 aef46502079960f611fe3c93cf30a1506cdde3e0cec225a26720885414a4783a

See more details on using hashes here.

File details

Details for the file pcs_argpass-1.11.160.220820150730-py3-none-any.whl.

File metadata

File hashes

Hashes for pcs_argpass-1.11.160.220820150730-py3-none-any.whl
Algorithm Hash digest
SHA256 83cce754037f24dde37a595fd12b37229f862742c7700a60257e8e979b57ef7f
MD5 c3d946cb922c7e2e0d5364bf7df91fed
BLAKE2b-256 6d5165c3e43661fc8ee042fda7d122122bcf271e9e5cf05e3952e2c581b4bed4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page