summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/FileMonitor/Pseudo.py
blob: 089d4cf0f6ba1261b77b213a93c4f4cd1cddda73 (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
""" Pseudo provides static monitor support for file alteration events """

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

logger = logging.getLogger(__name__)

class Pseudo(FileMonitor):
    __priority__ = 99

    def AddMonitor(self, path, obj, handleID=None):
        """add a monitor to path, installing a callback to obj.HandleEvent"""
        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 includedFile in dirList:
                self.events.append(Event(handleID, includedFile, 'exists'))
            self.events.append(Event(handleID, path, 'endExist'))

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