Support all different section syntaxes (sx, sy, ...) side by side

This commit is contained in:
Florian Festi 2019-06-15 20:04:09 +02:00
parent db706fc939
commit 01ca56fdce
1 changed files with 18 additions and 9 deletions

View File

@ -147,19 +147,28 @@ def argparseSections(s):
:param s: string to parse :param s: string to parse
""" """
m = re.match(r"(\d+(\.\d+)?)/(\d+)", s)
if m: result = []
n = int(m.group(3))
return [float(m.group(1)) / n] * n s = re.split(r"\s|:", s)
m = re.match(r"(\d+(\.\d+)?)\*(\d+)", s)
if m:
n = int(m.group(3))
return [float(m.group(1))] * n
try: try:
return [float(part) for part in s.split(":")] for part in s:
m = re.match(r"^(\d+(\.\d+)?)/(\d+)$", part)
if m:
n = int(m.group(3))
result.extend([float(m.group(1)) / n] * n)
continue
m = re.match(r"^(\d+(\.\d+)?)\*(\d+)$", part)
if m:
n = int(m.group(3))
result.extend([float(m.group(1))] * n)
continue
result.append(float(part))
except ValueError: except ValueError:
raise argparse.ArgumentTypeError("Don't understand sections string") raise argparse.ArgumentTypeError("Don't understand sections string")
return result
class ArgparseEdgeType: class ArgparseEdgeType:
"""argparse type to select from a set of edge types""" """argparse type to select from a set of edge types"""