Save sites.json every 10 minute
This commit is contained in:
parent
55d76c8c5c
commit
cd52a61c4c
1 changed files with 20 additions and 2 deletions
|
@ -4,15 +4,18 @@ import re
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import gevent
|
||||||
|
|
||||||
from Plugin import PluginManager
|
from Plugin import PluginManager
|
||||||
from Config import config
|
from Config import config
|
||||||
from util import helper
|
from util import helper
|
||||||
|
|
||||||
|
|
||||||
@PluginManager.acceptPlugins
|
@PluginManager.acceptPlugins
|
||||||
class SiteManager(object):
|
class SiteManager(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.sites = None
|
self.sites = None
|
||||||
|
gevent.spawn(self.saveTimer)
|
||||||
|
|
||||||
# Load all sites from data/sites.json
|
# Load all sites from data/sites.json
|
||||||
def load(self):
|
def load(self):
|
||||||
|
@ -39,6 +42,21 @@ class SiteManager(object):
|
||||||
if added:
|
if added:
|
||||||
logging.debug("SiteManager added %s sites" % added)
|
logging.debug("SiteManager added %s sites" % added)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
if not self.sites:
|
||||||
|
logging.error("Save error: No sites found")
|
||||||
|
s = time.time()
|
||||||
|
data = json.load(open("%s/sites.json" % config.data_dir))
|
||||||
|
for address, site in self.list().iteritems():
|
||||||
|
data[address] = site.settings
|
||||||
|
helper.atomicWrite("%s/sites.json" % config.data_dir, json.dumps(data, indent=2, sort_keys=True))
|
||||||
|
logging.debug("Saved sites in %.2fs" % (time.time() - s))
|
||||||
|
|
||||||
|
def saveTimer(self):
|
||||||
|
while 1:
|
||||||
|
time.sleep(60 * 10)
|
||||||
|
self.save()
|
||||||
|
|
||||||
# Checks if its a valid address
|
# Checks if its a valid address
|
||||||
def isAddress(self, address):
|
def isAddress(self, address):
|
||||||
return re.match("^[A-Za-z0-9]{26,35}$", address)
|
return re.match("^[A-Za-z0-9]{26,35}$", address)
|
||||||
|
|
Loading…
Reference in a new issue