From 006f84818561d0334d8d8e991bae08bc7d1c5916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org> Date: Mon, 20 May 2019 17:24:37 +0200 Subject: [PATCH] ENH: names of records can now be used for identification --- src/caosadvancedtools/cfood.py | 16 ++++++++++------ src/caosadvancedtools/utils.py | 5 ++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/caosadvancedtools/cfood.py b/src/caosadvancedtools/cfood.py index e89216dc..755f8537 100644 --- a/src/caosadvancedtools/cfood.py +++ b/src/caosadvancedtools/cfood.py @@ -147,12 +147,16 @@ class AbstractCFood(object): @staticmethod def find_existing(entity): - query_string = "FIND Record " + entity.get_parents()[0].name - #import IPython - # IPython.embed() - query_string += " with " + " and ".join( - ["'" + p.name + "'='" - + get_value(p) + "'" for p in entity.get_properties()]) + if entity.name is None: + query_string = "FIND Record " + entity.get_parents()[0].name + #import IPython + # IPython.embed() + query_string += " with " + " and ".join( + ["'" + p.name + "'='" + + get_value(p) + "'" for p in entity.get_properties()]) + else: + query_string = "FIND '{}'".format(entity.name) + print(query_string) q = db.Query(query_string) try: diff --git a/src/caosadvancedtools/utils.py b/src/caosadvancedtools/utils.py index 2d3e5c78..4fd569a1 100644 --- a/src/caosadvancedtools/utils.py +++ b/src/caosadvancedtools/utils.py @@ -35,7 +35,10 @@ def replace_path_prefix(path, old_prefix, new_prefix): """ if not path.startswith(old_prefix): - raise RuntimeError("Path does not start with old_prefix") + raise RuntimeError( + "Path does not start with old_prefix\n{}\nvs\n{}".format( + path, + old_prefix)) path = path[len(old_prefix):] return os.path.join(new_prefix, path) -- GitLab