summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/FileMonitor/Pseudo.py
blob: 24cd099d0a6db16c4e82345921d513653994e0a9 (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
""" Pseudo provides static monitor support for file alteration events.
That is, it only produces "exists" and "endExist" events and does not
monitor for ongoing changes. """

import os
from Bcfg2.Server.FileMonitor import FileMonitor, Event


class Pseudo(FileMonitor):
    """ File monitor that only produces events on server startup and
    doesn't actually monitor for ongoing changes at all. """

    #: The ``Pseudo`` monitor should only be used if no other FAM
    #: backends are available.
    __priority__ = 1

    def AddMonitor(self, path, obj, handleID=None):
        if handleID is None:
            handleID = len(list(self.handles.keys()))
        self.events.append(Event(handleID, path, 'exists'))
        if os.path.isdir(path):
            dirlist = os.listdir(path)
            for fname in dirlist:
                self.events.append(Event(handleID, fname, 'exists'))
            self.events.append(Event(handleID, path, 'endExist'))

        if obj != None:
            self.handles[handleID] = obj
        return handleID