-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathlabels.py
70 lines (59 loc) · 1.75 KB
/
labels.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
import os
from bs4 import BeautifulSoup
import codecs
DIR="src/main/webapp";
RESOURCES="src/main/webapp/WEB-INF/resources/"
NEW_RESOURCES="/tmp/"
def parse_dir(directory, filter):
file_paths = []
for root, directories, files in os.walk(directory):
for filename in files:
filepath = os.path.join(root, filename)
if (filter in filepath):
file_paths.append(filepath)
return file_paths
codes = {}
for jsp_file in parse_dir(DIR, ".jsp"):
jsp = open(jsp_file).read()
html = BeautifulSoup(jsp)
for link in html.find_all('spring:message'):
text = link.get("text") if link.get("text") != None else ""
code = link.get('code')
if not code.startswith("$"):
if code in codes:
there = codes[code]
if isinstance(there, list):
if not text in there:
codes[code].append(text)
else:
if text != there:
codes[code] = [there, text]
else:
codes[code] = text
# for code in sorted(codes):
# print "%s=%s" % (code, codes[code])
for rsr_file in parse_dir(RESOURCES, "SpacesResources"):
print "process " + rsr_file
rsr = open(rsr_file).readlines()
rsr_map = {}
for r in rsr:
if "=" in r:
prop = r.strip().split("=")
key = prop[0].strip()
value = prop[1].strip()
print ">%s<" % key
rsr_map[key] = value
for code in sorted(codes):
if not code in rsr_map:
rsr_map[code] = codes[code]
fpath = rsr_file.split("/")
nfpath = "%s/New%s" % ("/".join(fpath[:-1]), fpath[-1:][0])
f = open(nfpath, "w")
for code in sorted(rsr_map):
prop = "%s=%s\n" % (code, rsr_map[code])
f.write(prop)
f.close()
# xmldoc = minidom.parse("labels.xml")
# messages = xmldoc.getElementsByTagName("spring:message")
# for message in messages:
# print "%s=%s" % (message.attributes['code'].value, message.attributes['text'].value)