Signed-off-by: Ramon Medeiros <ramonn(a)linux.vnet.ibm.com>
---
utils.py | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/utils.py b/utils.py
index 5a3f209..ae8954f 100644
--- a/utils.py
+++ b/utils.py
@@ -35,6 +35,36 @@ from wok.xmlutils.utils import xpath_get_text
MAX_REDIRECTION_ALLOWED = 5
+def get_template_by_name(name):
+
+ conn = sqlite3.connect(config.get_object_store(), timeout=10)
+ cursor = conn.cursor()
+
+ # if * is passed: select all fields
+ sql = "SELECT json from objects where type=='template' and
id=='%s'" % name
+ if name == "*":
+ sql = "SELECT json from objects where type == 'template'"
+
+ # execute and fetch results
+ cursor.execute(sql)
+ content = cursor.fetchall()
+
+ # no record: return nothing
+ if len(content) == 0:
+ return {}
+
+ # sqllite returns a tuple of strings
+ # iterate over it and return a list of dictonaries
+ if len(content[0]) == 1:
+ return eval(content[0][0])
+
+ result = []
+ for dictonary in content[0]:
+ result.append(eval(dictonary))
+
+ return result
+
+
def _uri_to_name(collection, uri):
expr = '/plugins/kimchi/%s/(.*?)$' % collection
m = re.match(expr, uri)
--
2.1.0