summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py
blob: 956ebfe1797591fb8a81755111ea463ffab91170 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import logging
import Bcfg2.Server.Plugin
from Bcfg2.Server.Plugins.Cfg import CfgInfo

logger = logging.getLogger(__name__)

class CfgInfoXML(CfgInfo):
    __basenames__ = ['info.xml']

    def __init__(self, path):
        CfgInfo.__init__(self, path)
        self.infoxml = Bcfg2.Server.Plugin.InfoXML(path)

    def bind_info_to_entry(self, entry, metadata):
        mdata = dict()
        self.infoxml.pnode.Match(metadata, mdata, entry=entry)
        if 'Info' not in mdata:
            logger.error("Failed to set metadata for file %s" %
                         entry.get('name'))
            raise PluginExecutionError
        self._set_info(entry, mdata['Info'][None])

    def handle_event(self, event):
        self.infoxml.HandleEvent()

    def _set_info(self, entry, info):
        CfgInfo._set_info(self, entry, info)
        if '__children__' in info:
            for child in info['__children__']:
                entry.append(child)