コード例 #1
0
ファイル: argument.py プロジェクト: jebreimo/Argen
 def __init__(self, props):
     self.props = dict((k, props[k]) for k in props
                       if k not in constants.MemberProps)
     self.argument = props.get("argument", "")
     self.flags = props["flags"].split() if "flags" in props else []
     self.value = props.get("value")
     self.member = None
     self.memberProps = dict((k, props[k])
                             for k in constants.MemberProps if k in props)
     self.index = int(props["index"]) if "index" in props else None
     self.name = props["name"]
     self.memberName = props["member"]
     self.action = props.get("action")
     self.condition = props.get("condition")
     self.conditionMessage = props.get("conditionmessage")
     self.delimiter = props.get("delimiter", "")
     self.delimiterCount = utilities.parseCount(props.get("delimitercount", "0"))
     self.minDelimiters, self.maxDelimiters = self.delimiterCount
     self.count = utilities.parseCount(props["count"])
     self.minCount, self.maxCount = self.count
     self.lineNo = props["lineno"]
コード例 #2
0
ファイル: member.py プロジェクト: jebreimo/Argen
 def __init__(self, props):
     self.default = props["default"]
     self.props = props
     self.arguments = props["arguments"]
     self.name = props["name"]
     self.values = utilities.parseValues(props.get("values", ""))
     self.valueType = props["valuetype"]
     self.count = utilities.parseCount(props["count"])
     self.minCount, self.maxCount = self.count
     self.include = props.get("include")
     self.includeCpp = props.get("includecpp")
     self.action = props.get("memberaction")
     self.condition = props.get("membercondition")
     self.conditionMessage = props.get("memberconditionmessage")
     self.type = props.get("type")
     if not self.type:
         self.type = "value" if self.maxCount == 1 else "list"
     if self.type in ("list", "multivalue"):
         self.memberType = "std::vector<%s>" % self.valueType
     else:
         self.memberType = self.valueType
     self.isOption = not any(a for a in self.arguments if not a.flags)
コード例 #3
0
ファイル: properties.py プロジェクト: jebreimo/Argen
def inferArgumentProperties(props):
    if not props.get("flags", " "):
        raise Error("Flags property can't be empty.")
    if "flags" not in props and "value" in props:
        raise Error("Arguments can't have the value property.")
    if "argument" in props and "value" in props:
        raise Error("An option can't have both argument and " "value properties.")
    if not props.get("argument", props.get("flags")):
        props["argument"] = "VALUE"
    if not props.get("value", " "):
        raise Error("Value property can't be empty.")
    if "value" not in props and "argument" not in props:
        props["value"] = "true"
    if "delimitercount" in props:
        lo, hi = utilities.parseCount(props["delimitercount"])
        if lo < 0:
            raise Error("Minimum DelimiterCount can't be less than zero.")
        elif hi != -1 and hi < lo:
            raise Error("Maximum DelimiterCount can't be less than " "the minimum.")
    if "delimiter" not in props:
        s = props.get("value") or props.get("argument", "")
        if "," in s:
            props["delimiter"] = ","
    if len(props.get("delimiter", " ")) != 1:
        msg = "Delimiter must be a single non-whitespace character."
        if "," in props.get("value") or props.get("argument", ""):
            msg += ' Use "DelimiterCount: 0" to disable the comma-delimiter.'
        raise Error(msg)
    if "delimiter" not in props and props.get("delimitercount", "0") != "0":
        raise Error("DelimiterCount property where there is no delimiter.")
    if "delimiter" in props and "delimitercount" not in props:
        s = props.get("value") or props.get("argument", "")
        n = s.count(props["delimiter"])
        if n != 0:
            props["delimitercount"] = str(n)
        else:
            props["delimitercount"] = "0.."
    if "value" in props and "delimiter" in props:
        props["value"] = "|".join(props["value"].split(props["delimiter"]))
    if "type" in props:
        props["type"] = props["type"].lower()
        if props["type"] in ("help", "info", "final"):
            if "value" not in props:
                raise Error("Options of type %(type)s can't take an argument." % props)
            elif props["value"] != "true":
                raise Error('Options of type %(type)s must have value "true".' % props)
    if "default" in props and "delimiter" in props:
        count = utilities.parseCount(props["delimitercount"])
        defvals = props["default"].split(props["delimiter"], count[1])
        if len(defvals) > 1 and count[0] <= len(defvals) <= count[1]:
            raise Error("Default has too few delimited values (expects %d)." % count[0])
        elif len(defvals) == 1 and count[0] > 1:
            defvals = defvals * count[0]
        props["default"] = "|".join(defvals)
    if "count" not in props:
        props["count"] = "0..1" if "flags" in props else "1"
    else:
        c = utilities.parseCount(props["count"])
        if c[0] < 0:
            raise Error("Min-count can't be less than 0.")
        elif c[1] == 0:
            raise Error("Max-count can't be 0.")
    if props.get("valuetype") == "string":
        props["valuetype"] = "std::string"
    if "conditionmessage" in props and "condition" not in props:
        raise Error("ConditionMessage, but no Condition.")
    if "postconditionmessage" in props and "postcondition" not in props:
        raise Error("PostConditionMessage, but no PostCondition.")