# HG changeset patch # User Jeff Hammel # Date 1322168595 28800 # Node ID 0b51868bdfb9419fc59a75d09f38d1f807bb9e07 # Parent cf920f85fb98db93ddb5ea0ea4951da79af055b4 better documentation diff -r cf920f85fb98 -r 0b51868bdfb9 licenser/main.py --- 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)