forked from cubesky/MAT2IFW
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmat2ifw_Auto.py
45 lines (37 loc) · 1.48 KB
/
mat2ifw_Auto.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
# coding: utf-8
from functools import reduce
def comb(s1,s2): return s1 + "\n" + s2
matService = []
matReciever = []
matActivity = []
matUnknown = []
for line in open("mat.txt"):
if "service" in line.lower():
matService.append(" <component-filter name=\"" + line.replace("\n","") + "\" />")
elif "receiver" in line.lower():
matReciever.append(" <component-filter name=\"" + line.replace("\n","") + "\" />")
elif "activity" in line.lower():
matActivity.append(" <component-filter name=\"" + line.replace("\n","") + "\" />")
else:
matUnknown.append(" <component-filter name=\"" + line.replace("\n","") + "\" />")
if len(matService) > 0:
ifwServiceText = "<service block=\"true\" log=\"false\">\n" + reduce(comb,matService) + "\n</service>"
else:
ifwServiceText = ""
if len(matReciever) > 0:
ifwRecieverText = "<broadcast block=\"true\" log=\"false\">\n" + reduce(comb,matReciever) + "\n</broadcast>"
else:
ifwRecieverText = ""
if len(matActivity) > 0:
ifwActivityText = "<activity block=\"true\" log=\"false\">\n" + reduce(comb,matActivity) + "\n</activity>"
else:
ifwActivityText = ""
if len(matUnknown) > 0:
ifwUnknownText = "<!-- Unrecognized --\n" + reduce(comb,matUnknown) + "\n-->"
else:
ifwUnknownText = ""
result = "<rules>\n" + ifwServiceText + "\n" + ifwRecieverText + "\n" + ifwActivityText + "\n\n" + ifwUnknownText + "\n\n</rules>"
print(result)
fo = open("ifw.xml", "w")
fo.write(result)
fo.close()