-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter-java-imports.py
More file actions
executable file
·58 lines (45 loc) · 1.47 KB
/
Copy pathfilter-java-imports.py
File metadata and controls
executable file
·58 lines (45 loc) · 1.47 KB
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
52
53
54
55
56
57
58
#!/usr/bin/env python
import re
import sys
number_re = re.compile('^[0-9]+$')
def extract_coordinate(part):
## print 'PART', part
return part.split(']')[0]
def extract_coordinates(name):
return map(extract_coordinate, name.split('[')[1:])
def allowed(importer, imported):
if importer == imported:
return None
if number_re.match(importer) and number_re.match(imported):
importer_number = int(importer)
imported_number = int(imported)
if imported_number <= importer_number:
return True
print 'DISALLOWED', importer, imported
return False
def check_import(importer_name, imported_name):
importer = extract_coordinates(importer_name)
imported = extract_coordinates(imported_name)
## print 'COORDINATES', importer, imported
while importer and imported:
status = allowed(importer[0], imported[0]) # Can be either True, False, or None
if status is None:
return status
del importer[0]
del imported[0]
if importer:
print 'DISALLOWED', importer[0], '?'
return False
return True
def main():
while True:
line = sys.stdin.readline()
if not line:
break
if line[-1:] == '\n':
line = line[:-1]
dummy, importer, imported = line.split(':')
## print 'NAMES', importer, imported
if not check_import(importer, imported):
print 'WARNING', importer, imported
main()