##// END OF EJS Templates
fileset: parse argument of size() by predicate function...
Yuya Nishihara -
r38709:1500cbe2 default
parent child Browse files
Show More
@@ -384,11 +384,9 b' def _sizetomax(s):'
384 except ValueError:
384 except ValueError:
385 raise error.ParseError(_("couldn't parse size: %s") % s)
385 raise error.ParseError(_("couldn't parse size: %s") % s)
386
386
387 def sizematcher(x):
387 def sizematcher(expr):
388 """Return a function(size) -> bool from the ``size()`` expression"""
388 """Return a function(size) -> bool from the ``size()`` expression"""
389
389 expr = expr.strip()
390 # i18n: "size" is a keyword
391 expr = getstring(x, _("size requires an expression")).strip()
392 if '-' in expr: # do we have a range?
390 if '-' in expr: # do we have a range?
393 a, b = expr.split('-', 1)
391 a, b = expr.split('-', 1)
394 a = util.sizetoint(a)
392 a = util.sizetoint(a)
@@ -420,7 +418,9 b' def size(mctx, x):'
420 - size('>= .5MB') - files at least 524288 bytes
418 - size('>= .5MB') - files at least 524288 bytes
421 - size('4k - 1MB') - files from 4096 bytes to 1048576 bytes
419 - size('4k - 1MB') - files from 4096 bytes to 1048576 bytes
422 """
420 """
423 m = sizematcher(x)
421 # i18n: "size" is a keyword
422 expr = getstring(x, _("size requires an expression"))
423 m = sizematcher(expr)
424 return [f for f in mctx.existing() if m(mctx.ctx[f].size())]
424 return [f for f in mctx.existing() if m(mctx.ctx[f].size())]
425
425
426 @predicate('encoding(name)', callexisting=True)
426 @predicate('encoding(name)', callexisting=True)
@@ -14,6 +14,11 b' from . import ('
14 pycompat,
14 pycompat,
15 )
15 )
16
16
17 def _sizep(x):
18 # i18n: "size" is a keyword
19 expr = fileset.getstring(x, _("size requires an expression"))
20 return fileset.sizematcher(expr)
21
17 def _compile(tree):
22 def _compile(tree):
18 if not tree:
23 if not tree:
19 raise error.ParseError(_("missing argument"))
24 raise error.ParseError(_("missing argument"))
@@ -50,7 +55,7 b' def _compile(tree):'
50 symbols = {
55 symbols = {
51 'all': lambda n, s: True,
56 'all': lambda n, s: True,
52 'none': lambda n, s: False,
57 'none': lambda n, s: False,
53 'size': lambda n, s: fileset.sizematcher(tree[2])(s),
58 'size': lambda n, s: _sizep(tree[2])(s),
54 }
59 }
55
60
56 name = fileset.getsymbol(tree[1])
61 name = fileset.getsymbol(tree[1])
General Comments 0
You need to be logged in to leave comments. Login now