forked from norBIT/alkisimport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refilter.py
executable file
·73 lines (60 loc) · 1.92 KB
/
refilter.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
***************************************************************************
refilter.py
---------------------
Date : Sep 2012
Copyright : (C) 2012-2023 by Jürgen E. Fischer
Email : jef at norbit dot de
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
from __future__ import print_function
from builtins import str
import re
import sys
import os
from itertools import islice
patterns = []
f = open(os.path.join(os.path.dirname(__file__), "re"), "r", encoding="utf-8")
while True:
line = list(islice(f, 50))
if not line:
break
patterns.append(re.compile("|".join([x.replace('\n','') for x in line])))
f.close()
if len(sys.argv) > 2:
print("usage: %s [logfile]" % (sys.argv[0]))
exit(1)
try:
if len(sys.argv) == 2:
f = open(sys.argv[1], "r", encoding="utf-8")
else:
f = os.fdopen(0, "r", encoding="utf-8")
except IOError:
print("%s: could not open %s" % (sys.argv[0], sys.argv[1]))
exit(1)
while True:
try:
line = f.readline()
except UnicodeDecodeError:
continue
if line == "":
break
found = False
for p in patterns:
if p.match(line):
found = True
break
if found:
continue
print(line, end=' ')
sys.stdout.flush()
f.close()