From 1077428858e262780665452df1aef2d9429d0578 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org>
Date: Mon, 12 Aug 2019 08:37:55 +0200
Subject: [PATCH] MAINT: do first all the matches and then identifiables

---
 src/caosadvancedtools/cfood.py   | 15 +++++++++++++++
 src/caosadvancedtools/crawler.py |  5 +++++
 2 files changed, 20 insertions(+)

diff --git a/src/caosadvancedtools/cfood.py b/src/caosadvancedtools/cfood.py
index a6e44294..324a6769 100644
--- a/src/caosadvancedtools/cfood.py
+++ b/src/caosadvancedtools/cfood.py
@@ -78,6 +78,7 @@ class AbstractCFood(object):
         self.to_be_updated = db.Container()
         self.identifiables = db.Container()
         self.verbose = verbose
+        self.attached_ones = []
 
     @staticmethod
     def get_re():
@@ -127,8 +128,19 @@ class AbstractCFood(object):
         if len(self.to_be_updated) == 0:
             return
         get_ids_for_entities_with_names(self.to_be_updated)
+        print(self.to_be_updated)
         self.to_be_updated.update()
 
+    def attach(self, crawled_file):
+        self.attached_ones.append(crawled_file)
+
+    def looking_for(self, crawled_file):
+        """
+        should set the instance variable Container with the identifiables
+        """
+
+        return False
+
     @staticmethod
     # move to api?
     def set_parents(entity, names):
@@ -179,6 +191,9 @@ def assure_object_is_in_list(obj, containing_object, property_name,
         containing_object.add_property(property_name, value=[],
                                        datatype=db.LIST(property_name))
     current_list = containing_object.get_property(property_name).value
+
+    if not isinstance(current_list, list):
+        current_list = [current_list]
     contained = False
 
     for el in current_list:
diff --git a/src/caosadvancedtools/crawler.py b/src/caosadvancedtools/crawler.py
index 74c13732..2cc85ec7 100644
--- a/src/caosadvancedtools/crawler.py
+++ b/src/caosadvancedtools/crawler.py
@@ -106,6 +106,11 @@ class Crawler(object):
             if self.verbose and matches > 1:
                 print("Attention: More than one matching cfood!")
 
+        for crawled_file in sorted(files, key=lambda x: x.path):
+            for cfood in cfoods:
+                if cfood.looking_for(crawled_file):
+                    cfood.attach(crawled_file)
+
         for cfood in cfoods:
             try:
                 cfood.create_identifiables()
-- 
GitLab