diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-10-30 11:35:46 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-01-17 10:44:14 -0500 |
commit | 45c7bbf24ae3c6530f33ebb33c062818ad44816d (patch) | |
tree | d39fbacaae2d712fdf250a9bce19f9737392539e /src/lib/Bcfg2/Server/FileMonitor | |
parent | a6b269011b2f1e84c650239065e56778591f087e (diff) | |
download | bcfg2-45c7bbf24ae3c6530f33ebb33c062818ad44816d.tar.gz bcfg2-45c7bbf24ae3c6530f33ebb33c062818ad44816d.tar.bz2 bcfg2-45c7bbf24ae3c6530f33ebb33c062818ad44816d.zip |
added a module-level FAM object to avoid passing it as an argument a billion times
Diffstat (limited to 'src/lib/Bcfg2/Server/FileMonitor')
-rw-r--r-- | src/lib/Bcfg2/Server/FileMonitor/__init__.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lib/Bcfg2/Server/FileMonitor/__init__.py b/src/lib/Bcfg2/Server/FileMonitor/__init__.py index a1ff655d0..37a2a8763 100644 --- a/src/lib/Bcfg2/Server/FileMonitor/__init__.py +++ b/src/lib/Bcfg2/Server/FileMonitor/__init__.py @@ -311,6 +311,31 @@ class FileMonitor(Debuggable): raise NotImplementedError +#: A module-level FAM object that all plugins, etc., can use. This +#: should not be used directly, but retrieved via :func:`get_fam`. +_FAM = None + +def get_fam(filemonitor='default', ignore=None, debug=False): + """ Get a filemonitor object. If :attr:`_FAM` already exists, + that will be used; if not, a new filemonitor object will be + created. + + :param filemonitor: Which filemonitor backend to use + :type filemonitor: string + :param ignore: A list of filenames to ignore + :type ignore: list of strings (filename globs) + :param debug: Produce debugging information + :type debug: bool + :returns: :class:`Bcfg2.Server.FileMonitor.FileMonitor` + """ + global _FAM # pylint: disable=W0603 + if _FAM is None: + if ignore is None: + ignore = [] + _FAM = available[filemonitor](ignore=ignore, debug=debug) + return _FAM + + #: A dict of all available FAM backends. Keys are the human-readable #: names of the backends, which are used in bcfg2.conf to select a #: backend; values are the backend classes. In addition, the |