aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/processing.py
diff options
context:
space:
mode:
authorBrett Smith <brettcsmith@brettcsmith.org>2012-03-25 12:16:19 -0400
committerBrett Smith <brettcsmith@brettcsmith.org>2012-03-25 12:16:19 -0400
commit4774cfa3c0df8ce1e20f0220e560a3c5d2ff0b82 (patch)
tree0093e2e7d8f4bd28ea3a4beef743812388907299 /mediagoblin/processing.py
parent095fbdaf8d165dae390c4fb61b888309056b8fe6 (diff)
downloadmediagoblin-4774cfa3c0df8ce1e20f0220e560a3c5d2ff0b82.tar.lz
mediagoblin-4774cfa3c0df8ce1e20f0220e560a3c5d2ff0b82.tar.xz
mediagoblin-4774cfa3c0df8ce1e20f0220e560a3c5d2ff0b82.zip
Add documentation to the FilenameMunger class.
Diffstat (limited to 'mediagoblin/processing.py')
-rw-r--r--mediagoblin/processing.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/mediagoblin/processing.py b/mediagoblin/processing.py
index b0d5751e..fa9192d9 100644
--- a/mediagoblin/processing.py
+++ b/mediagoblin/processing.py
@@ -44,14 +44,29 @@ def create_pub_filepath(entry, filename):
################################
class FilenameMunger(object):
- MAX_FILENAME_LENGTH = 255
+ """Easily slice and dice filenames.
+
+ Initialize this class with an original filename, then use the munge()
+ 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."""
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.
+
+ 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.
+
+ """
basename_len = (self.MAX_FILENAME_LENGTH -
len(fmtstr.format(basename='', ext=self.ext)))
return fmtstr.format(basename=self.basename[:basename_len],