66"""
77
88import inspect
9+ import itertools
910import logging
1011import logging .handlers
1112import optparse
@@ -98,7 +99,11 @@ def main():
9899
99100 # Determine which hook we're running
100101 if not args :
101- parser .error ('Please specify the hook to run' )
102+ if options .listing :
103+ list_hooks ()
104+ return 0
105+ else :
106+ parser .error ('Please specify the hook to run' )
102107 hook = args [0 ]
103108
104109 if options .sourcing and options .script_filename :
@@ -126,6 +131,7 @@ def main():
126131
127132 return 0
128133
134+
129135def run_hooks (hook , options , args , output = None ):
130136 if output is None :
131137 output = sys .stdout
@@ -135,7 +141,7 @@ def run_hooks(hook, options, args, output=None):
135141 continue
136142 plugin = ep .load ()
137143 if options .listing :
138- sys . stdout .write (' %-10s -- %s\n ' % (ep .name , inspect .getdoc (plugin ) or '' ))
144+ output .write (' %-10s -- %s\n ' % (ep .name , inspect .getdoc (plugin ) or '' ))
139145 continue
140146 if options .sourcing :
141147 # Show the shell commands so they can
@@ -149,5 +155,29 @@ def run_hooks(hook, options, args, output=None):
149155 # Just run the plugin ourselves
150156 plugin (args [1 :])
151157
158+
159+ def list_hooks (output = None ):
160+ if output is None :
161+ output = sys .stdout
162+ for hook in itertools .chain (
163+ ('_' .join (h )
164+ for h in itertools .product (['pre' , 'post' ],
165+ ['mkvirtualenv' ,
166+ 'rmvirtualenv' ,
167+ 'activate' ,
168+ 'deactivate' ,
169+ 'cpvirtualenv' ,
170+ ])
171+ ),
172+ ['initialize' ,
173+ 'get_env_details' ,
174+ 'project.pre_mkproject' ,
175+ 'project.post_mkproject' ,
176+ 'project.template' ,
177+ ]
178+ ):
179+ output .write (hook + '\n ' )
180+
181+
152182if __name__ == '__main__' :
153183 main ()
0 commit comments