changeset 0:b0665b243ccd

initial import of licenser
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 10 May 2010 09:18:26 -0700
parents
children cc5add25bf83
files licenser/__init__.py licenser/licenses.py licenser/main.py setup.py
diffstat 4 files changed, 108 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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 @@
+#
--- /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
--- /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()
--- /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
+      """,
+      )