diff options
author | Brett Smith <brettcsmith@brettcsmith.org> | 2012-03-25 12:11:13 -0400 |
---|---|---|
committer | Brett Smith <brettcsmith@brettcsmith.org> | 2012-03-25 12:11:13 -0400 |
commit | 095fbdaf8d165dae390c4fb61b888309056b8fe6 (patch) | |
tree | 64397fbaee4baeefce2ff81aca68897a92b3b796 /mediagoblin/processing.py | |
parent | 6573573dd1650a73fe058df43dfb5770217b2afa (diff) | |
download | mediagoblin-095fbdaf8d165dae390c4fb61b888309056b8fe6.tar.lz mediagoblin-095fbdaf8d165dae390c4fb61b888309056b8fe6.tar.xz mediagoblin-095fbdaf8d165dae390c4fb61b888309056b8fe6.zip |
Add FilenameMunger class to processing, with tests.
Munging filenames is something all media type processors want to be able to
do, so I'm refactoring it out into a nice bite-sized class.
Diffstat (limited to 'mediagoblin/processing.py')
-rw-r--r-- | mediagoblin/processing.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/mediagoblin/processing.py b/mediagoblin/processing.py index 1c84c557..b0d5751e 100644 --- a/mediagoblin/processing.py +++ b/mediagoblin/processing.py @@ -15,6 +15,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import logging +import os from celery.task import Task @@ -42,6 +43,21 @@ def create_pub_filepath(entry, filename): # Media processing initial steps ################################ +class FilenameMunger(object): + MAX_FILENAME_LENGTH = 255 + + def __init__(self, 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): + basename_len = (self.MAX_FILENAME_LENGTH - + len(fmtstr.format(basename='', ext=self.ext))) + return fmtstr.format(basename=self.basename[:basename_len], + ext=self.ext) + + class ProcessMedia(Task): """ DEPRECATED -- This now resides in the individual media plugins |