Mercurial > mozilla > hg > licenser
diff licenser/main.py @ 1:cc5add25bf83
abstract License to its own class and do the work there
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 10 May 2010 11:24:02 -0700 |
parents | b0665b243ccd |
children | b8d620fa1116 |
line wrap: on
line diff
--- a/licenser/main.py Mon May 10 09:18:26 2010 -0700 +++ b/licenser/main.py Mon May 10 11:24:02 2010 -0700 @@ -10,41 +10,24 @@ def license_list(debug=False): licenses = {} - for entry_point in iter_entry_points(): + for entry_point in iter_entry_points('licenser.license'): try: license = entry_point.load() - except: + except Exception, e: if debug: import pdb; pdb.set_trace() else: - print >> sys.stderr, "Couldn't load license '%s'" % entry_point.name + print >> sys.stderr, "Couldn't load license '%s' [%s]" % (entry_point.name, e) continue licenses[entry_point.name] = license return licenses -def isempty(path): - """ - determines if a python file is empty; that is, contains only comments - """ - for line in file(path, 'r').readlines(): - line = line.strip() - if line and line[0] != '#': - return False - return True - -def files(directory): - files = set() - for dirpath, _, filenames in os.walk(directory): - for f in filenames: - if f.endswith('.py'): # could use os.path.splitext() - path = os.path.join(dirpath, f) - if not isempty(path): - files.add(path) - return files def main(args=sys.argv[1:]): usage = '%prog [options] directory' parser = OptionParser(usage, description=__doc__) + parser.add_option('-d', '--debug', action='store_true', default=False, + help="debug the application") parser.add_option('-l', '--license', help="license to use") parser.add_option('--list', action='store_true', default=False, @@ -54,8 +37,12 @@ licenses = license_list() if options.list: # list the licenses - for i in licenses: - pass + for i in sorted(licenses.keys()): + doc = getattr(licenses[i], '__doc__') + if doc: + print '%s: %s' % (i, doc) + else: + print i sys.exit(0) if not options.license: