changeset 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 16d41af2d8ef
children a328cc9d2c74
files decoupage/formatters.py setup.py
diffstat 2 files changed, 27 insertions(+), 2 deletions(-) [+]
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()
--- a/setup.py	Thu Dec 24 22:48:55 2009 -0500
+++ b/setup.py	Thu Dec 24 23:33:37 2009 -0500
@@ -6,7 +6,7 @@
 except IOError:
     description = ''
 
-version = '0.3.1'
+version = '0.3.2'
 
 setup(name='decoupage',
       version=version,
@@ -32,6 +32,7 @@
       # -*- Entry points: -*-
       [console_scripts]
       decoupage-templates = decoupage.templates:main
+      decoupage-formatters = decoupage.formatters:main
 
       [paste.app_factory]
       main = decoupage.factory:factory