Refactor xpath eval code from BuildDispatcher so that it can be
re-used.
---
imagefactory/BuildDispatcher.py | 5 +----
imagefactory/Template.py | 3 +++
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/imagefactory/BuildDispatcher.py b/imagefactory/BuildDispatcher.py
index e07cff9..ea0fa4d 100644
--- a/imagefactory/BuildDispatcher.py
+++ b/imagefactory/BuildDispatcher.py
@@ -16,7 +16,6 @@
# also available at
http://www.gnu.org/copyleft/gpl.html.
import sys
-import libxml2
import logging
from threading import Thread, Lock
from imagefactory.builders import *
@@ -36,9 +35,7 @@ class BuildDispatcher(object):
builder_class = MockBuilder.MockBuilder
if (target != "mock"): # If target is mock always run mock builder
regardless of template
- parsed_doc = libxml2.parseDoc(template_object.xml)
- node = parsed_doc.xpathEval('/template/os/name')
- os_name = node[0].content
+ os_name = template_object.xmlNode('/template/os/name')
class_name = "%sBuilder" % (os_name, )
try:
module_name = "imagefactory.builders.%s" % (class_name, )
diff --git a/imagefactory/Template.py b/imagefactory/Template.py
index af005a1..260db7a 100644
--- a/imagefactory/Template.py
+++ b/imagefactory/Template.py
@@ -18,6 +18,7 @@
# MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at
http://www.gnu.org/copyleft/gpl.html.
+import libxml2
import logging
import httplib2
import re
@@ -63,6 +64,8 @@ class Template(object):
return locals()
xml = property(**xml())
+ def xmlNode(self, xpath):
+ return libxml2.parseDoc(self.xml).xpathEval(xpath)[0].content
def __repr__(self):
if(self.xml):
--
1.7.4.4