From 426e8fad3aa09a124d3bd5c9e628739d05797909 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Mon, 8 Nov 2004 20:59:47 +0000 Subject: tighten up error checking 2004/11/07 19:54:59-06:00 anl.gov!desai remove bogus functions 2004/11/07 11:46:54-06:00 anl.gov!desai pylint fixes 2004/11/04 16:46:02-06:00 anl.gov!desai clean up preinstall config files (Logical change 1.148) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@660 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Client/Toolset.py | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/lib/Client/Toolset.py b/src/lib/Client/Toolset.py index bc73240f1..20895ce28 100644 --- a/src/lib/Client/Toolset.py +++ b/src/lib/Client/Toolset.py @@ -42,10 +42,10 @@ class Toolset(object): self.modified = [] self.extra = [] if self.__important__: - for cfile in cfg.findall(".//ConfigFile"): - for name in self.__important__: - if cfile.get("name") == name: - self.InstallConfigFile(cfile) + for cfile in [cfl for cfl in cfg.findall(".//ConfigFile") if cfl.get('name') in self.__important__]: + self.VerifyEntry(cfile) + if not self.states[cfile]: + self.InstallConfigFile(cfile) def CondPrint(self, state, msg): '''Conditionally print message''' @@ -61,14 +61,6 @@ class Toolset(object): print "%s: %s\n" % (ttype, value) del ttype, value, trace - def print_failure(self): - '''Display curses style failure message''' - self.CondPrint('verbose', "\033[60G[\033[1;31mFAILED\033[0;39m]\r") - - def print_success(self): - '''Display curses style success message''' - self.CondPrint('verbose', "\033[60G[ \033[1;32mOK\033[0;39m ]\r") - # These next functions form the external API def Inventory(self): @@ -93,31 +85,31 @@ class Toolset(object): self.modified.remove(structure) if structure.tag == 'Bundle': # check for clobbered data - modlist = [x.get('name') for x in structure.getchildren() if x.tag == 'ConfigFile'] + modlist = [cfile.get('name') for cfile in structure.getchildren() if cfile.tag == 'ConfigFile'] for entry in structure.getchildren(): self.VerifyEntry(entry, modlist) try: - state = [self.states[x] for x in structure.getchildren()] + state = [self.states[entry] for entry in structure.getchildren()] if False not in state: self.structures[structure] = True - except KeyError, k: - print "State verify evidently failed for %s" % (k) + except KeyError, msg: + print "State verify evidently failed for %s" % (msg) self.structures[structure] = False def Install(self): '''Baseline Installation method based on current entry states''' - self.modified = [k for (k, v) in self.structures.iteritems() if not v] - for entry in [k for (k, v) in self.states.iteritems() if not v]: - self.InstallEntry(entry) + self.modified = [key for (key, val) in self.structures.iteritems() if not val] + [self.InstallEntry(key) for (key, val) in self.states.iteritems() if not val] def GenerateStats(self): '''Generate XML summary of execution statistics''' stats = Element("Statistics") - SubElement(stats, "Structures", good=str(len([k for k, v in self.structures.iteritems() if v])), \ - bad=str(len([k for k, v in self.structures.iteritems() if not v]))) - SubElement(stats, "Entries", good=str(len([k for k, v in self.states.iteritems() if v])), \ - bad=str(len([k for k, v in self.states.iteritems() if not v]))) - if len([k for k, v in self.structures.iteritems() if not v]) == 0: + SubElement(stats, "Structures", good=str(len([key for key, val in + self.structures.iteritems() if val])), \ + bad=str(len([key for key, val in self.structures.iteritems() if not val]))) + SubElement(stats, "Entries", good=str(len([key for key, val in self.states.iteritems() if val])), \ + bad=str(len([key for key, val in self.states.iteritems() if not val]))) + if len([key for key, val in self.structures.iteritems() if not val]) == 0: stats.set('state', 'clean') else: stats.set('state', 'dirty') @@ -221,7 +213,7 @@ class Toolset(object): chown(entry.get('name'), getpwnam(entry.get('owner'))[2], getgrnam(entry.get('group'))[2]) chmod(entry.get('name'), entry.get('perms')) - except: + except (OSError, KeyError): self.CondPrint('debug', 'Permission fixup failed for %s' % (entry.get('name'))) return False -- cgit v1.2.3-1-g7c22