From da00d86da5864a1397ed83381eb0984cf4052a5b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org>
Date: Mon, 5 Aug 2019 10:11:28 +0200
Subject: [PATCH] ENH: cfoods should use self.to_be_updated

---
 src/caosadvancedtools/cfood.py   | 11 +++++++++++
 src/caosadvancedtools/crawler.py |  1 +
 2 files changed, 12 insertions(+)

diff --git a/src/caosadvancedtools/cfood.py b/src/caosadvancedtools/cfood.py
index 32703b65..c6800902 100644
--- a/src/caosadvancedtools/cfood.py
+++ b/src/caosadvancedtools/cfood.py
@@ -81,6 +81,7 @@ class AbstractCFood(object):
         self.crawled_file = crawled_file
         self.crawled_path = crawled_file.path
         self.match = type(self).match(crawled_file.path)
+        self.to_be_updated = db.Container()
 
     @staticmethod
     def get_re():
@@ -113,8 +114,18 @@ class AbstractCFood(object):
         raise NotImplementedError()
 
     def update_identifiables(self):
+        """ Changes the identifiables as needed and adds changed identifiables
+        to self.to_be_updated
+        """
         raise NotImplementedError()
 
+    def push_identifiables_to_CaosDB(self):
+        """ Updates the self.to_be_updated Container, i.e. pushes the changes
+        to CaosDB
+        """
+        get_ids_for_entities_with_names(self.to_be_updated)
+        self.to_be_updated.update()
+
     @staticmethod
     # move to api?
     def set_parents(entity, names):
diff --git a/src/caosadvancedtools/crawler.py b/src/caosadvancedtools/crawler.py
index 2fe94484..24c974b9 100644
--- a/src/caosadvancedtools/crawler.py
+++ b/src/caosadvancedtools/crawler.py
@@ -90,6 +90,7 @@ class Crawler(object):
                             self.cache.insert_list(hashes, identifiables)
 
                         cfood.update_identifiables()
+                        cfood.push_identifiables_to_CaosDB()
                     except Exception as e:
                         print(e)
 
-- 
GitLab