示例#1
0
    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
        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)
        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", "localhost")
        self.port = feedservice.get("port", 9000)
        s = webServe(self.host, self.port, self.__feeder)
        self.__webServer = s
示例#2
0
        else:
            time.sleep(1)
            while True:
                time.sleep(1)
                #print "tic"
                if not watcher.isServing:
                    break
        watcher.close()
    else:
        # Testing
        print "--TESTING--"
        class Feeder(object):
            def formatDateTime(self, utc=False):
                return "DateTime utc='%s'" % utc
        feeder = Feeder()
        s = webServe("localhost", 9000, feeder)
        time.sleep(1)
        while True:
            time.sleep(1)
            if s.isServing:
                print "isServing..."
            else:
                print "stopped serving"
                break

    print "--DONE--"
    try:
        sys.exit(0)
    except Exception, e:
        print "-- %s" % str(e)