[Pkg-mozext-commits] [adblock-plus] 259/464: Locale processing: Added export to Chrome-style JSON data
David Prévot
taffit at moszumanska.debian.org
Tue Jul 22 20:44:23 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit a30f983e7a9ff1564e7f8063bc1fe0ec634861de
Author: Wladimir Palant <trev at adblockplus.org>
Date: Wed Jul 4 15:24:31 2012 +0200
Locale processing: Added export to Chrome-style JSON data
---
localeTools.py | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/localeTools.py b/localeTools.py
index 8e08246..d340e91 100644
--- a/localeTools.py
+++ b/localeTools.py
@@ -4,11 +4,24 @@
# version 2.0 (the "License"). You can obtain a copy of the License at
# http://mozilla.org/MPL/2.0/.
-import re, sys, codecs, cgi
+import re, sys, codecs, cgi, json
from StringIO import StringIO
from ConfigParser import SafeConfigParser
from xml.parsers.expat import ParserCreate, XML_PARAM_ENTITY_PARSING_ALWAYS
+class OrderedDict(dict):
+ def __init__(self):
+ self.__order = []
+ def __setitem__(self, key, value):
+ self.__order.append(key)
+ dict.__setitem__(self, key, value)
+ def iteritems(self):
+ done = set()
+ for key in self.__order:
+ if not key in done and key in self:
+ yield (key, self[key])
+ done.add(key)
+
def parseDTDString(data, path):
result = []
currentComment = [None]
@@ -93,3 +106,23 @@ def removeFromFile(path, key):
fileHandle = codecs.open(path, 'wb', encoding='utf-8')
fileHandle.write(data)
fileHandle.close()
+
+def toJSON(path):
+ fileHandle = codecs.open(path, 'rb', encoding='utf-8')
+ data = fileHandle.read()
+ fileHandle.close()
+
+ if path.endswith('.dtd'):
+ it = parseDTDString(data, path)
+ elif path.endswith('.properties'):
+ it = parsePropertiesString(data, path)
+ else:
+ return None
+
+ result = OrderedDict()
+ for name, comment, value in it:
+ obj = {'message': value}
+ if comment != None:
+ obj['description'] = comment
+ result[name] = obj
+ return json.dumps(result, indent=2)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list