diff --git a/backend/lib/processor.py b/backend/lib/processor.py index 3aad595c7..f792c5243 100644 --- a/backend/lib/processor.py +++ b/backend/lib/processor.py @@ -863,4 +863,16 @@ def process(self): """ pass + @staticmethod + def is_4cat_processor(): + """ + Is this a 4CAT processor? + + This is used to determine whether a class is a 4CAT + processor. + + :return: True + """ + return True + diff --git a/backend/lib/worker.py b/backend/lib/worker.py index de9f3802a..3fe19e067 100644 --- a/backend/lib/worker.py +++ b/backend/lib/worker.py @@ -167,3 +167,27 @@ def work(self): classes should implement this method. """ pass + + @staticmethod + def is_4cat_class(): + """ + Is this a 4CAT class? + + This is used to determine whether a class is a 4CAT worker or a + processor. This method should always return True for workers. + + :return: True + """ + return True + + @staticmethod + def is_4cat_processor(): + """ + Is this a 4CAT processor? + + This is used to determine whether a class is a 4CAT + processor. + + :return: False + """ + return False \ No newline at end of file diff --git a/common/lib/module_loader.py b/common/lib/module_loader.py index 24edb233a..84e5d951e 100644 --- a/common/lib/module_loader.py +++ b/common/lib/module_loader.py @@ -72,20 +72,21 @@ def is_4cat_class(object, only_processors=False): # it would be super cool to just use issubclass() here! # but that requires importing the classes themselves, which leads to # circular imports - # todo: fix this because this sucks - # agreed - Dale - parent_classes = {"BasicWorker", "BasicProcessor", "Search", "SearchWithScope", "Search4Chan", - "ProcessorPreset", "TwitterStatsBase", "BaseFilter", "TwitterAggregatedStats", "ColumnFilter", - "BasicJSONScraper", "BoardScraper4chan", "ThreadScraper4chan"} - if only_processors: - # only allow processors - for worker_only_class in ["BasicWorker", "BasicJSONScraper", "BoardScraper4chan", "ThreadScraper4chan"]: - parent_classes.remove(worker_only_class) - - return inspect.isclass(object) and \ - parent_classes & set([f.__name__ for f in object.__bases__]) and \ - object.__name__ not in("BasicProcessor", "BasicWorker") and \ - not inspect.isabstract(object) + if inspect.isclass(object): + if object.__name__ in("BasicProcessor", "BasicWorker") or inspect.isabstract(object): + # ignore abstract and base classes + return False + + if hasattr(object, "is_4cat_class"): + if only_processors: + if hasattr(object, "is_4cat_processor"): + return object.is_4cat_processor() + else: + return False + else: + return object.is_4cat_class() + + return False def load_modules(self): """