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

update

parent 21071fcb
No related branches found
No related tags found
No related merge requests found
......@@ -3,12 +3,15 @@
"""does something"""
import argparse
from argparse import RawTextHelpFormatter
import re
import caosdb as db
from argparse import RawTextHelpFormatter
from datetime import datetime
import caosdb as db
from caosdb.exceptions import TransactionError
from something import get_entity
class AbstractCFood(object):
def __init__(self, pattern):
......@@ -16,8 +19,10 @@ class AbstractCFood(object):
def treat_match(self, filename, match):
entities = self.create_identifiables(filename, match)
for key, ent in entities.items():
existing = find_existing(ent)
existing = AbstractCFood.find_existing(ent)
if existing is None:
print(key, "does not exist")
ent.insert()
......@@ -35,6 +40,17 @@ class AbstractCFood(object):
def update_identifiables(self, entities, filename, match):
raise NotImplementedError()
@staticmethod
# move to api?
def set_parents(entity, names):
parents = [p.name for p in entity.get_parents()]
for p in parents:
entity.remove_parent(p)
for n in names:
entity.add_parent(get_entity(n))
@staticmethod
def find_existing(entity):
query_string = "FIND Record "+ entity.get_parents()[0].name
......
......@@ -4,21 +4,31 @@
import argparse
from argparse import RawTextHelpFormatter
from cfood import CFood
import caosdb as db
from cfood import CFood
class Crawler(object):
def __init__(self, food):
self.food = food
self.report = db.Container()
def crawl(self, files):
for crawled_file in files:
if crawled_file.size == 0:
crawled_file.add_message(
type="Warning", description="This file is empty. Shouldn't we delete it?")
self.report.append(f)
continue
for cfood in self.food:
match = cfood.pattern.match(crawled_file.path)
def crawl(self):
filename="path/to/file"
for cfood in self.food:
match = cfood.pattern.match(filename)
if match is not None:
print("match")
cfood.treat_match(filename, match)
if match is not None:
cfood.treat_match(crawled_file.path, match)
def get_parser():
......@@ -34,4 +44,4 @@ if __name__ == "__main__":
f = CFood(pattern="(.*)to(.*)")
c = Crawler(food=[f])
c.crawl()
c.crawl(["path/to/file"])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment