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

DEV: introduced CMeal, an addition for CFood that allows to collect similar files in one CFood

parent 84b62645
No related branches found
No related tags found
No related merge requests found
...@@ -91,6 +91,25 @@ class AbstractCFood(object): ...@@ -91,6 +91,25 @@ class AbstractCFood(object):
""" """
raise NotImplementedError() raise NotImplementedError()
@classmethod
def cook(cls, crawled_file):
""" possibly checks for existing CFoods whether the match should be
added or whether a new CFood instance needs to be returned
This function should typically be used to create CFoods in order to
prevent the creation of unnecessary instances.
This standard implementation does not do a check but may be overwritten
by subclasses.
Retruns
-------------
CFood: if a new instance was created
None: otherwise
"""
return cls()
@classmethod @classmethod
def match(cls, string): def match(cls, string):
""" Matches the regular expression of this class against file names """ Matches the regular expression of this class against file names
...@@ -337,3 +356,31 @@ def get_ids_for_entities_with_names(entities): ...@@ -337,3 +356,31 @@ def get_ids_for_entities_with_names(entities):
for parent in ent.get_parents(): for parent in ent.get_parents():
insert_id_based_on_name(parent) insert_id_based_on_name(parent)
insert_id_based_on_name(ent) insert_id_based_on_name(ent)
class CMeal(object):
existing_instances = []
matching_groups = []
def __init__(self, *args, **kwargs):
self.existing_instances.append(self)
self.crawled_files = []
def add(self, crawled_file):
self.crawled_files.append(crawled_file)
@classmethod
def get_suitable_cfood(cls, match):
for cfood in cls.existing_instances:
suitable = True
for group in cls.matching_groups:
if (group not in match or
group not in cfood.match or
match.group(group) == cfood.match.group(group)):
suitable = False
if suitable:
return cfood
return None
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