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

Merge branch 'f-matchonly' into 'master'

Separate matching of files from the remaining tasks

See merge request caosdb/caosdb-advanced-user-tools!14
parents 46742117 7af972b0
No related branches found
No related tags found
No related merge requests found
...@@ -75,9 +75,9 @@ class AbstractCFood(object): ...@@ -75,9 +75,9 @@ class AbstractCFood(object):
A function that takes a CaosDB path and returns a local path A function that takes a CaosDB path and returns a local path
""" """
self.access = access self.access = access
self.crawled_file = crawled_file self.crawled_file = None
self.crawled_path = crawled_file.path self.crawled_path = crawled_file
self.match = type(self).match(crawled_file.path) self.match = type(self).match(crawled_file)
self.to_be_updated = db.Container() self.to_be_updated = db.Container()
self.identifiables = db.Container() self.identifiables = db.Container()
self.verbosity = verbosity self.verbosity = verbosity
......
...@@ -74,14 +74,11 @@ class Crawler(object): ...@@ -74,14 +74,11 @@ class Crawler(object):
if self.use_cache: if self.use_cache:
self.cache = Cache() self.cache = Cache()
def crawl(self, files, interactive=True, security_level=RETRIEVE): def match(self, files):
errors_occured = False errors_occured = False
tbs = [] tbs = []
guard.set_level(level=security_level)
files = sorted(files, key=lambda x: x.path)
cfoods = [] cfoods = []
matches = {f.path: 0 for f in files} matches = {f: 0 for f in files}
if self.verbosity >= INFO: if self.verbosity >= INFO:
print("-"*60) print("-"*60)
...@@ -93,15 +90,15 @@ class Crawler(object): ...@@ -93,15 +90,15 @@ class Crawler(object):
for crawled_file in files: for crawled_file in files:
if self.verbosity >= DEBUG: if self.verbosity >= DEBUG:
print("Matching {}...".format(crawled_file.path)) print("Matching {}...".format(crawled_file))
if Cfood.match(crawled_file.path) is not None: if Cfood.match(crawled_file) is not None:
matches[crawled_file.path] += 1 matches[crawled_file] += 1
if self.verbosity >= VERBOSE: if self.verbosity >= VERBOSE:
print("{} matched\n{}.".format( print("{} matched\n{}.".format(
Cfood.__class__.__name__, Cfood.__class__.__name__,
crawled_file.path)) crawled_file))
try: try:
cfood = Cfood.cook(crawled_file, access=self.access, cfood = Cfood.cook(crawled_file, access=self.access,
verbosity=self.verbosity) verbosity=self.verbosity)
...@@ -127,25 +124,34 @@ class Crawler(object): ...@@ -127,25 +124,34 @@ class Crawler(object):
for crawled_file in files: for crawled_file in files:
if self.verbosity >= DEBUG: if self.verbosity >= DEBUG:
print("Matching {}...".format(crawled_file.path)) print("Matching {}...".format(crawled_file))
if cfood.looking_for(crawled_file): if cfood.looking_for(crawled_file):
if self.verbosity >= VERBOSE: if self.verbosity >= VERBOSE:
print("{} matched\n{}.".format( print("{} matched\n{}.".format(
Cfood.__class__.__name__, Cfood.__class__.__name__,
crawled_file.path)) crawled_file))
cfood.attach(crawled_file) cfood.attach(crawled_file)
matches[crawled_file.path] += 1 matches[crawled_file] += 1
if self.verbosity >= INFO: if self.verbosity >= INFO:
for crawled_file in files: for crawled_file in files:
if matches[crawled_file.path] == 0: if matches[crawled_file] == 0:
print("ATTENTION: No matching cfood!") print("ATTENTION: No matching cfood!")
print("Tried to match {}".format(crawled_file.path)) print("Tried to match {}".format(crawled_file))
if matches[crawled_file.path] > 1: if matches[crawled_file] > 1:
print("Attention: More than one matching cfood!") print("Attention: More than one matching cfood!")
print("Tried to match {}".format(crawled_file.path)) print("Tried to match {}".format(crawled_file))
return cfoods, matches, tbs, errors_occured
def crawl(self, files, interactive=True, security_level=RETRIEVE):
guard.set_level(level=security_level)
files = sorted(files, key=lambda x: x.path)
cfoods, matches, tbs, errors_occured = self.match(files)
if interactive and "y" != input("Do you want to continue? (y)"): if interactive and "y" != input("Do you want to continue? (y)"):
return return
......
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