diff options
author | 2010-07-05 03:44:59 -0400 | |
---|---|---|
committer | 2010-07-05 03:44:59 -0400 | |
commit | 5a1b2d20545a02caf8eec343eba70c00effdf539 (patch) | |
tree | 77ef8cc8cae29c298f2153f93284c5e3e8f4d15c | |
parent | Some useful print statements, with augtool syntax. (diff) | |
download | ventoo-5a1b2d20545a02caf8eec343eba70c00effdf539.tar.gz ventoo-5a1b2d20545a02caf8eec343eba70c00effdf539.tar.bz2 ventoo-5a1b2d20545a02caf8eec343eba70c00effdf539.zip |
Added comesBefore to VentooModule
-rw-r--r-- | src/ventoo/VentooModule.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/ventoo/VentooModule.py b/src/ventoo/VentooModule.py index 35c79f9..e320766 100644 --- a/src/ventoo/VentooModule.py +++ b/src/ventoo/VentooModule.py @@ -64,9 +64,35 @@ class VentooModule: try: elem = self.xmlTree.xpath(osp.join(xPath)) if len(elem) >= 1 and not elem[0].get("docurl") == None: - #pdb.set_trace() return "file:///"+osp.abspath(osp.join(self.docRoot, augeas_utils.stripBothSlashes(elem[0].get("docurl")))) except etree.XPathEvalError: pass return None - + + + """ + Returns true if a comes before b + Raise ValueError if either a or b are not in the xml file. + a and b must both have the same parent node. + a and b are both tags, not paths. + """ + def comesBefore(self, a, b): + try: + elemAlist = self.xmlTree.xpath("//"+a) + elemBlist = self.xmlTree.xpath("//"+b) + except etree.XPathEvalError: + raise ValueError("Could not find one of "+b) + if len(elemBlist) != 1: + return ValueError("Could not find one of "+b) + if len(elemAlist) != 1: + return ValueError("Could not find one of "+a) + elemAparent = elemAlist[0].getparent() + elemBparent = elemBlist[0].getparent() + if elemBparent.tag != elemAparent.tag: + raise ValueError(a+" and "+b+" do not have the same parent.") + for child in elemAparent: + if child.tag == elemBlist[0].tag: + return False + if child.tag == elemAlist[0].tag: + return True + raise RuntimeError("Something is wrong in comesBefore in VentooModule...") |