Ejemplo n.º 1
0
 def rogerHost(self, host):
     '''the parameter should be a dic contains items:'''
     with HostScheduler.mutex:
         sql_checkExists = "SELECT name FROM Host WHERE MAC='%s'"
         sql_rogerHost = "INSERT OR REPLACE INTO Host (name, ip_local, ip_remote, mac, type, status) " \
                         "VALUES ('%s','%s','%s','%s','%s','OK')"
         data = None
         db = DbUtil()
         exists = db.execute(sql_checkExists % host['MAC'])
         if len(exists) == 0:
             data = db.execute(sql_rogerHost %
                     (host['HostName'], host['IPLocal'], host['IPRemote'], host['MAC'], host['NodeType']))
         return data
Ejemplo n.º 2
0
 def fetchTodoTask(self, TaskMode = 'default', mark='doing', number=-1):
     data = None
     with TaskScheduler.mutex:
         sql_fetch1 = "SELECT id,rogerTime FROM task_%s WHERE status='todo' order by rogerTime ASC, id ASC LIMIT %d"
         sql_fetch2 = "UPDATE task_%s SET status='%s' WHERE id=?"
         db = DbUtil()
         data = db.execute(sql_fetch1 % (TaskMode, TaskScheduler.taskPerTime if number<0 else number))
         if len(data) > 0:
             ids = [(id,) for (id,rogerTime) in data]
             db.executeMany(sql_fetch2 % (TaskMode , mark) , ids)
         return data
Ejemplo n.º 3
0
    def ensureTaskMode(self, TaskMode = 'default'):
        with TaskScheduler.mutex:
            sql_checkTaskTables = "SELECT name FROM sqlite_master WHERE type='table' and name = 'Task_%s'"
            sql_task = '''DROP TABLE IF EXISTS "Task_%s";
                CREATE TABLE "Task_%s" (
                    "id"           INTEGER NOT NULL,
                    "rogerTime"     TIMESTAMP NOT NULL DEFAULT (datetime(CURRENT_TIMESTAMP, 'localtime')),
                    "finishTime"    TIMESTAMP DEFAULT NULL,
                    "status"        TEXT DEFAULT 'todo',
                    PRIMARY KEY ("id" ASC) ON CONFLICT FAIL
                );'''

            db = DbUtil()
            exists = len( db.execute(sql_checkTaskTables % TaskMode) ) > 0
            if not exists:
                db.executeScript(sql_task % (TaskMode,TaskMode))
            return  1 if exists else 0