Rename to FilenameBuilder, with a main method named fill.
authorBrett Smith <brettcsmith@brettcsmith.org>
Mon, 26 Mar 2012 17:40:35 +0000 (13:40 -0400)
committerBrett Smith <brettcsmith@brettcsmith.org>
Mon, 26 Mar 2012 17:40:35 +0000 (13:40 -0400)
I think these names better convey what's actually going on.  I updated the
documentation a bit while I was at it.

mediagoblin/media_types/image/processing.py
mediagoblin/media_types/video/processing.py
mediagoblin/processing.py
mediagoblin/tests/test_processing.py

index 37fa861370d354de073b3220828139338b9cc53f..554c72b8800576f1f11ab65107cec025b196b259 100644 (file)
@@ -19,7 +19,7 @@ import os
 
 from mediagoblin import mg_globals as mgg
 from mediagoblin.processing import BadMediaFail, \
-    create_pub_filepath, THUMB_SIZE, MEDIUM_SIZE, FilenameMunger
+    create_pub_filepath, THUMB_SIZE, MEDIUM_SIZE, FilenameBuilder
 from mediagoblin.tools.exif import exif_fix_image_orientation, \
     extract_exif, clean_exif, get_gps_data, get_useful
 
@@ -67,7 +67,7 @@ def process_image(entry):
     queued_filename = workbench.localized_file(
         mgg.queue_store, queued_filepath,
         'source')
-    name_munger = FilenameMunger(queued_filename)
+    name_builder = FilenameBuilder(queued_filename)
 
     # EXIF extraction
     exif_tags = extract_exif(queued_filename)
@@ -75,7 +75,7 @@ def process_image(entry):
 
     # Always create a small thumbnail
     thumb_filepath = create_pub_filepath(
-        entry, name_munger.munge('{basename}.thumbnail{ext}'))
+        entry, name_builder.fill('{basename}.thumbnail{ext}'))
     resize_image(entry, queued_filename, thumb_filepath,
                  exif_tags, conversions_subdir, THUMB_SIZE)
 
@@ -83,7 +83,7 @@ def process_image(entry):
     # file, a `.medium.jpg` files is created and later associated with the media
     # entry.
     medium_filepath = create_pub_filepath(
-        entry, name_munger.munge('{basename}.medium{ext}'))
+        entry, name_builder.fill('{basename}.medium{ext}'))
     resize_image(entry, queued_filename, medium_filepath,
                  exif_tags, conversions_subdir, MEDIUM_SIZE, MEDIUM_SIZE)
 
@@ -93,7 +93,7 @@ def process_image(entry):
 
     with queued_file:
         original_filepath = create_pub_filepath(
-            entry, name_munger.munge('{basename}{ext}') )
+            entry, name_builder.fill('{basename}{ext}') )
 
         with mgg.public_store.get_file(original_filepath, 'wb') \
             as original_file:
index 98379d52e4e4e5e1aa8231e52f44a961252faa5f..24c036488199707015567089484dfae0e95e5d33 100644 (file)
@@ -20,7 +20,7 @@ import os
 
 from mediagoblin import mg_globals as mgg
 from mediagoblin.processing import mark_entry_failed, \
-    THUMB_SIZE, MEDIUM_SIZE, create_pub_filepath, FilenameMunger
+    THUMB_SIZE, MEDIUM_SIZE, create_pub_filepath, FilenameBuilder
 from . import transcoders
 
 logging.basicConfig()
@@ -49,13 +49,13 @@ def process_video(entry):
     queued_filename = workbench.localized_file(
         mgg.queue_store, queued_filepath,
         'source')
-    name_munger = FilenameMunger(queued_filename)
+    name_builder = FilenameBuilder(queued_filename)
 
     medium_filepath = create_pub_filepath(
-        entry, name_munger.munge('{basename}-640p.webm'))
+        entry, name_builder.fill('{basename}-640p.webm'))
 
     thumbnail_filepath = create_pub_filepath(
-        entry, name_munger.munge('{basename}.thumbnail.jpg'))
+        entry, name_builder.fill('{basename}.thumbnail.jpg'))
 
     # Create a temporary file for the video destination
     tmp_dst = tempfile.NamedTemporaryFile()
index fa9192d9e6b1be097bc17524513b1f6f3794b1f5..718351d59159f82ebe35ec13e5ef1505c9b3b227 100644 (file)
@@ -43,28 +43,30 @@ def create_pub_filepath(entry, filename):
 # Media processing initial steps
 ################################
 
-class FilenameMunger(object):
+class FilenameBuilder(object):
     """Easily slice and dice filenames.
 
-    Initialize this class with an original filename, then use the munge()
+    Initialize this class with an original file path, then use the fill()
     method to create new filenames based on the original.
 
     """
     MAX_FILENAME_LENGTH = 255  # VFAT's maximum filename length
 
     def __init__(self, path):
-        """Initialize a munger with one original filename."""
+        """Initialize a builder from an original file path."""
         self.dirpath, self.basename = os.path.split(path)
         self.basename, self.ext = os.path.splitext(self.basename)
         self.ext = self.ext.lower()
 
-    def munge(self, fmtstr):
-        """Return a new filename based on the initialized original.
+    def fill(self, fmtstr):
+        """Build a new filename based on the original.
 
-        The fmtstr argumentcan include {basename} and {ext}, which will
-        fill in components of the original filename.  The extension will
-        always be lowercased.  The filename will also be trunacted to this
-        class' MAX_FILENAME_LENGTH characters.
+        The fmtstr argument can include the following:
+        {basename} -- the original basename, with the extension removed
+        {ext} -- the original extension, always lowercase
+
+        If necessary, {basename} will be truncated so the filename does not
+        exceed this class' MAX_FILENAME_LENGTH in length.
 
         """
         basename_len = (self.MAX_FILENAME_LENGTH -
index 6f3fad7085c78651f94af4e68d146eb043af4fd9..417f91f365b1f207c16621809226cb6b31c5a5d0 100644 (file)
@@ -5,16 +5,16 @@ from nose.tools import assert_equal, assert_true, assert_false
 from mediagoblin import processing
 
 class TestProcessing(object):
-    def run_munge(self, input, format, output=None):
-        munger = processing.FilenameMunger(input)
-        result = munger.munge(format)
+    def run_fill(self, input, format, output=None):
+        builder = processing.FilenameBuilder(input)
+        result = builder.fill(format)
         if output is None:
             return result
         assert_equal(output, result)
         
-    def test_easy_filename_munge(self):
-        self.run_munge('/home/user/foo.TXT', '{basename}bar{ext}', 'foobar.txt')
+    def test_easy_filename_fill(self):
+        self.run_fill('/home/user/foo.TXT', '{basename}bar{ext}', 'foobar.txt')
 
-    def test_long_filename_munge(self):
-        self.run_munge('{0}.png'.format('A' * 300), 'image-{basename}{ext}',
-                       'image-{0}.png'.format('A' * 245))
+    def test_long_filename_fill(self):
+        self.run_fill('{0}.png'.format('A' * 300), 'image-{basename}{ext}',
+                      'image-{0}.png'.format('A' * 245))