diff options
Diffstat (limited to 'src/ventoo/VentooModule.py')
-rw-r--r-- | src/ventoo/VentooModule.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/ventoo/VentooModule.py b/src/ventoo/VentooModule.py new file mode 100644 index 0000000..35c79f9 --- /dev/null +++ b/src/ventoo/VentooModule.py @@ -0,0 +1,72 @@ +""" + + This file is part of the Ventoo program. + + This is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + It is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this software. If not, see <http://www.gnu.org/licenses/>. + + Copyright 2010 Christopher Harvey + +""" + +import os.path as osp +from lxml import etree +import augeas_utils +import search_paths + +class VentooModule: + def __init__(self, moduleName): + #see if we can find the module files + found = False; + for p in search_paths.modules: + thisPath = osp.join(p,moduleName,"main.xml") + if osp.isfile(thisPath): + self.pathFound = thisPath + found = True + self.docRoot = osp.join(p, moduleName) + break + if not found: + raise RuntimeError('Could not find '+moduleName+' Module') + self.xmlTree = etree.parse(self.pathFound) + #validate the module main.xml file. + #make sure it starts with <VentooModule> + self.xmlRoot = self.xmlTree.getroot() + if self.xmlRoot.tag != "VentooModule": + raise RuntimeError('Ventoo modules need to start with <VentooModule>') + + + def getChildrenOf(self, xPath): + children = self.xmlTree.xpath(osp.join(xPath, '*')) + ret = [] + for i in range(len(children)): + if not children[i].tag.startswith('ventoo_'): + ret.extend([children[i]]) + return ret + + def getMultOf(self, xPath): + elem = self.xmlTree.xpath(osp.join(xPath)) + if len(elem) >= 1: + return elem[0].get("mult") + else: + return '0' + + def getDocURLOf(self, xPath): + 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 + |