-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsj.py
51 lines (38 loc) · 1.11 KB
/
sj.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# vim:fileencoding=utf-8
"""
"""
from __future__ import print_function
import argparse
import re
import sys
import ijson
__version__ = '0.2.1'
KEY_RE = re.compile('^[a-z0-9_][\\.a-z0-9_]*[a-z0-9_]*$')
def yield_offenders(stream, matcher=KEY_RE):
parser = ijson.parse(stream)
for prefix, event, value in parser:
if event != 'map_key':
continue
if matcher.match(value):
continue
yield prefix, value
def main(sysargs=sys.argv[:], stream=sys.stdin):
parser = argparse.ArgumentParser(version=__version__)
parser.add_argument(
'-q', '--quiet', help='exit code only', action='store_true'
)
args = parser.parse_args(sysargs[1:])
res = 0
for prefix, value in yield_offenders(stream):
res = 1
if args.quiet:
continue
if prefix != '':
print('"{}.{}" is not snakey!'.format(prefix, value),
file=sys.stderr)
else:
print('"{}" is not snakey!'.format(value), file=sys.stderr)
return res
if __name__ == '__main__':
sys.exit(main())