Add documentation to the FilenameMunger class.
authorBrett Smith <brettcsmith@brettcsmith.org>
Sun, 25 Mar 2012 16:16:19 +0000 (12:16 -0400)
committerBrett Smith <brettcsmith@brettcsmith.org>
Sun, 25 Mar 2012 16:16:19 +0000 (12:16 -0400)
mediagoblin/processing.py

index b0d5751e98c36fac33457e501d2896497ac84a38..fa9192d9e6b1be097bc17524513b1f6f3794b1f5 100644 (file)
@@ -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],