Argument parser and checker.
Homepage Repository PyPI Python
pip install pcs-argpass==0.3.1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><title>Python: class Param</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head><body bgcolor="#f0f0f8"> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><strong>Param.Param</strong> = <a name="Param.Param">class Param</a>(<a href="builtins.html#dict">builtins.dict</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Param.Param(Def: dict = {}, Args: list = None, Chk=None, Desc: str = '', AddPar: str = '', AllParams: bool = True, UserPars: dict = None, UserModes: dict = None, Translate=None)<br> <br> Main class and also the result-dictionary<br> normally imported as<br> <br> from pcs_argpass.Param import Param<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="Param.html#Param">Param</a></dd> <dd><a href="builtins.html#dict">builtins.dict</a></dd> <dd><a href="builtins.html#object">builtins.object</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="Param-GetLongOpts"><strong>GetLongOpts</strong></a>(self) -> list</dt><dd><tt>Return list of long options<br> (only? for debugging declarations)<br> <br> Returns:<br> list: List of long options</tt></dd></dl> <dl><dt><a name="Param-GetParDict"><strong>GetParDict</strong></a>(self) -> dict</dt><dd><tt>Return dict with references options -> parameter-names<br> (only? for debugging declarations)<br> <br> Returns:<br> dict: {option: name, ...}</tt></dd></dl> <dl><dt><a name="Param-GetRemainder"><strong>GetRemainder</strong></a>(self) -> list</dt><dd><tt>Return list of additionel arguments on command-line<br> <br> Returns:<br> list: List of additional arguments within runtime-arguments</tt></dd></dl> <dl><dt><a name="Param-GetShortOpts"><strong>GetShortOpts</strong></a>(self) -> list</dt><dd><tt>Return list of short options<br> (only? for debugging declarations)<br> <br> Returns:<br> str: List of short options</tt></dd></dl> <dl><dt><a name="Param-MyProgName"><strong>MyProgName</strong></a>(self) -> str</dt><dd><tt>Return the program-name<br> <br> Returns:<br> str: Name of the executeable</tt></dd></dl> <dl><dt><a name="Param-MyProgPath"><strong>MyProgPath</strong></a>(self) -> str</dt><dd><tt>Return the program-path<br> <br> Returns:<br> str: Path of the executeable</tt></dd></dl> <dl><dt><a name="Param-MyPwd"><strong>MyPwd</strong></a>(self) -> str</dt><dd><tt>Return the directory at invocation of "Process"<br> <br> Returns:<br> str: Directory at "Process"-time</tt></dd></dl> <dl><dt><a name="Param-Process"><strong>Process</strong></a>(self) -> None</dt><dd><tt>Process the runtime-arguments<br> <br> Raises:<br> self.<strong>ParamError</strong>: if an error occures within a parameter<br> RuntimeError: if an internal error occures</tt></dd></dl> <dl><dt><a name="Param-SetAddPar"><strong>SetAddPar</strong></a>(self, AddPar: str = '') -> None</dt><dd><tt>Description of additional parameters for usage-function.<br> printed in first line after "OPTIONS"<br> <br> Args:<br> AddPar (str, optional): The text or additional parameters. Defaults to "".<br> <br> Raises:<br> TypeError: if AddPar is not a string</tt></dd></dl> <dl><dt><a name="Param-SetAllParams"><strong>SetAllParams</strong></a>(self, AllParams: bool = True) -> None</dt><dd><tt>Set the flag for All Params<br> <br> Args:<br> AllParams (bool, optional): If True, all params are initialized,<br> at least with None. If False params with no default and no setting on<br> the commandline are not defined within the dictionary. Defaults to True.</tt></dd></dl> <dl><dt><a name="Param-SetArgs"><strong>SetArgs</strong></a>(self, Args: list = None) -> None</dt><dd><tt>Set the argument list to process<br> if None: use sys.argv as the arguments<br> <br> Args:<br> Args ([type], optional): Runtime Arguments. Defaults to None.<br> <br> Raises:<br> TypeError: If Args is not a list</tt></dd></dl> <dl><dt><a name="Param-SetChk"><strong>SetChk</strong></a>(self, Chk=None)</dt><dd><tt>Set the check-function. Not implementet now<br> <br> Args:<br> Chk ([type], optional): [description]. Defaults to None.<br> <br> Raises:<br> TypeError: if function is not of the proper type</tt></dd></dl> <dl><dt><a name="Param-SetDef"><strong>SetDef</strong></a>(self, Def: dict = {}) -> None</dt><dd><tt>Set the definition for processing arguments<br> <br> Args:<br> Def (dict, optional): A definition-dict. Defaults to {}.<br> <br> Raises:<br> TypeError: on error within the definition<br> <br> Describes the definition for arg-parsing.<br> Def-dict: a dictionary of dictionaries<br> { 'Name1': {.. declaration ..}, <br> ...<br> 'Name2': {.. declaration ..}, }<br> "NameN" is the index under which at runtime you get the values <br> within the resulting dictionary.<br> The individual definitions look like:<br> {'s': 'a',<br> 'l': 'longval', <br> 'o': True, <br> 'v':"LuLu",<br> 'm': 't',<br> 'd': 'Description',<br> 'L': 'Low', <br> 'U': 'Up', <br> 'r': False },<br> where:<br> m : Mode -> t=Text, <br> b=Bool, <br> p=Path, <br> f=Existing File, <br> d=Exist. Dir, <br> i=Integer, <br> F=Float, <br> C=Counter (start default as 0 and increment each time found)<br> The following are processed BEVOR all others:<br> H=Show help and exit<br> x=Import config-file as json (file must exist loke "f")<br> can be given more than once!<br> The following are processed AFTER all others:<br> X=Export config as json to stdout und exit<br> r : Required -> True or False, False is default<br> s : Short Option(s) -> string or list or tuple of strings<br> l : Long Option(s) -> string or list or tuple of strings<br> o : Ein Parameter notendig -> True oder False, False is default<br> v : Default value -> if not given: <br> "" for Text, <br> False for Bool, <br> None for Path, File and Dir,<br> 0 for Int und Counter, <br> 0. for Float<br> L : Lower Limit, value >= L if present<br> U : Upper Limit, value <= U if present<br> d : Description for helptext<br> The entries "m" and ("s" or "l") must be present, all others are optional.</tt></dd></dl> <dl><dt><a name="Param-SetDesc"><strong>SetDesc</strong></a>(self, Desc: str = '') -> None</dt><dd><tt>Set the description of the program<br> for usage-string<br> <br> Args:<br> Desc (str, optional): A descriptive string for the Program.<br> printed bevore the parameters. Defaults to "".<br> <br> Raises:<br> TypeError: if Desc is not a string.</tt></dd></dl> <dl><dt><a name="Param-SetTranslate"><strong>SetTranslate</strong></a>(self, Translate=None) -> None</dt><dd><tt>Set translation routine for error-messages<br> <br> Args:<br> Translate (callable, optional): Defaults to None.<br> example:<br> TransFunc(*,Type:str,Param:str, Path:str, FullPath:str, Msg:str, OptList:str) -> str:<br> This function is called with the folowing parameters:<br> Type, Param, Path, FullPath, Msg, OptList<br> all of them are strings. The return value is the error-msg, also<br> a string.<br> The default messages are:<br> if Type is "ImpFail"<br> "Import failed, {Path} for parameter {Param} is not a valid file"<br> if Type is "ErrMsg"<br> "Error '{Msg}' in {Path} ({FullPath}) for parameter {Param}"<br> if Type is "NoFile"<br> "The path {Path} ({FullPath}) for parameter {Param} is not a file"<br> if Type is "NoPath"<br> "The path {Path} ({FullPath}) for parameter {Param} does not exist"<br> if Type is "NoAct"<br> "No action defined for {Param}"<br> if Type is "Required"<br> "{Param} ({OptList}) required but not given"<br> for all other Type values<br> "Undefined error Type='{Type}', Param='{Param}', Path='{Path}', FullPath='{FullPath}', Msg='{Msg}', OptList='{OptList}'"<br> If this function is given it has to translate ALL messages.<br> If an error occures, the default messages are used<br> <br> Raises:<br> self.<strong>DeclarationError</strong>: if Translate not callable or None</tt></dd></dl> <dl><dt><a name="Param-SetUserKeys"><strong>SetUserKeys</strong></a>(self, UserPars: dict = None, UserModes: dict = None) -> None</dt><dd><tt>Set the key-table for the definition-dictionary<br> <br> Args:<br> UserPars (dict, optional): ignored if None. Defaults to None.<br> Dictionary of keys used within the definition-dictionary.<br> All key-value pairs are optional.<br> Only the keys from self.<strong>__WorkPars</strong> are valid.<br> The value has to be a string. This string replaces the <br> keysting for this key.<br> After all changes are made the values within self.<strong>__WorkPars</strong><br> have to be unique!<br> UserModes (dict, optional): ignored if None. Defaults to None.<br> Dictionary of modes used within the definition-dictionary.<br> All key-value pairs are optional.<br> Only the keys from self.<strong>__WorkModes</strong> are valid.<br> The value has to be a string. This string replaces the <br> keysting for this key.<br> After all changes are made the values within self.<strong>__WorkModes</strong><br> have to be unique!</tt></dd></dl> <dl><dt><a name="Param-Usage"><strong>Usage</strong></a>(self) -> str</dt><dd><tt>Return the helptext<br> <br> Returns:<br> str: The help-text</tt></dd></dl> <dl><dt><a name="Param-__init__"><strong>__init__</strong></a>(self, Def: dict = {}, Args: list = None, Chk=None, Desc: str = '', AddPar: str = '', AllParams: bool = True, UserPars: dict = None, UserModes: dict = None, Translate=None)</dt><dd><tt>The construktor<br> Args:<br> Def (dict, optional): See <a href="#Param.Param-SetDef">SetDef</a>(). Defaults to {}.<br> Args ([type], optional): See <a href="#Param.Param-SetArgs">SetArgs</a>(). Defaults to None.<br> Chk ([type], optional): See <a href="#Param.Param-SetChk">SetChk</a>(). Defaults to None.<br> Desc (str, optional): See <a href="#Param.Param-SetDesc">SetDesc</a>(). Defaults to "".<br> AddPar (str, optional): See SetAddPar. Defaults to "".<br> AllParams (Boolean, optional): See SetAllParams. Defaults to True.<br> UserPars (dict, optional): See SetUserKeys. Defaults to None.<br> UserModes (dict, optional): See SetUserKeys. Defaults to None.</tt></dd></dl> <hr> Data descriptors defined here:<br> <dl><dt><strong>__dict__</strong></dt> <dd><tt>dictionary for instance variables (if defined)</tt></dd> </dl> <dl><dt><strong>__weakref__</strong></dt> <dd><tt>list of weak references to the object (if defined)</tt></dd> </dl> <hr> Data and other attributes defined here:<br> <dl><dt><strong>DeclarationError</strong> = <class 'Param.Param.DeclarationError'><dd><tt>s exception is raised if there is an declaration error within the <br> parameters of the class.</tt></dl> <dl><dt><strong>ParamError</strong> = <class 'Param.Param.ParamError'><dd><tt>s exception is raised if there is an error within the runtime-parameters.<br> s os only within the "Process"-function.</tt></dl> <hr> Methods inherited from <a href="builtins.html#dict">builtins.dict</a>:<br> <dl><dt><a name="Param-__contains__"><strong>__contains__</strong></a>(self, key, /)</dt><dd><tt>True if the dictionary has the specified key, else False.</tt></dd></dl> <dl><dt><a name="Param-__delitem__"><strong>__delitem__</strong></a>(self, key, /)</dt><dd><tt>Delete self[key].</tt></dd></dl> <dl><dt><a name="Param-__eq__"><strong>__eq__</strong></a>(self, value, /)</dt><dd><tt>Return self==value.</tt></dd></dl> <dl><dt><a name="Param-__ge__"><strong>__ge__</strong></a>(self, value, /)</dt><dd><tt>Return self>=value.</tt></dd></dl> <dl><dt><a name="Param-__getattribute__"><strong>__getattribute__</strong></a>(self, name, /)</dt><dd><tt>Return getattr(self, name).</tt></dd></dl> <dl><dt><a name="Param-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#Param.Param-__getitem__">__getitem__</a>(y) <==> x[y]</tt></dd></dl> <dl><dt><a name="Param-__gt__"><strong>__gt__</strong></a>(self, value, /)</dt><dd><tt>Return self>value.</tt></dd></dl> <dl><dt><a name="Param-__iter__"><strong>__iter__</strong></a>(self, /)</dt><dd><tt>Implement iter(self).</tt></dd></dl> <dl><dt><a name="Param-__le__"><strong>__le__</strong></a>(self, value, /)</dt><dd><tt>Return self<=value.</tt></dd></dl> <dl><dt><a name="Param-__len__"><strong>__len__</strong></a>(self, /)</dt><dd><tt>Return len(self).</tt></dd></dl> <dl><dt><a name="Param-__lt__"><strong>__lt__</strong></a>(self, value, /)</dt><dd><tt>Return self<value.</tt></dd></dl> <dl><dt><a name="Param-__ne__"><strong>__ne__</strong></a>(self, value, /)</dt><dd><tt>Return self!=value.</tt></dd></dl> <dl><dt><a name="Param-__repr__"><strong>__repr__</strong></a>(self, /)</dt><dd><tt>Return repr(self).</tt></dd></dl> <dl><dt><a name="Param-__reversed__"><strong>__reversed__</strong></a>(self, /)</dt><dd><tt>Return a reverse iterator over the dict keys.</tt></dd></dl> <dl><dt><a name="Param-__setitem__"><strong>__setitem__</strong></a>(self, key, value, /)</dt><dd><tt>Set self[key] to value.</tt></dd></dl> <dl><dt><a name="Param-__sizeof__"><strong>__sizeof__</strong></a>(...)</dt><dd><tt>D.<a href="#Param.Param-__sizeof__">__sizeof__</a>() -> size of D in memory, in bytes</tt></dd></dl> <dl><dt><a name="Param-clear"><strong>clear</strong></a>(...)</dt><dd><tt>D.<a href="#Param.Param-clear">clear</a>() -> None. Remove all items from D.</tt></dd></dl> <dl><dt><a name="Param-copy"><strong>copy</strong></a>(...)</dt><dd><tt>D.<a href="#Param.Param-copy">copy</a>() -> a shallow copy of D</tt></dd></dl> <dl><dt><a name="Param-get"><strong>get</strong></a>(self, key, default=None, /)</dt><dd><tt>Return the value for key if key is in the dictionary, else default.</tt></dd></dl> <dl><dt><a name="Param-items"><strong>items</strong></a>(...)</dt><dd><tt>D.<a href="#Param.Param-items">items</a>() -> a set-like object providing a view on D's items</tt></dd></dl> <dl><dt><a name="Param-keys"><strong>keys</strong></a>(...)</dt><dd><tt>D.<a href="#Param.Param-keys">keys</a>() -> a set-like object providing a view on D's keys</tt></dd></dl> <dl><dt><a name="Param-pop"><strong>pop</strong></a>(...)</dt><dd><tt>D.<a href="#Param.Param-pop">pop</a>(k[,d]) -> v, remove specified key and return the corresponding value.<br> If key is not found, d is returned if given, otherwise KeyError is raised</tt></dd></dl> <dl><dt><a name="Param-popitem"><strong>popitem</strong></a>(self, /)</dt><dd><tt>Remove and return a (key, value) pair as a 2-tuple.<br> <br> Pairs are returned in LIFO (last-in, first-out) order.<br> Raises KeyError if the dict is empty.</tt></dd></dl> <dl><dt><a name="Param-setdefault"><strong>setdefault</strong></a>(self, key, default=None, /)</dt><dd><tt>Insert key with a value of default if key is not in the dictionary.<br> <br> Return the value for key if key is in the dictionary, else default.</tt></dd></dl> <dl><dt><a name="Param-update"><strong>update</strong></a>(...)</dt><dd><tt>D.<a href="#Param.Param-update">update</a>([E, ]**F) -> None. Update D from dict/iterable E and F.<br> If E is present and has a .<a href="#Param.Param-keys">keys</a>() method, then does: for k in E: D[k] = E[k]<br> If E is present and lacks a .<a href="#Param.Param-keys">keys</a>() method, then does: for k, v in E: D[k] = v<br> In either case, this is followed by: for k in F: D[k] = F[k]</tt></dd></dl> <dl><dt><a name="Param-values"><strong>values</strong></a>(...)</dt><dd><tt>D.<a href="#Param.Param-values">values</a>() -> an object providing a view on D's values</tt></dd></dl> <hr> Class methods inherited from <a href="builtins.html#dict">builtins.dict</a>:<br> <dl><dt><a name="Param-fromkeys"><strong>fromkeys</strong></a>(iterable, value=None, /)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt><dd><tt>Create a new dictionary with keys from iterable and values set to value.</tt></dd></dl> <hr> Static methods inherited from <a href="builtins.html#dict">builtins.dict</a>:<br> <dl><dt><a name="Param-__new__"><strong>__new__</strong></a>(*args, **kwargs)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt><dd><tt>Create and return a new object. See help(type) for accurate signature.</tt></dd></dl> <hr> Data and other attributes inherited from <a href="builtins.html#dict">builtins.dict</a>:<br> <dl><dt><strong>__hash__</strong> = None</dl> </td></tr></table> </body></html>