Skip to content
Snippets Groups Projects
Commit b5444cb1 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

fixes and debug output

parent 1c610f14
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,13 @@ from caosdb.exceptions import TransactionError ...@@ -37,6 +37,13 @@ from caosdb.exceptions import TransactionError
ENTITIES = {} ENTITIES = {}
def get_value(prop):
if not isinstance(prop.value, db.Entity):
return prop.value
else:
return str(prop.value.id)
def get_entity(name): def get_entity(name):
if name not in ENTITIES: if name not in ENTITIES:
ent = db.Entity(name=name) ent = db.Entity(name=name)
...@@ -69,14 +76,18 @@ class AbstractCFood(object): ...@@ -69,14 +76,18 @@ class AbstractCFood(object):
continue continue
existing = None existing = None
print("Looking for \n", identifiable)
if self.use_cache: if self.use_cache:
identifiable_cache = Cache() identifiable_cache = Cache()
identifier = Cache.hash_entity(identifiable) identifier = Cache.hash_entity(identifiable)
print(identifier)
cached_id = identifiable_cache.check_existing(identifier) cached_id = identifiable_cache.check_existing(identifier)
if cached_id is not None: if cached_id is not None:
existing = db.execute_query("FIND {}".format(cached_id), existing = db.execute_query("FIND {}".format(cached_id),
unique=True) unique=True)
print("Found Entity in cache; Id:", cached_id)
# Nothing in cache or cache not used. Check in CaosDB # Nothing in cache or cache not used. Check in CaosDB
...@@ -91,8 +102,13 @@ class AbstractCFood(object): ...@@ -91,8 +102,13 @@ class AbstractCFood(object):
else: else:
entities[key] = existing entities[key] = existing
if self.use_cache and cached_id is None: print("Got\n", identifiable)
identifiable_cache.insert(identifier, entities[key].id)
if self.use_cache:
print("cid", cached_id)
if self.use_cache and cached_id is None:
identifiable_cache.insert(identifier, entities[key].id)
self.update_identifiables(entities, crawled_file, match) self.update_identifiables(entities, crawled_file, match)
...@@ -127,8 +143,11 @@ class AbstractCFood(object): ...@@ -127,8 +143,11 @@ class AbstractCFood(object):
@staticmethod @staticmethod
def find_existing(entity): def find_existing(entity):
query_string = "FIND Record " + entity.get_parents()[0].name query_string = "FIND Record " + entity.get_parents()[0].name
query_string += " with " + "and".join(["'" + p.name + "'='" + p.value + "'" #import IPython
for p in entity.get_properties()]) # IPython.embed()
query_string += " with " + " and ".join(
["'" + p.name + "'='"
+ get_value(p) + "'" for p in entity.get_properties()])
print(query_string) print(query_string)
q = db.Query(query_string) q = db.Query(query_string)
try: try:
...@@ -136,6 +155,11 @@ class AbstractCFood(object): ...@@ -136,6 +155,11 @@ class AbstractCFood(object):
except TransactionError as er: except TransactionError as er:
r = None r = None
if r is not None:
print("Found Entity with id:", r.id)
else:
print("Did not find an existing entity")
return r return r
......
...@@ -31,6 +31,8 @@ import re ...@@ -31,6 +31,8 @@ import re
import caosdb as db import caosdb as db
import yaml import yaml
from .cfood import AbstractCFood, get_entity
TEMPLATEHEADER = """ TEMPLATEHEADER = """
--- ---
title: {title} title: {title}
...@@ -210,15 +212,32 @@ def parse_responsibles(header): ...@@ -210,15 +212,32 @@ def parse_responsibles(header):
return people return people
def reference_data_files(entity, header): def reference_data_files(entity, header, prefix=""):
for glob in header["data"]: referenced_files = []
for glob in get_data_glob(header):
if not glob.startswith("/"):
glob = os.path.normpath(os.path.join(prefix, glob))
for dfile in find_file_for_fileglob(glob): for dfile in find_file_for_fileglob(glob):
entity.add_property("data", dfile) if dfile is not None:
referenced_files.append(dfile)
AbstractCFood.set_property(entity, get_entity("Data"), referenced_files)
def get_data_glob(header):
globs = []
for el in header["data"]:
if isinstance(el, dict) and "filename" in el:
globs.append(el["filename"])
else:
globs.append(el)
return globs
def find_file_for_fileglob(glob): def find_file_for_fileglob(glob):
# TODO this probalby needs to be extended for different kinds of glob # TODO this probalby needs to be extended for different kinds of glob
res = db.execute_query("FIND file which is stored at {}".format(glob)) query_string = "FIND file which is stored at {}".format(glob)
print(query_string)
return db.execute_query(query_string)
def find_records_referencing_files(glob): def find_records_referencing_files(glob):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment