From 9dc375039c7e7f56bdcaa799b2e983c450c840c0 Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 22 Jan 2024 01:13:28 +0100 Subject: Moving argument validator/type parser to target namespace --- squaredeal/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'squaredeal') diff --git a/squaredeal/__init__.py b/squaredeal/__init__.py index 163be72..c0ebd1a 100644 --- a/squaredeal/__init__.py +++ b/squaredeal/__init__.py @@ -1,2 +1,15 @@ class SquareDealError(Exception): pass + + +def squaredeal_board_range(arg_str): + from squaredeal.sqd import validate_board_range_str + ranges = [] + for range_str in arg_str.split(','): + range_match = re.match(r'^([0-9]+)x([0-9]+)$', range_str) + if range_match: + subrange_count = int(range_match.group(2)) + ranges += ['%d-%d' % (i*subrange_count+1, (i+1)*subrange_count) for i in range(0, int(range_match.group(1)))] + continue + ranges += [validate_board_range_str(range_str)] + return ','.join(ranges) -- cgit v1.2.3