diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Server/Core.py | 11 | ||||
-rwxr-xr-x | src/sbin/bcfg2-info | 11 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/lib/Server/Core.py b/src/lib/Server/Core.py index 05625cf22..38f854f66 100644 --- a/src/lib/Server/Core.py +++ b/src/lib/Server/Core.py @@ -37,6 +37,14 @@ except: pass +def sort_xml(node, key=None): + for child in node: + sort_xml(child, key) + + sorted_children = sorted(node, key=key) + node[:] = sorted_children + + class CoreInitError(Exception): """This error is raised when the core cannot be initialized.""" pass @@ -315,6 +323,9 @@ class Core(Component): except: logger.error("error in BindStructure", exc_info=1) self.validate_goals(meta, config) + + sort_xml(config, key=lambda e: e.get('name')) + logger.info("Generated config for %s in %.03f seconds" % \ (client, time.time() - start)) return config diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index 7c655ebe0..31b9ba0c6 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -104,13 +104,6 @@ def displayTrace(trace, num=80, sort=('time', 'calls')): stats.sort_stats('cumulative', 'calls', 'time') stats.print_stats(200) -def sort_xml(node, key=None): - for child in node: - sort_xml(child, key) - - sorted_children = sorted(node, key=key) - node[:] = sorted_children - class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core): """Main class for bcfg2-info.""" def __init__(self, repo, plgs, passwd, encoding, event_debug, filemonitor='default'): @@ -214,9 +207,7 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core): if not ofile.startswith('/tmp') and not path_force: print("Refusing to write files outside of /tmp without -f option") return - client_config = self.BuildConfiguration(client) - sort_xml(client_config, key=lambda e: e.get('name')) - lxml.etree.ElementTree(client_config).write(ofile, + lxml.etree.ElementTree(self.BuildConfiguration(client)).write(ofile, encoding='UTF-8', xml_declaration=True, pretty_print=True) else: |