diff --git a/extras/post-install.sh b/extras/post-install.sh index 123f3850dbadcd196c469c55da3844d0126326a9..b24e2c8b284f89323f63012a8f4445886053c101 100644 --- a/extras/post-install.sh +++ b/extras/post-install.sh @@ -303,9 +303,11 @@ CREATE TABLE GBInfo ( ChrStop int(12) DEFAULT NULL, orientation int(2) DEFAULT NULL, url char(255) DEFAULT NULL, + created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (AccNo), UNIQUE KEY hash (hash), - UNIQUE KEY alias (GI) + UNIQUE KEY alias (GI), + INDEX (created) ); CREATE TABLE Link ( mrnaAcc char(20) NOT NULL, diff --git a/extras/soap-tools/getcache.py b/extras/soap-tools/getcache.py index 9e44d31f2bce2303f1517379892236ea96d5e700..fc8cd298a01462f43764ef0886519703ff964cea 100755 --- a/extras/soap-tools/getcache.py +++ b/extras/soap-tools/getcache.py @@ -13,6 +13,7 @@ def _import_open_patched(self, *args, **kwargs): Import.open = _import_open_patched import sys +from datetime import datetime, timedelta from suds.client import Client URL = 'http://localhost/mutalyzer/services/?wsdl' @@ -20,9 +21,15 @@ URL = 'http://localhost/mutalyzer/services/?wsdl' c = Client(URL, cache=None) o = c.service +days = 1 +if len(sys.argv) > 1: + days = int(sys.argv[1]) + +created_since = datetime.today() - timedelta(minutes=days) + print 'Getting cache...' -cache = o.getCache() +cache = o.getCache(created_since) if cache: for r in cache.CacheEntry: @@ -40,4 +47,5 @@ if cache: print r.chromosomeOrientation if 'url' in r: print r.url + print r.created print diff --git a/mutalyzer/Db.py b/mutalyzer/Db.py index 8bc326e99f71c3d320cc18723e628137f9234369..ce7b8e32bcd3a2b729057ecadf1e93b6a05ae9c0 100644 --- a/mutalyzer/Db.py +++ b/mutalyzer/Db.py @@ -1033,20 +1033,25 @@ class Cache(Db) : return None #getGBFromGI - def getGB(self): + def getGB(self, created_since): """ - Get all accession numbers from the cache. + Get all accession number entries starting with creation date + {created_since}. SQL tables from internalDb: - GBInfo ; Information about cached and uploaded GenBank files. + @arg created_since: Only entries with later creation dates are returned. + @type created_since: datatime.datetime + @return: The accession number @rtype: string """ statement = """ SELECT * - FROM GBInfo; - """, None + FROM GBInfo + WHERE created >= %s; + """, created_since return self.query(statement) #getGB diff --git a/mutalyzer/models.py b/mutalyzer/models.py index c6fba15c58b5573ae1d29ba5ab61a8494b27c9b1..d8b00138d68c16f7c8883bd8a7d8117a3cf5ebaa 100644 --- a/mutalyzer/models.py +++ b/mutalyzer/models.py @@ -17,7 +17,7 @@ Additional attributes values for the soaplib String model: """ -from soaplib.core.model.primitive import String, Integer, Boolean +from soaplib.core.model.primitive import String, Integer, Boolean, DateTime from soaplib.core.model.clazz import ClassModel, Array from mutalyzer import SOAP_NAMESPACE @@ -31,6 +31,7 @@ class Mandatory(object): String = String(min_occurs=1, nillable=False) Integer = Integer(min_occurs=1, nillable=False) Boolean = Boolean(min_occurs=1, nillable=False) + DateTime = DateTime(min_occurs=1, nillable=False) #Mandatory @@ -231,4 +232,5 @@ class CacheEntry(ClassModel): chromosomeStop = Integer chromosomeOrientation = Integer url = String + created = Mandatory.DateTime #CacheEntry diff --git a/mutalyzer/sync.py b/mutalyzer/sync.py index 2ece6e610c09f0bbb2fd93e1358583a7accf6079..b99cf11685b8c9b2b7a688abd69a57ee8de5d54e 100644 --- a/mutalyzer/sync.py +++ b/mutalyzer/sync.py @@ -3,6 +3,9 @@ Module for synchronizing the database with other Mutalyzer instances. """ +from datetime import datetime, timedelta + + class CacheSync(object): """ Todo. @@ -14,8 +17,10 @@ class CacheSync(object): self._config = config self._database = database - def local_cache(self): + def local_cache(self, created_since=None): """ Todo. """ - return self._database.getGB() + if not created_since: + created_since = datetime.today() - timedelta(days=7) + return self._database.getGB(created_since) diff --git a/mutalyzer/webservice.py b/mutalyzer/webservice.py index 6798ba02141d8c5ee790e49149515273a364dad0..720ba44507a3745277b1f27ff95f938014d869b1 100644 --- a/mutalyzer/webservice.py +++ b/mutalyzer/webservice.py @@ -23,7 +23,7 @@ import logging; logging.basicConfig() from soaplib.core import Application from soaplib.core.service import soap from soaplib.core.service import DefinitionBase -from soaplib.core.model.primitive import String, Integer +from soaplib.core.model.primitive import String, Integer, DateTime from soaplib.core.model.clazz import Array from soaplib.core.model.exception import Fault from soaplib.core.server import wsgi @@ -882,8 +882,8 @@ class MutalyzerService(DefinitionBase): return result #info - @soap(_returns = Array(CacheEntry)) - def getCache(self): + @soap(DateTime, _returns = Array(CacheEntry)) + def getCache(self, created_since=None): """ Todo: documentation. """ @@ -895,7 +895,7 @@ class MutalyzerService(DefinitionBase): database = Db.Cache(self._config.Db) sync = CacheSync(self._config.Sync, database) - cache = sync.local_cache() + cache = sync.local_cache(created_since) def soap_cache_entry(entry): e = CacheEntry() @@ -907,6 +907,7 @@ class MutalyzerService(DefinitionBase): e.chromosomeStop = entry[5] e.chromosomeOrientation = entry[6] e.url = entry[7] + e.created = entry[8] return e output.addMessage(__file__, -1, 'INFO',