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