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
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)
# 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)
# 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)
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:
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()
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()
# 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 -
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))