From ec13ec8f3ae554c2a354eb573f06bb7a056616e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org>
Date: Tue, 5 Feb 2019 13:38:59 +0100
Subject: [PATCH] update

---
 src/caosadvancedtools/cfood.py     | 28 +++++---------------
 src/caosadvancedtools/crawler.py   | 42 +++++++++++++++++-------------
 src/caosadvancedtools/loadFiles.py |  1 +
 3 files changed, 31 insertions(+), 40 deletions(-)

diff --git a/src/caosadvancedtools/cfood.py b/src/caosadvancedtools/cfood.py
index eca51a16..94fd3892 100644
--- a/src/caosadvancedtools/cfood.py
+++ b/src/caosadvancedtools/cfood.py
@@ -31,15 +31,15 @@ from datetime import datetime
 import caosdb as db
 from caosdb.exceptions import TransactionError
 
-from something import get_entity
+#from something import get_entity
 
 
 class AbstractCFood(object):
     def __init__(self, pattern):
         self.pattern = re.compile(pattern)
 
-    def treat_match(self, filename, match):
-        entities = self.create_identifiables(filename, match)
+    def treat_match(self, crawled_file, match):
+        entities = self.create_identifiables(crawled_file, match)
 
         for key, ent in entities.items():
             existing = AbstractCFood.find_existing(ent)
@@ -53,12 +53,12 @@ class AbstractCFood(object):
                 print(key, "exists")
                 entities[key] = existing
 
-        self.update_identifiables(entities, filename, match)
+        self.update_identifiables(entities, crawled_file, match)
 
-    def create_identifiables(self, filename, match):
+    def create_identifiables(self, crawled_file, match):
         raise NotImplementedError()
 
-    def update_identifiables(self, entities, filename, match):
+    def update_identifiables(self, entities, crawled_file, match):
         raise NotImplementedError()
 
     @staticmethod
@@ -92,22 +92,6 @@ class AbstractCFood(object):
         return r
 
 
-class ExampleCFood(AbstractCFood):
-    def create_identifiables(self, filename, match):
-        entities = {}
-        entities["exp"] = db.Record()
-        #import IPython
-        # IPython.embed()
-        entities["exp"].add_parent(name="Experiment")
-        entities["exp"].add_property(name="species", value=match.group)
-
-        return entities
-
-    def update_identifiables(self, entities, filename, match):
-        entities["exp"].add_property(name="date",
-                                     value=datetime.today().isoformat())
-        db.Container().extend(entities.values).update()
-
 
 def get_parser():
     parser = argparse.ArgumentParser(description=__doc__,
diff --git a/src/caosadvancedtools/crawler.py b/src/caosadvancedtools/crawler.py
index 24374607..51f07367 100644
--- a/src/caosadvancedtools/crawler.py
+++ b/src/caosadvancedtools/crawler.py
@@ -1,5 +1,27 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
+#!/usr/bin/env python
+# encoding: utf-8
+#
+# ** header v3.0
+# This file is a part of the CaosDB Project.
+#
+# Copyright (C) 2018 Research Group Biomedical Physics,
+# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+# ** end header
+#
 """does something"""
 
 import argparse
@@ -7,8 +29,6 @@ from argparse import RawTextHelpFormatter
 
 import caosdb as db
 
-from cfood import CFood
-
 
 class Crawler(object):
     def __init__(self, food):
@@ -31,17 +51,3 @@ class Crawler(object):
                     cfood.treat_match(crawled_file.path, match)
 
 
-def get_parser():
-    parser = argparse.ArgumentParser(description=__doc__,
-                                     formatter_class=RawTextHelpFormatter)
-
-    return parser
-
-
-if __name__ == "__main__":
-    parser = get_parser()
-    args = parser.parse_args()
-
-    f = CFood(pattern="(.*)to(.*)")
-    c = Crawler(food=[f])
-    c.crawl(["path/to/file"])
diff --git a/src/caosadvancedtools/loadFiles.py b/src/caosadvancedtools/loadFiles.py
index 953cfc45..9ebf8b9f 100755
--- a/src/caosadvancedtools/loadFiles.py
+++ b/src/caosadvancedtools/loadFiles.py
@@ -26,6 +26,7 @@
 import math
 import sys
 from argparse import ArgumentParser
+import argparse
 
 import caosdb as db
 
-- 
GitLab