Logo Search packages:      
Sourcecode: bcfg2 version File versions  Download package

def lib::Server::Metadata::Metadata::HandleEvent (   self,

Handle update events for data files

Definition at line 46 of file Metadata.py.

00046                                 :
        '''Handle update events for data files'''
        filename = event.filename.split('/')[-1]
        if filename not in ['groups.xml', 'clients.xml']:
        if event.code2str() == 'endExist':
            xdata = lxml.etree.parse("%s/%s" % (self.data, filename))
        except lxml.etree.XMLSyntaxError:
            self.logger.error('Failed to parse %s' % (filename))
        if filename == 'clients.xml':
            self.clients = {}
            self.aliases = {}
            self.clientdata = xdata
            for client in xdata.findall('./Client'):
                if 'address' in client.attrib:
                    self.addresses[client.get('address')] = client.get('name')
                for alias in [alias for alias in client.findall('Alias') if 'address' in alias.attrib]:
                    self.addresses[alias.get('address')] = client.get('name')
                self.clients.update({client.get('name'): client.get('profile')})
                [self.aliases.update({alias.get('name'): client.get('name')}) for alias in client.findall('Alias')]
        elif filename == 'groups.xml':
            self.public = []
            self.profiles = []
            self.toolsets = {}
            self.groups = {}
            grouptmp = {}
            self.categories = {}
            for group in xdata.findall('./Group'):
                grouptmp[group.get('name')] = tuple([[item.get('name') for item in group.findall(spec)]
                                                     for spec in ['./Bundle', './Group']])
                if group.get('default', 'false') == 'true':
                    self.default = group.get('name')
                if group.get('profile', 'false') == 'true':
                if group.get('public', 'false') == 'true':
                if group.attrib.has_key('toolset'):
                    self.toolsets[group.get('name')] = group.get('toolset')
                if group.attrib.has_key('category'):
                    self.categories[group.get('name')] = group.get('category')
            for group in grouptmp:
                # self.groups[group] => (bundles, groups, categories)
                self.groups[group] = ([], [], {})
                tocheck = [group]
                while tocheck:
                    now = tocheck.pop()
                    if now not in self.groups[group][1]:
                    if grouptmp.has_key(now):
                        (bundles, groups) = grouptmp[now]
                        for ggg in [ggg for ggg in groups if ggg not in self.groups[group][1]]:
                            if not self.categories.has_key(ggg) or not self.groups[group][2].has_key(self.categories[ggg]):
                            if self.categories.has_key(ggg):
                                self.groups[group][2][self.categories[ggg]] = ggg
                        [self.groups[group][0].append(bund) for bund in bundles
                         if bund not in self.groups[group][0]]
        self.states[filename] = True
        if False not in self.states.values():
            # check that all client groups are real and complete
            real = self.groups.keys()
            for client in self.clients.keys():
                if self.clients[client] not in real or self.clients[client] not in self.profiles:
                    self.logger.error("Client %s set as nonexistant or incomplete group %s" \
                                      % (client, self.clients[client]))
                    self.logger.error("Removing client mapping for %s" % (client))
                    del self.clients[client]

    def set_profile(self, client, profile):

Generated by  Doxygen 1.6.0   Back to index