forked from SparkyBluefang/S4E
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildInstallRdf
executable file
·211 lines (174 loc) · 4.57 KB
/
buildInstallRdf
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python2
# ***** BEGIN LICENSE BLOCK *****
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012, 2015 Matthew Turnbull <sparky@bluefang-logic.com>. All Rights Reserved.
#
# ***** END LICENSE BLOCK *****
import re
import os
import codecs
from datetime import datetime
from xml.sax.saxutils import escape
propRE = re.compile(r"^\s*([a-zA-Z.]+)\s*=\s*(.+?)\s*(#.*)?$", re.U)
targetIds = {
"Firefox": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
"SeaMonkey": "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}"
}
rdfProps = [
"name",
"description",
"id",
"version",
"creator",
"developer",
"translator",
"contributor",
"type",
"bootstrap",
"unpack",
"strictCompatibility",
"aboutURL",
"homepageURL",
"icon64URL",
"iconURL",
"optionsType",
"optionsURL",
"updateKey",
"updateURL",
"multiprocessCompatible"
]
rdfPropsMulti = [
"developer",
"translator",
"contributor"
]
def parsePropFile(filename):
props = {}
with codecs.open(filename, mode="r", encoding="utf-8") as f:
for line in f:
result = propRE.search(line)
if result:
props[result.group(1)] = result.group(2)
return props
def parseL10N(l10nDir):
langs = {}
for l10n in os.listdir(l10nDir):
l10nMeta = os.path.join(l10nDir, l10n, "meta.properties")
if os.path.isfile(l10nMeta):
langs[l10n] = parsePropFile(l10nMeta)
else:
print "WARNING: could not find %s" % l10nMeta
return langs
def getConfig():
props = parsePropFile("install.manifest")
langs = parseL10N("chrome/locale/")
defaultLocale = langs[props["defaultLocale"]]
del langs[props["defaultLocale"]]
del props["defaultLocale"]
info = {}
targets = {}
for prop in props:
val = props[prop]
if prop in targetIds:
val = val.split('|')
target = {
"id": targetIds[prop],
"min": val[0],
"max": val[1]
}
targets[prop] = target
continue;
if prop in rdfPropsMulti:
val = val.split('|')
if prop in rdfProps:
info[prop] = val
info["name"] = defaultLocale["name"]
info["description"] = defaultLocale["description"]
return (info, targets, langs)
def buildManafest():
(info, targets, locales) = getConfig()
f = codecs.open("install.rdf", mode="w", encoding="utf-8")
#
# Print the header
#
f.write(u"""<?xml version="1.0" encoding="UTF-8"?>
<!-- ***** BEGIN LICENSE BLOCK *****
-
- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
- Copyright (C) %s Matthew Turnbull <sparky@bluefang-logic.com>. All Rights Reserved.
-
- ***** END LICENSE BLOCK ***** -->
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">\n""" % (datetime.now().year))
#
# Print extension info blocks
#
f.write(u"""
<!-- Info -->\n""")
keys = info.keys()
keys.sort()
for prop in rdfProps:
if prop in info:
if prop in rdfPropsMulti:
for val in info[prop]:
f.write(u"""
<em:%s>%s</em:%s>""" % (prop, escape(val), prop))
else:
f.write(u"""
<em:%s>%s</em:%s>""" % (prop, escape(info[prop]), prop))
f.write(u"""\n""")
#
# Print the locale blocks
#
f.write(u"""
<!-- Localizations -->\n""")
keys = locales.keys()
keys.sort()
for locale in keys:
l10n = locales[locale]
translators = ""
for t in l10n["translator"].split(","):
translators += u"""<em:translator>%s [%s]</em:translator>""" % (escape(t.strip()), locale)
f.write(u"""
<em:localized><!-- %s -->
<Description>
<em:locale>%s</em:locale>
<em:name>%s</em:name>
<em:description>%s</em:description>
<em:creator>%s</em:creator>
<em:homepageURL>%s</em:homepageURL>
%s
</Description>
</em:localized>\n""" % (locale, locale, escape(l10n["name"]), escape(l10n["description"]), escape(info["creator"]), escape(info["homepageURL"]), translators))
#
# Print target blocks
#
f.write(u"""
<!-- Targets -->\n""")
keys = targets.keys()
keys.sort()
for t in keys:
target = targets[t]
f.write(u"""
<em:targetApplication><!-- %s -->
<Description>
<em:id>%s</em:id>
<em:minVersion>%s</em:minVersion>
<em:maxVersion>%s</em:maxVersion>
</Description>
</em:targetApplication>\n""" % (t, target["id"], target["min"], target["max"]))
#
# Print the footer
#
f.write("""
</Description>
</RDF>\n""")
if __name__ == "__main__":
buildManafest()