diff decoupage/formatters.py @ 9:ec2d0d850b83

add ability to print formatters with decoupage-formatters console_script
author k0s <k0scist@gmail.com>
date Thu, 24 Dec 2009 23:33:37 -0500
parents 93ab6d1968bd
children a328cc9d2c74
line wrap: on
line diff
--- a/decoupage/formatters.py	Thu Dec 24 22:48:55 2009 -0500
+++ b/decoupage/formatters.py	Thu Dec 24 23:33:37 2009 -0500
@@ -1,4 +1,8 @@
+#!/usr/bin/env python
+
+import sys
 from fnmatch import fnmatch
+from pkg_resources import iter_entry_points
 
 ### abstract base classes for formatters
 
@@ -49,7 +53,7 @@
 
 class All(object):
     """
-    only pass files of a certain pattern;
+    only pass files of a certain pattern; 
     the inverse of ignore
     """
     
@@ -74,6 +78,7 @@
         
 
 class FilenameDescription(FormatterBase):
+    """substitute the description for the filename"""
 
     def __call__(self, request, data):
         for f in data['files']:
@@ -85,6 +90,9 @@
 
 
 class TitleDescription(FormatterBase):
+    """splits a description into a title and a description with a separator"""
+    
+
     defaults = { 'separator': ':' }
         
     def __call__(self, request, data):
@@ -98,3 +106,19 @@
                 f['description'] = None
                 
         
+def formatters():
+    formatters = {}
+    for entry_point in iter_entry_points('decoupage.formatters'):
+        try:
+            formatter = entry_point.load()
+        except:
+            continue
+        formatters[entry_point.name] = formatter
+    return formatters
+
+def main(args=sys.argv[1:]):
+    for name, formatter in formatters().items():
+        print '%s%s' % (name, formatter.__doc__ and ': ' + formatter.__doc__ or '')
+
+if __name__ == '__main__':
+    main()