Commit a4b9c029 authored by Franco Fichtner's avatar Franco Fichtner

configd: small improvements loosely related to #1238

o Don't look for templates in manufacturer directory
o Allow to use "/" component separator, it's safe
o Hook up the "template list" command
parent 35122576
......@@ -5,3 +5,9 @@ type:inline
message:generate template %s
config:/conf/config.xml
root_dir:/
[list]
command:template.list
type:inline
message:list templates
root_dir:/
"""
Copyright (c) 2014 Ad Schellevis
All rights reserved.
Redistribution and use in source and binary forms, with or without
......@@ -28,15 +27,14 @@
package : configd
function: configd inline actions
"""
import syslog
import template
import config
__author__ = 'Ad Schellevis'
def execute(action, parameters):
""" wrapper for inline functions
......@@ -49,6 +47,8 @@ def execute(action, parameters):
tmpl = template.Template(action.root_dir)
conf = config.Config(action.config)
tmpl.set_config(conf.get())
# XXX backwards-compat for '.' syntax, remove post-17.1
parameters = parameters.replace('.', '/')
filenames = tmpl.generate(parameters)
del conf
......
......@@ -95,8 +95,8 @@ class Template(object):
"""
result = {}
for root, dirs, files in os.walk(self._template_dir):
if len(root) > len(self._template_dir):
module_name = '.'.join(root.replace(self._template_dir, '').split('/'))
if root.count('/') > self._template_dir.count('/'):
module_name = root.replace(self._template_dir, '')
if module_name not in result:
result[module_name] = self.list_module(module_name)
......
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