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

update

parent 00eed496
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,7 @@ import os ...@@ -35,6 +35,7 @@ import os
import caosdb as db import caosdb as db
from caosdb.apiutils import retrieve_entities_with_ids from caosdb.apiutils import retrieve_entities_with_ids
from caosdb.common.datatype import get_id_of_datatype, is_reference from caosdb.common.datatype import get_id_of_datatype, is_reference
from lxml import etree
def get_ids_of_related_entities(entity): def get_ids_of_related_entities(entity):
......
...@@ -35,7 +35,7 @@ import caosdb as db ...@@ -35,7 +35,7 @@ import caosdb as db
from caosmodels.data_model import DataModel from caosmodels.data_model import DataModel
from lxml import etree from lxml import etree
from export_related import apply_to_ids RERUN = False
def create_dummy_file(text="Please ask the administrator for this file."): def create_dummy_file(text="Please ask the administrator for this file."):
...@@ -76,7 +76,9 @@ def main(filename): ...@@ -76,7 +76,9 @@ def main(filename):
# TODO why is this necessary? # TODO why is this necessary?
new_files = [] new_files = []
print(files)
if not RERUN:
for fi in files: for fi in files:
new = db.File(file=fi.file, path=fi.path, name=fi.name, id=fi.id, new = db.File(file=fi.file, path=fi.path, name=fi.name, id=fi.id,
description=fi.description) description=fi.description)
...@@ -84,14 +86,17 @@ def main(filename): ...@@ -84,14 +86,17 @@ def main(filename):
for p in fi.parents: for p in fi.parents:
new.add_parent(p) new.add_parent(p)
new_files.append(new) new_files.append(new)
else:
files = new_files for fi in files:
new = db.File(path=fi.path, id=fi.id)
new_files.append(new)
# remove entities of the model from the container # remove entities of the model from the container
for el in model+files: for el in model+files:
cont.remove(el) cont.remove(el)
cont.remove(fi)
files = new_files
id_mapping = {} id_mapping = {}
...@@ -105,9 +110,15 @@ def main(filename): ...@@ -105,9 +110,15 @@ def main(filename):
# insert files # insert files
if not RERUN:
for i, el in enumerate(files): for i, el in enumerate(files):
id_mapping[el.id] = el print(el)
el.insert(unique=False) r = el.insert(unique=False)
print(r)
else:
for i, el in enumerate(files):
el.id = None
el.retrieve()
def replace_by_new(old): def replace_by_new(old):
if old in id_mapping: if old in id_mapping:
...@@ -118,7 +129,7 @@ def main(filename): ...@@ -118,7 +129,7 @@ def main(filename):
# set the ids of already inserted entities in the container # set the ids of already inserted entities in the container
for el in cont: for el in cont:
apply_to_ids(el, replace_by_new) el.apply_to_ids(replace_by_new)
cont.insert(unique=False) cont.insert(unique=False)
......
...@@ -24,9 +24,8 @@ import argparse ...@@ -24,9 +24,8 @@ import argparse
import re import re
import sys import sys
import pandas as pd
import caosdb as db import caosdb as db
import pandas as pd
def from_tsv(filename, recordtype): def from_tsv(filename, recordtype):
...@@ -81,6 +80,10 @@ def from_table(spreadsheet, recordtype): ...@@ -81,6 +80,10 @@ def from_table(spreadsheet, recordtype):
rec.add_parent(name=recordtype) rec.add_parent(name=recordtype)
for key, value in row.iteritems(): for key, value in row.iteritems():
if key.lower() == "description":
rec.description = value
continue
if (pd.notnull(value) and if (pd.notnull(value) and
(not isinstance(value, str) or value.strip() != "")): (not isinstance(value, str) or value.strip() != "")):
regexp = r"(.*)\[(.*)\].*" regexp = r"(.*)\[(.*)\].*"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment