-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvj-ag-filter.py
40 lines (35 loc) · 962 Bytes
/
vj-ag-filter.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
import fileinput
import re
import os
import sys
def print_file_matches(dir, collect):
print("\nEntering directory `{}'".format(dir), flush=True)
for suffix in collect:
print(suffix)
print("Leaving directory `{}'".format(dir), flush=True)
collect = []
collect = []
lastdir = None
hits = 0
for line in fileinput.input():
line = line.rstrip()
if len(line) == 0:
continue
match = re.match('^(..[^:]+)([:(]\d+[:,]\d+[:)].*)$', line)
if not match:
print(line, flush=True)
continue
hits += 1
dir = os.path.dirname(match.group(1)) # os.path.realpath( ?
basename = os.path.basename(match.group(1))
if lastdir is None:
lastdir = dir
if dir != lastdir:
print_file_matches(lastdir, collect)
collect = []
collect.append(basename + match.group(2))
lastdir = dir
if lastdir is not None:
print_file_matches(lastdir, collect)
if hits == 0:
sys.exit(1)