Commit 241ff426 authored by Konstantin Ritt's avatar Konstantin Ritt
Browse files

[locale database utility] Minor code deduplication


Change-Id: Ib6917940dfc410148d88e539cad2cdf7331a940d
Reviewed-by: default avatarLars Knoll <lars.knoll@digia.com>
Showing with 9 additions and 20 deletions
...@@ -36,8 +36,6 @@ import sys ...@@ -36,8 +36,6 @@ import sys
import os import os
import xml.dom.minidom import xml.dom.minidom
doc_cache = {}
class DraftResolution: class DraftResolution:
# See http://www.unicode.org/cldr/process.html for description # See http://www.unicode.org/cldr/process.html for description
unconfirmed = 'unconfirmed' unconfirmed = 'unconfirmed'
...@@ -56,6 +54,12 @@ class Error: ...@@ -56,6 +54,12 @@ class Error:
def __str__(self): def __str__(self):
return self.msg return self.msg
doc_cache = {}
def parseDoc(file):
if not doc_cache.has_key(file):
doc_cache[file] = xml.dom.minidom.parse(file)
return doc_cache[file]
def findChild(parent, tag_name, arg_name=None, arg_value=None, draft=None): def findChild(parent, tag_name, arg_name=None, arg_value=None, draft=None):
for node in parent.childNodes: for node in parent.childNodes:
if node.nodeType != node.ELEMENT_NODE: if node.nodeType != node.ELEMENT_NODE:
...@@ -80,12 +84,7 @@ def findChild(parent, tag_name, arg_name=None, arg_value=None, draft=None): ...@@ -80,12 +84,7 @@ def findChild(parent, tag_name, arg_name=None, arg_value=None, draft=None):
return False return False
def findTagsInFile(file, path): def findTagsInFile(file, path):
doc = False doc = parseDoc(file)
if doc_cache.has_key(file):
doc = doc_cache[file]
else:
doc = xml.dom.minidom.parse(file)
doc_cache[file] = doc
elt = doc.documentElement elt = doc.documentElement
tag_spec_list = path.split("/") tag_spec_list = path.split("/")
...@@ -122,12 +121,7 @@ def findTagsInFile(file, path): ...@@ -122,12 +121,7 @@ def findTagsInFile(file, path):
return ret return ret
def _findEntryInFile(file, path, draft=None, attribute=None): def _findEntryInFile(file, path, draft=None, attribute=None):
doc = False doc = parseDoc(file)
if doc_cache.has_key(file):
doc = doc_cache[file]
else:
doc = xml.dom.minidom.parse(file)
doc_cache[file] = doc
elt = doc.documentElement elt = doc.documentElement
tag_spec_list = path.split("/") tag_spec_list = path.split("/")
...@@ -177,12 +171,7 @@ def _findEntryInFile(file, path, draft=None, attribute=None): ...@@ -177,12 +171,7 @@ def _findEntryInFile(file, path, draft=None, attribute=None):
return (None, None) return (None, None)
def findAlias(file): def findAlias(file):
doc = False doc = parseDoc(file)
if doc_cache.has_key(file):
doc = doc_cache[file]
else:
doc = xml.dom.minidom.parse(file)
doc_cache[file] = doc
alias_elt = findChild(doc.documentElement, "alias") alias_elt = findChild(doc.documentElement, "alias")
if not alias_elt: if not alias_elt:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment