def parse_limit_expression()

in pbspro/src/pbspro/parser.py [0:0]


    def parse_limit_expression(self, expr: str) -> "PBSProLimit":
        # avoid circular import
        from pbspro.pbsqueue import PBSProLimit

        ret = PBSProLimit()
        expr = expr.replace('"', "")

        toks = [t.strip() for t in expr.split(",")]
        for tok in toks:
            if not tok:
                continue

            if tok.isnumeric():
                # easy case max_run = 20 is equivalent to
                # max_run = [o:PBS_ALL=20]
                ret.overall["PBS_ALL"] = int(tok)
                continue

            tok = tok.replace("[", "").replace("]", "")
            key, value = tok.split("=", 1)
            key, value = key.strip(), value.strip()
            parsed_value = int(value)

            scope, name = key.split(":", 1)
            if scope == "o":
                ret.overall[name] = parsed_value
            elif scope == "u":
                ret.user[name] = parsed_value
            elif scope == "g":
                ret.group[name] = parsed_value
            elif scope == "p":
                ret.project[name] = parsed_value
            else:
                raise RuntimeError(
                    "Unknown scope '{}' while parsing limit '{}'".format(scope, tok)
                )

        return ret