Parse –id data and append results to namespace.
<argument>.idList
- Parameters
-
[in] | parser | argument parser (instance of ArgumentParser) |
[in,out] | namespace | parsed command (an instance of argparse.Namespace); updated values:
- <idName>.idList, where <idName> is the name of the ID argument, for instance "id" for ID argument –id
|
[in] | values | a list of data IDs; see data format below |
[in] | option_string | option value specified by the user (a str) |
The data format is: key1=value1_1[^value1_2[^value1_3...] key2=value2_1[^value2_2[^value2_3...]...
The values (e.g. value1_1) may either be a string, or of the form "int..int" (e.g. "1..3") which is interpreted as "1^2^3" (inclusive, unlike a python range). So "0^2..4^7..9" is equivalent to "0^2^3^4^7^8^9". You may also specify a stride: "1..5:2" is "1^3^5"
The cross product is computed for keys with multiple values. For example: –id visit 1^2 ccd 1,1^2,2 results in the following data ID dicts being appended to namespace.<argument>.idList: {"visit":1, "ccd":"1,1"} {"visit":2, "ccd":"1,1"} {"visit":1, "ccd":"2,2"} {"visit":2, "ccd":"2,2"}
Definition at line 662 of file argumentParser.py.
663 def __call__(self, parser, namespace, values, option_string):
664 """!Parse --id data and append results to namespace.<argument>.idList
666 @param[in] parser argument parser (instance of ArgumentParser)
667 @param[in,out] namespace parsed command (an instance of argparse.Namespace);
669 - <idName>.idList, where <idName> is the name of the ID argument,
670 for instance "id" for ID argument --id
671 @param[in] values a list of data IDs; see data format below
672 @param[in] option_string option value specified by the user (a str)
675 key1=value1_1[^value1_2[^value1_3...] key2=value2_1[^value2_2[^value2_3...]...
677 The values (e.g. value1_1) may either be a string, or of the form "int..int" (e.g. "1..3")
678 which is interpreted as "1^2^3" (inclusive, unlike a python range). So "0^2..4^7..9" is
679 equivalent to "0^2^3^4^7^8^9". You may also specify a stride: "1..5:2" is "1^3^5"
681 The cross product is computed for keys with multiple values. For example:
682 --id visit 1^2 ccd 1,1^2,2
683 results in the following data ID dicts being appended to namespace.<argument>.idList:
684 {"visit":1, "ccd":"1,1"}
685 {"visit":2, "ccd":"1,1"}
686 {"visit":1, "ccd":"2,2"}
687 {"visit":2, "ccd":"2,2"}
689 if namespace.config
is None:
691 idDict = collections.OrderedDict()
692 for nameValue
in values:
693 name, sep, valueStr = nameValue.partition(
"=")
695 parser.error(
"%s appears multiple times in one ID argument: %s" % (name, option_string))
697 for v
in valueStr.split(
"^"):
698 mat = re.search(
r"^(\d+)\.\.(\d+)(?::(\d+))?$", v)
700 v1 = int(mat.group(1))
701 v2 = int(mat.group(2))
702 v3 = mat.group(3); v3 = int(v3)
if v3
else 1
703 for v
in range(v1, v2 + 1, v3):
704 idDict[name].append(str(v))
706 idDict[name].append(v)
708 keyList = idDict.keys()
709 iterList = [idDict[key]
for key
in keyList]
710 idDictList = [collections.OrderedDict(zip(keyList, valList))
711 for valList
in itertools.product(*iterList)]
713 argName = option_string.lstrip(
"-")
714 ident = getattr(namespace, argName)
715 ident.idList += idDictList
def __call__
Parse –id data and append results to namespace.