blob: aedf579fcbeaa158880ec06d334a2f8a7abcf56d (
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
""" Handle info and :info files """
import logging
import Bcfg2.Server.Plugin
from Bcfg2.Server.Plugins.Cfg import CfgInfo
LOGGER = logging.getLogger(__name__)
class CfgLegacyInfo(CfgInfo):
""" CfgLegacyInfo handles :file:`info` and :file:`:info` files for
:ref:`server-plugins-generators-cfg` """
#: Handle :file:`info` and :file:`:info`
__basenames__ = ['info', ':info']
#: CfgLegacyInfo is deprecated. Use
#: :class:`Bcfg2.Server.Plugins.Cfg.CfgInfoXML.CfgInfoXML` instead.
deprecated = True
def __init__(self, path):
CfgInfo.__init__(self, path)
self.path = path
#: The set of info metadata stored in the file
self.metadata = None
__init__.__doc__ = CfgInfo.__init__.__doc__
def bind_info_to_entry(self, entry, metadata):
self._set_info(entry, self.metadata)
bind_info_to_entry.__doc__ = CfgInfo.bind_info_to_entry.__doc__
def handle_event(self, event):
if event.code2str() == 'deleted':
return
for line in open(self.path).readlines():
match = Bcfg2.Server.Plugin.INFO_REGEX.match(line)
if not match:
LOGGER.warning("Failed to parse line in %s: %s" %
(event.filename, line))
continue
else:
self.metadata = \
dict([(key, value)
for key, value in list(match.groupdict().items())
if value])
if ('mode' in self.metadata and
len(self.metadata['mode']) == 3):
self.metadata['mode'] = "0%s" % self.metadata['mode']
handle_event.__doc__ = CfgInfo.handle_event.__doc__
|