From 5a1b2d20545a02caf8eec343eba70c00effdf539 Mon Sep 17 00:00:00 2001 From: Christopher Harvey Date: Mon, 5 Jul 2010 03:44:59 -0400 Subject: Added comesBefore to VentooModule --- src/ventoo/VentooModule.py | 30 ++++++++++++++++++++++++++++-- 1 file 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...") -- cgit v1.2.3-65-gdbad