aboutsummaryrefslogtreecommitdiff
path: root/b4/__init__.py
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-07 11:52:20 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-07 11:52:20 -0400
commit56b965b2e30d483145a737062151616a3628960c (patch)
tree7be920499024f71bb2bed31a0afe19ae43872077 /b4/__init__.py
parentafd622604f9ec4360d50b6e32b11fc66e44d62a1 (diff)
downloadb4-56b965b2e30d483145a737062151616a3628960c.tar.gz
Switch ty -s and -d to allow friendly ranges
Instead of insisting that people put in specific numbers, allow them to specify ranges, such as: b4 ty -s 1-3,5,7- Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Diffstat (limited to 'b4/__init__.py')
-rw-r--r--b4/__init__.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index a6b683e..a7fb436 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -1904,3 +1904,21 @@ def make_quote(body, maxlines=5):
quotelines.append('> %s' % line.rstrip())
qcount += 1
return '\n'.join(quotelines)
+
+
+def parse_int_range(intrange, upper=None):
+ # Remove all whitespace
+ intrange = re.sub(r'\s', '', intrange)
+ for n in intrange.split(','):
+ if n.isdigit():
+ yield int(n)
+ elif n.find('<') == 0 and len(n) > 1 and n[1:].isdigit():
+ yield from range(0, int(n[1:]))
+ elif n.find('-') > 0:
+ nr = n.split('-')
+ if nr[0].isdigit() and nr[1].isdigit():
+ yield from range(int(nr[0]), int(nr[1])+1)
+ elif not len(nr[1]) and nr[0].isdigit() and upper:
+ yield from range(int(nr[0]), upper+1)
+ else:
+ logger.critical('Unknown range value specified: %s', n)