Commit 5f38b93d authored by Ad Schellevis's avatar Ad Schellevis

add alternate root location for template generation (for local testing)

parent 37cadc25
...@@ -4,3 +4,4 @@ parameters:%s ...@@ -4,3 +4,4 @@ parameters:%s
type:inline type:inline
message:generate template %s message:generate template %s
config:/conf/config.xml config:/conf/config.xml
root_dir:/
...@@ -47,7 +47,7 @@ def execute(action,parameters): ...@@ -47,7 +47,7 @@ def execute(action,parameters):
if action.command == 'template.reload': if action.command == 'template.reload':
import template import template
import config import config
tmpl = template.Template() tmpl = template.Template(action.root_dir)
conf = config.Config(action.config) conf = config.Config(action.config)
tmpl.setConfig(conf.get()) tmpl.setConfig(conf.get())
filenames = tmpl.generate(parameters) filenames = tmpl.generate(parameters)
......
...@@ -42,11 +42,16 @@ import jinja2 ...@@ -42,11 +42,16 @@ import jinja2
class Template(object): class Template(object):
def __init__(self): def __init__(self,target_root_directory="/"):
""" constructor """ constructor
:return: :return:
""" """
# init config (config.xml) data
self._config = {} self._config = {}
# set target root
self._target_root_directory = target_root_directory
# setup jinja2 environment # setup jinja2 environment
self._template_dir = os.path.dirname(os.path.abspath(__file__))+'/../templates/' self._template_dir = os.path.dirname(os.path.abspath(__file__))+'/../templates/'
self._j2_env = jinja2.Environment(loader=jinja2.FileSystemLoader(self._template_dir),trim_blocks=True) self._j2_env = jinja2.Environment(loader=jinja2.FileSystemLoader(self._template_dir),trim_blocks=True)
...@@ -229,6 +234,8 @@ class Template(object): ...@@ -229,6 +234,8 @@ class Template(object):
# render page and write to disc # render page and write to disc
content = j2_page.render(cnf_data) content = j2_page.render(cnf_data)
# prefix filename with defined root directory
filename = ('%s/%s'%(self._target_root_directory, filename)).replace('//','/')
if create_directory: if create_directory:
# make sure the target directory exists # make sure the target directory exists
self._create_directory(filename) self._create_directory(filename)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment