diff makeitso/makeitso.py @ 107:2142ad247eb6

we can has entry points
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 14 Jan 2011 07:29:23 -0800
parents 1295df1700a4
children 32893f67f85d
line wrap: on
line diff
--- a/makeitso/makeitso.py	Tue Jan 11 19:30:13 2011 -0800
+++ b/makeitso/makeitso.py	Fri Jan 14 07:29:23 2011 -0800
@@ -325,14 +325,16 @@
     """template for several files/directories"""
 
     def __init__(self, templates, interactive=True, variables=None):
-
         self.interactive = interactive
         self.templates = []
+        entry_points = get_entry_points()
         for template in templates:
             if isinstance(template, basestring):
                 # TODO: check if the template is a [e.g] PasteScript.template entry point
                 if os.path.isdir(template):
                     self.templates.append(DirectoryTemplate(template, interactive=self.interactive, variables=variables))
+                elif not os.path.exists(template) and template in entry_points:
+                    self.templates.append(entry_points[template](interactive=interactive, variables=variables))
                 else:
                     self.templates.append(URITemplate(template, interactive=self.interactive, variables=variables))
             else:
@@ -512,11 +514,16 @@
 # get templates from pkg_resources
 # (MakeItSo! and [TODO] pastescript templates)
 # this should go last to ensure the module is wholly loaded
-def get_entry_points(name):
+def get_entry_points():
+    retval = {}
     try:
         from pkg_resources import iter_entry_points
         for i in iter_entry_points('makeitso.templates'):
-            pass # :(
+            try:
+                retval[i.name] = i.load()
+            except:
+                continue
 
     except ImportError:
-        return None
+        return retval
+    return retval