diff --git a/mutalyzer/Db.py b/mutalyzer/Db.py index ea559584fe778a3c5d2298a25f32cfa8df74a5dd..bb57f851820c86a688c0a3c97a1fb6da52509a52 100644 --- a/mutalyzer/Db.py +++ b/mutalyzer/Db.py @@ -1050,8 +1050,8 @@ class Cache(Db) : @rtype: string """ statement = """ - SELECT - (AccNo, GI, hash, ChrAccVer, ChrStart, ChrStop, orientation, url, created) + SELECT AccNo, GI, hash, ChrAccVer, ChrStart, + ChrStop, orientation, url, created FROM GBInfo WHERE created >= %s; """, created_since diff --git a/mutalyzer/config.py b/mutalyzer/config.py index 363d0a88c83ce3b109030308f80b8bff1c5c6946..0314500a0df0ffd6796eee9e664b00a41215180c 100644 --- a/mutalyzer/config.py +++ b/mutalyzer/config.py @@ -134,6 +134,9 @@ class Config(): self.GenRecord.spliceAlarm = int(config["spliceAlarm"]) self.GenRecord.spliceWarn = int(config["spliceWarn"]) + # Set the variables needed by the sync module. + self.Sync.cache = config["cache"] + # If we are in a testing environment, use a temporary file for # logging and a temporary directory for the cache. # We don't remove these after the tests, since they might be diff --git a/mutalyzer/models.py b/mutalyzer/models.py index d8b00138d68c16f7c8883bd8a7d8117a3cf5ebaa..c9e32322f9e3789bbd39aede86edc00284b22207 100644 --- a/mutalyzer/models.py +++ b/mutalyzer/models.py @@ -233,4 +233,5 @@ class CacheEntry(ClassModel): chromosomeOrientation = Integer url = String created = Mandatory.DateTime + cached = Mandatory.Boolean #CacheEntry diff --git a/mutalyzer/sync.py b/mutalyzer/sync.py index 1f4a8231a56d0e97b565c151b2a72f9a04c5219e..d5c7a6b79628be0b29d18a166b157329e6c01c8f 100644 --- a/mutalyzer/sync.py +++ b/mutalyzer/sync.py @@ -4,8 +4,10 @@ Module for synchronizing the database with other Mutalyzer instances. from mutalyzer.util import monkey_patch_suds; monkey_patch_suds() -from suds.client import Client + +import os from datetime import datetime, timedelta +from suds.client import Client DEFAULT_CREATED_SINCE_DAYS = 7 @@ -29,7 +31,19 @@ class CacheSync(object): if not created_since: created_since = datetime.today() - \ timedelta(days=DEFAULT_CREATED_SINCE_DAYS) - return self._database.getGB(created_since) + cache = self._database.getGB(created_since) + + entries = [] + + # For each entry, check if it is cached on our filesystem. + # Todo: refactor + for entry in cache: + file_path = os.path.join(self._config.cache, '%s.bz2' % entry[0]) + e = list(entry) + e.append(os.path.isfile(file_path)) + entries.append(e) + + return entries def remote_cache(self, remote_wsdl, created_since=None): """ @@ -47,7 +61,8 @@ class CacheSync(object): """ entry_dict = {'name': entry.name, 'hash': entry.hash, - 'created': entry.created} + 'created': entry.created, + 'cached': bool(entry.cached)} for attribute in ('gi', 'chromosomeName', 'chromosomeStart' 'chromosomeStop', 'chromosomeOrientation', 'url'): @@ -57,7 +72,7 @@ class CacheSync(object): return map(cache_entry_from_soap, cache.CacheEntry) - def sync_with_remote(self, remote_wsdl, created_since=None): + def sync_with_remote(self, remote_wsdl, remote_cache, created_since=None): """ Todo. """ @@ -74,7 +89,10 @@ class CacheSync(object): # entry['chromosomeStop'], # entry['chromosomeOrientation'], # entry['url']) - print 'inserting %s' % entry['name'] - print entry + #print 'inserting %s' % entry['name'] + #print entry if not entry['chromosomeName'] and not entry['url']: - print '(downloading file from remote cache...)' + if entry['cached']: + print 'downloading file from remote cache: %s' % (remote_cache % entry['name']) + #else: + #print 'cannot download this file from remote cache' diff --git a/mutalyzer/webservice.py b/mutalyzer/webservice.py index f6401e1dab7a23df2b24d206eb3303f922ef99f0..cd480fda8dadbc43a929b7bc3a0d6d723444c310 100644 --- a/mutalyzer/webservice.py +++ b/mutalyzer/webservice.py @@ -907,7 +907,8 @@ class MutalyzerService(DefinitionBase): e.chromosomeStop, e.chromosomeOrientation, e.url, - e.created) = entry + e.created, + e.cached) = entry return e output.addMessage(__file__, -1, 'INFO',