From 60301459da33e4fdad4c5bc4c836c8990238dd61 Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Wed, 25 Jan 2012 10:27:13 -0600 Subject: Cfg: Inform user of info.xml override (#1089) Signed-off-by: Sol Jerome --- src/lib/Server/Plugins/Cfg.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/lib') diff --git a/src/lib/Server/Plugins/Cfg.py b/src/lib/Server/Plugins/Cfg.py index 0a791f171..d2e6e8a1d 100644 --- a/src/lib/Server/Plugins/Cfg.py +++ b/src/lib/Server/Plugins/Cfg.py @@ -31,6 +31,7 @@ try: except: have_cheetah = False +# setup logging logger = logging.getLogger('Bcfg2.Plugins.Cfg') @@ -220,25 +221,33 @@ class CfgEntrySet(Bcfg2.Server.Plugin.EntrySet): return "%s.H_%s" % (bfname, specific.hostname) def write_update(self, specific, new_entry, log): + # FIXME: need to redo print with python's logging module if 'text' in new_entry: name = self.build_filename(specific) if os.path.exists("%s.genshi" % name): - logger.error("Cfg: Unable to pull data for genshi types") + print("Cfg: Unable to pull data for genshi types") raise Bcfg2.Server.Plugin.PluginExecutionError elif os.path.exists("%s.cheetah" % name): - logger.error("Cfg: Unable to pull data for cheetah types") + print("Cfg: Unable to pull data for cheetah types") raise Bcfg2.Server.Plugin.PluginExecutionError try: etext = new_entry['text'].encode(self.encoding) except: - logger.error("Cfg: Cannot encode content of %s as %s" % (name, self.encoding)) + print("Cfg: Cannot encode content of %s as %s" % (name, self.encoding)) raise Bcfg2.Server.Plugin.PluginExecutionError open(name, 'w').write(etext) if log: - logger.info("Wrote file %s" % name) + print("Wrote file %s" % name) badattr = [attr for attr in ['owner', 'group', 'perms'] if attr in new_entry] if badattr: + # check for info files and inform user of their removal + if os.path.exists(self.path + "/:info"): + print("Removing :info file and replacing with info.xml") + os.remove(self.path + "/:info") + if os.path.exists(self.path + "/info"): + print("Removing info file and replacing with info.xml") + os.remove(self.path + "/info") metadata_updates = {} metadata_updates.update(self.metadata) for attr in badattr: @@ -251,7 +260,7 @@ class CfgEntrySet(Bcfg2.Server.Plugin.EntrySet): ofile.write(lxml.etree.tostring(infoxml, pretty_print=True)) ofile.close() if log: - logger.info("Wrote file %s" % (self.path + "/info.xml")) + print("Wrote file %s" % (self.path + "/info.xml")) class Cfg(Bcfg2.Server.Plugin.GroupSpool, -- cgit v1.2.3-1-g7c22