changeset 16:0b51868bdfb9

better documentation
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 24 Nov 2011 13:03:15 -0800
parents cf920f85fb98
children 4566b3ac9838
files licenser/main.py
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/licenser/main.py	Thu Nov 24 12:58:32 2011 -0800
+++ b/licenser/main.py	Thu Nov 24 13:03:15 2011 -0800
@@ -46,6 +46,8 @@
 from pkg_resources import iter_entry_points
 
 def license_list(debug=False):
+    """get list of licenses"""
+    
     licenses = {}
     for entry_point in iter_entry_points('licenser.license'):
         try:
@@ -60,6 +62,8 @@
     return licenses
 
 def print_licenses(licenses):
+    """print licenses to stdout"""
+    
     for i in sorted(licenses.keys()):
         doc = getattr(licenses[i], '__doc__')
         if doc:
@@ -69,6 +73,8 @@
 
 
 def main(args=sys.argv[1:]):
+
+    # parse command line options
     usage = '%prog [options] directory'
     parser = OptionParser(usage, description=__doc__)
     parser.add_option('-l', '--license', dest='license', default='MPL',
@@ -80,25 +86,31 @@
                       help="print the chosen license")
     options, args = parser.parse_args(args)
 
+    # get the licenses
     licenses = license_list()
 
     if options.list: # list the licenses
         print_licenses(licenses)
         sys.exit(0)
 
-    if not options.license:
-        parser.error("Must specify --license")
+    # sanity check
     if options.license not in licenses:
+        print "License '%s' not found"
         print_licenses(licenses)
+        parser.exit(1)
 
+    # get the license of choice
     license = licenses[options.license]()
 
     if options._print:
+        # print the license if specified
         license.print_license()
         sys.exit(0)
 
+    # obtain the variables
     variables = license.obtain_variables()
 
+    # interpolate paths
     for arg in args:
         if os.path.isdir(arg):
             license.interpolate(arg, variables)