aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/processing/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/processing/__init__.py')
-rw-r--r--mediagoblin/processing/__init__.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/mediagoblin/processing/__init__.py b/mediagoblin/processing/__init__.py
index 5ce9281b..95f346d2 100644
--- a/mediagoblin/processing/__init__.py
+++ b/mediagoblin/processing/__init__.py
@@ -74,6 +74,58 @@ class FilenameBuilder(object):
ext=self.ext)
+
+
+class MediaProcessor(object):
+ # You MUST override this in the child MediaProcessor!
+ name = None
+
+ def __init__(self, manager):
+ self.manager = manager
+
+ def media_is_eligibile(self, media_entry):
+ raise NotImplementedError
+
+ def process(self):
+ raise NotImplementedError
+
+ def generate_parser(self):
+ raise NotImplementedError
+
+
+class ProcessingManager(object):
+ def __init__(self, entry):
+ self.entry = entry
+ # May merge these two classes soon....
+ self.state = ProcessingState(entry)
+
+ # Dict of all MediaProcessors of this media type
+ self.processors = {}
+
+ def add_processor(self, processor):
+ """
+ Add a processor class to this media type
+ """
+ name = processor.name
+ if name is None:
+ raise AttributeError("Processor class's .name attribute not set")
+
+ self.processors[name] = processor
+
+ def list_eligible_processors(self):
+ """
+ List all processors that this media entry is eligible to be processed
+ for.
+ """
+ return [
+ processor
+ for processor in self.processors.keys()
+ if processor.media_is_eligible(self.entry)]
+
+ def process(self, processor):
+ pass
+
+
class ProcessingState(object):
"""
The first and only argument to the "processor" of a media type