X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=monitor%2Fdatabase%2Fdbpickle.py;h=074ff68e2db943c222db0f5463e7e0d5ed0210a7;hb=d8c4f261680cbc9cb2708cf12d97202716120dc7;hp=e127791393a5a3a386552ae53075dfe108ee5c78;hpb=62928a9776311c5e1a64981851b855027b1f988e;p=monitor.git diff --git a/monitor/database/dbpickle.py b/monitor/database/dbpickle.py index e127791..074ff68 100644 --- a/monitor/database/dbpickle.py +++ b/monitor/database/dbpickle.py @@ -1,6 +1,11 @@ import os import sys import pickle +import inspect +import shutil +import time +from monitor import config + noserial=False try: from util.PHPSerialize import * @@ -9,14 +14,34 @@ except: #print >>sys.stderr, "PHPSerial db type not allowed." noserial=True -import inspect -import shutil -import config -import config as monitorconfig - DEBUG= 0 PICKLE_PATH=config.MONITOR_DATA_ROOT +def lastModified(name, type=None): + # TODO: fix for 'debug' mode also. + t = SPickle().mtime("production.%s" % name, type) + return t + +def cachedRecently(name, length=int(config.cachetime), type=None): + """ + return true or false based on whether the modified time of the cached + file is within 'length' minutes. + """ + if hasattr(config, 'cachecalls') and not config.cachecalls: + # don't use cached calls if cachecalls is false + return False + + try: + t = lastModified(name, type) + except: + # file doesn't exist or we can't access it. + return False + + current_time = time.time() + if current_time > t + length*60: + return False + else: + return True def dbLoad(name, type=None): return SPickle().load(name, type) @@ -74,6 +99,10 @@ class SPickle: raise Exception("No PHPSerializer module available") return "%s/%s.phpserial" % (self.path, name) + + def mtime(self, name, type=None): + f = os.stat(self.__file(name, type)) + return f[-2] def exists(self, name, type=None): return os.path.exists(self.__file(name, type))