Пример #1
0
 def tick(self):
     if time.time() - self.lasttick > 60 * 1:
         self.lasttick = time.time()
         #Determine if the database exists
         with self.db:
             self.dbexists = self.db.con.execute(
                     "PRAGMA table_info(games)").fetchone(
                         ) is not None
             if self.dbexists:
                 self.dbexists = self.db.con.execute(
                     "SELECT id FROM games ORDER BY id DESC").fetchone(
                         ) is not None
         if self.dbexists:
             #Get a list of weapons from the last played game
             with self.db:
                 lastgame = self.db.con.execute(
                 "SELECT id FROM games ORDER BY id DESC").fetchone()[0]
                 dbselectors.weaponlist = [
                 r[0] for r in self.db.con.execute(
                 "SELECT weapon FROM game_weapons WHERE game = %d" % (
                     lastgame))]
         #Create a backup, remove old backups
         backupfile = (homedir +
         "/statsdbbackups/" +
         time.strftime("%Y%m%d") + '.sqlite.bak')
         if not os.path.exists(backupfile):
             self.db.backup(backupfile)
             print("Creating backup.")
         db.flushdir(homedir + "/statsdbbackups",
             60 * 60 * 24 * cfgval("backupkeepdays"))
Пример #2
0
 def tick(self):
     #Calculate caches
     with self.db:
         for c in caches.classes:
             c[0].calcall()
     #Clear old cached pages
     todel = []
     for k, v in list(self.retcache.items()):
         dt = 5
         if v[1][0] in ['text/html', 'text/json']:
             dt = 1
         if time.time() - v[0] >= 60 * dt:
             todel.append(k)
     for k in todel:
         del self.retcache[k]
     if time.time() - self.lasttick >= 60 * 1:
         self.lasttick = time.time()
         #Determine if the database exists
         with self.db:
             self.dbexists = self.db.con.execute(
                     "PRAGMA table_info(games)").fetchone(
                         ) is not None
             if self.dbexists:
                 self.dbexists = self.db.con.execute(
                     "SELECT id FROM games ORDER BY id DESC").fetchone(
                         ) is not None
         #Create a backup, remove old backups
         backupfile = (homedir +
         "/statsdbbackups/" +
         time.strftime("%Y%m%d") + '.sqlite.bak')
         if not os.path.exists(backupfile):
             self.db.backup(backupfile)
             print("Creating backup.")
         db.flushdir(homedir + "/statsdbbackups",
             60 * 60 * 24 * cfgval("backupkeepdays"))