Create core directory to contain most of code not in object classes used by tests

Change-Id: I9aec6c55ccd71894182057d36e0025b69925d314
diff --git a/src/osmo_gsm_tester/core/template.py b/src/osmo_gsm_tester/core/template.py
new file mode 100644
index 0000000..2bf4fed
--- /dev/null
+++ b/src/osmo_gsm_tester/core/template.py
@@ -0,0 +1,62 @@
+# osmo_gsm_tester: automated cellular network hardware tests
+# Proxy to templating engine to handle files
+#
+# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
+#
+# Author: Neels Hofmeyr <neels@hofmeyr.de>
+#
+# This program 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.
+#
+# This program 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 program.  If not, see <http://www.gnu.org/licenses/>.
+
+import os
+from mako.lookup import TemplateLookup, Template
+
+from . import log
+from .util import dict2obj
+
+_lookup = None
+_logger = log.Origin(log.C_CNF, 'no templates dir set')
+
+def set_templates_dir(*templates_dirs):
+    global _lookup
+    global _logger
+    if not templates_dirs:
+        # default templates dir is relative to this source file
+        templates_dirs = [os.path.join(os.path.dirname(os.path.dirname(__file__)), 'templates')]
+    for d in templates_dirs:
+        if not os.path.isdir(d):
+            raise RuntimeError('templates dir is not a dir: %r'
+                               % os.path.abspath(d))
+    _lookup = TemplateLookup(directories=templates_dirs)
+    _logger = log.Origin(log.C_CNF, 'Templates')
+
+def render(name, values):
+    '''feed values dict into template and return rendered result.
+       ".tmpl" is added to the name to look it up in the templates dir.'''
+    global _lookup
+    if _lookup is None:
+        set_templates_dir()
+    tmpl_name = name + '.tmpl'
+    log.ctx(tmpl_name)
+    template = _lookup.get_template(tmpl_name)
+    _logger.dbg('rendering', tmpl_name)
+
+    return template.render(**dict2obj(values))
+
+def render_strbuf_inline(strbuf, values):
+    '''Receive a string containing template syntax, and generate output using
+       passed values.'''
+    mytemplate = Template(strbuf)
+    return mytemplate.render(**dict2obj(values))
+
+# vim: expandtab tabstop=4 shiftwidth=4