class Watcher(object): def __init__(self, logger): os.chdir("../") self.programPath = os.getcwd() os.chdir("app") self.__fs = FileSystem(".") self.__utils = Utils() self.__config = Config(fileSystem=self.__fs) self.__db = None self.__controller = None self.__feeder = None self.__webServer = None self.__logger = logger self.__configWatcher = None self.__stompClient = None dbName = self.__config.watcher.get("db", "sqlite") sys.path.insert(0, "../db/%s" % dbName) Database = __import__(dbName).Database dbFileName = self.__config.watcher.get("dbFile", "queue.db") print "Starting file watcher..." #------------------------ self.__db = Database(dbFileName) self.__controller = Controller(self.__db, self.__fs, self.__config, \ FileWatcher, WatchDirectory, update=False) #self.__controller.configChanged(config) #self.__config.addReloadWatcher(self.__controller.configChanged) if self.__config.messaging.enabled: self.__stompClient = StompClient(self.__config, self.__utils) def stompListener(file, eventTime, eventName, isDir): if not isDir: try: self.__stompClient.queueUpdate(file, eventName) except Exception, e: msg = "ERROR in stompClient.queueUpdate('%s', '%s) - '%s'" print msg % (file, eventName, str(e)) self.__controller.addListener(stompListener) ## Log events def logCallback(file, eventTime, eventName, isDir): tStr = time.strftime("%Y%m%dT%H:%M:%S", time.localtime(eventTime)) print "%s \t%s \t%s \t%s" % (tStr, eventName, isDir, file) self.__controller.addListener(logCallback) ## self.__configWatcher = FileWatcher(self.__config.configFile, self.__fs) self.__configWatcher.startWatching() def configChanged(file, eventName, **kwargs): #file=path, eventTime=eventTime, eventName=eventName, isDir=isDir, walk=False if eventName!="del" and file==self.__config.configFile: print "configChanged - reloading" self.__config.reload() self.__controller.configChanged(self.__config) self.__configWatcher.addListener(configChanged) self.__feeder = Feeder(self.__utils, self.__controller) feedservice = self.__config.watcher.get("feedservice", {}) self.host = feedservice.get("host", "*") self.port = feedservice.get("port", 9000) s = webServe(self.host, self.port, self.__feeder) self.__webServer = s
def __init__(self, logger): os.chdir("../") self.programPath = os.getcwd() os.chdir("app") self.__fs = FileSystem(".") self.__utils = Utils() self.__config = Config(fileSystem=self.__fs) self.__db = None self.__controller = None self.__feeder = None self.__webServer = None self.__logger = logger self.__configWatcher = None self.__stompClient = None dbName = self.__config.watcher.get("db", "sqlite") sys.path.insert(0, "../db/%s" % dbName) Database = __import__(dbName).Database dbFileName = self.__config.watcher.get("dbFile", "queue.db") print "Starting file watcher..." #------------------------ self.__db = Database(dbFileName) self.__controller = Controller(self.__db, self.__fs, self.__config, \ FileWatcher, WatchDirectory, update=False) #self.__controller.configChanged(config) #self.__config.addReloadWatcher(self.__controller.configChanged) if self.__config.messaging.enabled: self.__stompClient = StompClient(self.__config, self.__utils) def stompListener(file, eventTime, eventName, isDir): if not isDir: try: self.__stompClient.queueUpdate(file, eventName) except Exception, e: msg = "ERROR in stompClient.queueUpdate('%s', '%s) - '%s'" print msg % (file, eventName, str(e)) self.__controller.addListener(stompListener)