-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutil_unsubscribe_nonexistent.py
More file actions
executable file
·112 lines (86 loc) · 2.6 KB
/
Copy pathutil_unsubscribe_nonexistent.py
File metadata and controls
executable file
·112 lines (86 loc) · 2.6 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/local/bin/python3 -bb
import os
import re
import ftn.msg
import ftnimport
import ftnconfig
db=ftnconfig.connectdb()
def set_status(echostatus, e, s):
if e in echostatus:
raise Exception("duplicate echo")
echostatus[e] = s
def process_4441():
basedir="areafix/4441"
UPLINK="2:5020/4441"
RE_subscribed=re.compile("Эха (\S+) подписана")
RE_alreadysubscribed=re.compile("Вы уже подписаны на (\S+)")
RE_notfound=re.compile("Эха (\S+) не найдена")
echostatus={}
for mfile in os.listdir(basedir):
m=ftn.msg.MSG(os.path.join(basedir,mfile))
orig, dest, msgid, header, body, charset = ftnimport.normalize_message(m)
print(orig, dest, msgid)
if orig!=("node", UPLINK):
continue
# print(repr(header.find("subject").text))
lines = body.split("\n")
for l in lines:
if len(l)==0 or l[0]==">":
continue
m=RE_subscribed.match(l)
if m:
set_status(echostatus, m.group(1), "ok")
continue
m=RE_alreadysubscribed.match(l)
if m:
set_status(echostatus, m.group(1), "ok")
continue
m=RE_notfound.match(l)
if m:
set_status(echostatus, m.group(1), "absent")
continue
raise Exception("unrecognized: %s"%l)
return echostatus
def process_758():
basedir="areafix/758"
UPLINK="2:5020/758"
RE_subscribed=re.compile("(\S+) \.* Linked")
RE_alreadysubscribed=re.compile("Area (\S+) is already linked")
RE_notfound=re.compile("Area (\S+) doesn't exist")
echostatus={}
for mfile in os.listdir(basedir):
m=ftn.msg.MSG(os.path.join(basedir,mfile))
orig, dest, msgid, header, body, charset = ftnimport.normalize_message(m)
print(orig, dest, msgid)
if orig!=("node", UPLINK):
continue
# print(repr(header.find("subject").text))
lines = body.split("\n")
for l in lines:
if len(l)==0 or l[0]==">":
continue
m=RE_subscribed.match(l)
if m:
set_status(echostatus, m.group(1), "ok")
continue
m=RE_alreadysubscribed.match(l)
if m:
set_status(echostatus, m.group(1), "ok")
continue
m=RE_notfound.match(l)
if m:
set_status(echostatus, m.group(1), "absent")
continue
#raise Exception("unrecognized: %s"%l)
return echostatus
# ---
process = [
("2:5020/758", process_758),
#("2:5020/4441", process_4441),
]
for link, func in process:
with ftnimport.session(db) as sess:
for k, v in func().items():
if v=="absent":
print (k)
sess.remove_subscription("echo", k, link)