| OLD | NEW | 
|---|
| 1 # This Source Code Form is subject to the terms of the Mozilla Public | 1 # This Source Code Form is subject to the terms of the Mozilla Public | 
| 2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 
| 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 
| 4 | 4 | 
| 5 import re | 5 import re | 
| 6 import os | 6 import os | 
| 7 import sys | 7 import sys | 
| 8 import codecs | 8 import codecs | 
| 9 import json | 9 import json | 
| 10 import urllib | 10 import urllib | 
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 194     return parseString(data, path) | 194     return parseString(data, path) | 
| 195 | 195 | 
| 196 | 196 | 
| 197 def generateStringEntry(key, value, path): | 197 def generateStringEntry(key, value, path): | 
| 198     if path.endswith('.dtd'): | 198     if path.endswith('.dtd'): | 
| 199         return '<!ENTITY %s "%s">\n' % (escapeEntity(key), escapeEntity(value)) | 199         return '<!ENTITY %s "%s">\n' % (escapeEntity(key), escapeEntity(value)) | 
| 200     else: | 200     else: | 
| 201         return '%s=%s\n' % (escapeProperty(key), escapeProperty(value)) | 201         return '%s=%s\n' % (escapeProperty(key), escapeProperty(value)) | 
| 202 | 202 | 
| 203 | 203 | 
| 204 def appendToFile(path, key, value): |  | 
| 205     fileHandle = codecs.open(path, 'ab', encoding='utf-8') |  | 
| 206     fileHandle.write(generateStringEntry(key, value, path)) |  | 
| 207     fileHandle.close() |  | 
| 208 |  | 
| 209 |  | 
| 210 def removeFromFile(path, key): |  | 
| 211     fileHandle = codecs.open(path, 'rb', encoding='utf-8') |  | 
| 212     data = fileHandle.read() |  | 
| 213     fileHandle.close() |  | 
| 214 |  | 
| 215     if path.endswith('.dtd'): |  | 
| 216         data = re.sub(r'<!ENTITY\s+%s\s+"[^"]*">\s*' % key, '', data, re.S) |  | 
| 217     else: |  | 
| 218         data = re.sub(r'(^|\n)%s=[^\n]*\n' % key, r'\1', data, re.S) |  | 
| 219 |  | 
| 220     fileHandle = codecs.open(path, 'wb', encoding='utf-8') |  | 
| 221     fileHandle.write(data) |  | 
| 222     fileHandle.close() |  | 
| 223 |  | 
| 224 |  | 
| 225 def toJSON(path): | 204 def toJSON(path): | 
| 226     fileHandle = codecs.open(path, 'rb', encoding='utf-8') | 205     fileHandle = codecs.open(path, 'rb', encoding='utf-8') | 
| 227     data = fileHandle.read() | 206     data = fileHandle.read() | 
| 228     fileHandle.close() | 207     fileHandle.close() | 
| 229 | 208 | 
| 230     if path.endswith('.dtd'): | 209     if path.endswith('.dtd'): | 
| 231         it = parseDTDString(data, path) | 210         it = parseDTDString(data, path) | 
| 232     elif path.endswith('.properties'): | 211     elif path.endswith('.properties'): | 
| 233         it = parsePropertiesString(data, path) | 212         it = parsePropertiesString(data, path) | 
| 234     else: | 213     else: | 
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 484 | 463 | 
| 485     # Remove any extra files | 464     # Remove any extra files | 
| 486     for dir, files in dirs.iteritems(): | 465     for dir, files in dirs.iteritems(): | 
| 487         baseDir = os.path.join(localeConfig['base_path'], dir) | 466         baseDir = os.path.join(localeConfig['base_path'], dir) | 
| 488         if not os.path.exists(baseDir): | 467         if not os.path.exists(baseDir): | 
| 489             continue | 468             continue | 
| 490         for file in os.listdir(baseDir): | 469         for file in os.listdir(baseDir): | 
| 491             path = os.path.join(baseDir, file) | 470             path = os.path.join(baseDir, file) | 
| 492             if os.path.isfile(path) and (file.endswith('.json') or file.endswith
     ('.properties') or file.endswith('.dtd')) and not file in files: | 471             if os.path.isfile(path) and (file.endswith('.json') or file.endswith
     ('.properties') or file.endswith('.dtd')) and not file in files: | 
| 493                 os.remove(path) | 472                 os.remove(path) | 
| OLD | NEW | 
|---|