From 5ca4d216a762b827b7a7d85fe42235fce4185a03 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Sat, 4 Oct 2014 11:50:53 +0200
Subject: [PATCH] Fix sync of local cache with remote cache

---
 mutalyzer/entrypoints/admin.py |  6 +++++-
 mutalyzer/sync.py              | 11 +++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/mutalyzer/entrypoints/admin.py b/mutalyzer/entrypoints/admin.py
index 07ee52e8..42929e6b 100644
--- a/mutalyzer/entrypoints/admin.py
+++ b/mutalyzer/entrypoints/admin.py
@@ -136,7 +136,11 @@ def sync_cache(wsdl_url, url_template, history=7):
         55 5 * * *  mutalyzer-cache-sync 'http://dom2/?wsdl' 'http://dom2/{file}' -H 7
     """
     cache_sync = sync.CacheSync(output.Output(__file__))
-    cache_sync.sync_with_remote(wsdl_url, url_template, history)
+    inserted, downloaded = cache_sync.sync_with_remote(wsdl_url, url_template,
+                                                       history)
+
+    print ('Added %d entries to the local cache and downloaded %d cache files.'
+           % (inserted, downloaded))
 
 
 def set_announcement(body, url=None):
diff --git a/mutalyzer/sync.py b/mutalyzer/sync.py
index 4c278e81..e5465e1e 100644
--- a/mutalyzer/sync.py
+++ b/mutalyzer/sync.py
@@ -107,16 +107,21 @@ class CacheSync(object):
             """
             Create a nice dictionary out of the CacheEntry object.
             """
+            cast_orientation = {None: None,
+                                1: 'forward',
+                                2: 'reverse'}
+
             entry_dict =  {'name':    str(entry.name),
                            'hash':    str(entry.hash),
                            'created': entry.created}
             for attribute in ('gi', 'chromosomeName', 'url', 'cached'):
                 entry_dict[attribute] = str(entry[attribute]) \
                                         if attribute in entry else None
-            for attribute in ('chromosomeStart', 'chromosomeStop',
-                              'chromosomeOrientation'):
+            for attribute in ('chromosomeStart', 'chromosomeStop'):
                 entry_dict[attribute] = int(entry[attribute]) \
                                         if attribute in entry else None
+            entry_dict['chromosomeOrientation'] = cast_orientation[entry['chromosomeOrientation']] \
+                                                  if 'chromosomeOrientation' in entry else None
             return entry_dict
 
         return map(cache_entry_from_soap, cache.CacheEntry)
@@ -195,6 +200,8 @@ class CacheSync(object):
                                   slice_stop=entry['chromosomeStop'],
                                   slice_orientation=entry['chromosomeOrientation'],
                                   download_url=entry['url'])
+            session.add(reference)
+            session.commit()
             inserted += 1
             if not entry['chromosomeName'] and not entry['url'] \
                    and entry['cached']:
-- 
GitLab