aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/VentooModule.py')
-rw-r--r--src/backend/VentooModule.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/backend/VentooModule.py b/src/backend/VentooModule.py
new file mode 100644
index 0000000..77a81ea
--- /dev/null
+++ b/src/backend/VentooModule.py
@@ -0,0 +1,70 @@
+"""
+
+ 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
+
+_ventoo_search_paths_ = ['../modules', '../../modules']
+
+class VentooModule:
+ def __init__(self, moduleName):
+ #see if we can find the module files
+ found = False;
+ for p in _ventoo_search_paths_:
+ thisPath = osp.join(p,moduleName,"main.xml")
+ if osp.isfile(thisPath):
+ self.pathFound = thisPath
+ found = True
+ 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:
+ return elem[0].get("docurl")
+ except etree.XPathEvalError:
+ pass
+ return None
+