# HG changeset patch # User Jeff Hammel # Date 1273508306 25200 # Node ID b0665b243ccd531fc5182ba5c7fa27d7c89c5046 initial import of licenser diff -r 000000000000 -r b0665b243ccd licenser/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/licenser/__init__.py Mon May 10 09:18:26 2010 -0700 @@ -0,0 +1,1 @@ +# diff -r 000000000000 -r b0665b243ccd licenser/licenses.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/licenser/licenses.py Mon May 10 09:18:26 2010 -0700 @@ -0,0 +1,9 @@ +from datetime import datetime + +class MPL(object): + """Mozilla Public License""" + template = 'MPL' # could be implicit here + variables = [ 'author' ] + + def pre(self, variables): + variables['year'] = datetime.now().year diff -r 000000000000 -r b0665b243ccd licenser/main.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/licenser/main.py Mon May 10 09:18:26 2010 -0700 @@ -0,0 +1,68 @@ +#!/usr/bin/env python +""" +adds licenses to python packages +""" + +import os +import sys +from optparse import OptionParser +from pkg_resources import iter_entry_points + +def license_list(debug=False): + licenses = {} + for entry_point in iter_entry_points(): + try: + license = entry_point.load() + except: + if debug: + import pdb; pdb.set_trace() + else: + print >> sys.stderr, "Couldn't load license '%s'" % entry_point.name + 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('-l', '--license', + help="license to use") + parser.add_option('--list', action='store_true', default=False, + help="list available licenses") + options, args = parser.parse_args(args) + + licenses = license_list() + + if options.list: # list the licenses + for i in licenses: + pass + sys.exit(0) + + if not options.license: + parser.error("Must specify --license") + + for directory in args: + filelist = files(directory) + +if __name__ == '__main__': + main() diff -r 000000000000 -r b0665b243ccd setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Mon May 10 09:18:26 2010 -0700 @@ -0,0 +1,30 @@ +from setuptools import setup, find_packages + +version = '0.0' + +setup(name='licenser', + version=version, + description='adds licenses to python packages', + long_description="""\ +""", + classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers + keywords='license', + author='Jeff Hammel', + author_email='jhammel@mozilla.com', + url='', + license='MPL', + packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), + include_package_data=True, + zip_safe=False, + install_requires=[ + # -*- Extra requirements: -*- + ], + entry_points=""" + # -*- Entry points: -*- + [console_scripts] + licenser = licenser.main:main + + [licenser.license] + MPL = licenser.licenses:MPL + """, + )