Mercurial > mozilla > hg > licenser
changeset 3:e700bd2ec289
finish basic structure
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 10 May 2010 12:17:38 -0700 |
parents | b8d620fa1116 |
children | e46374799119 |
files | licenser/licenses.py licenser/licenses/MPL licenser/main.py |
diffstat | 3 files changed, 78 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/licenser/licenses.py Mon May 10 11:46:49 2010 -0700 +++ b/licenser/licenses.py Mon May 10 12:17:38 2010 -0700 @@ -13,6 +13,11 @@ self.template) assert os.path.exists(self.template) + def print_license(self): + f = file(self.template) + print f.read() + f.close() + def __call__(self, directory, **kw): variables = self.obtain_variables(**kw) self.interpolate(directory, variables) @@ -29,8 +34,30 @@ """do anything that needs to be done before interpolation""" def interpolate(self, directory, variables): - for file in self.files(directory): - pass + for _file in self.files(directory): + + # get the file lines + f = file(_file) + lines = [ i.rstrip() for i in f.readlines() ] + f.close() + f = file(_file, 'w') + + # print shebang if it exists + if lines[0].startswith('#!'): + shebang = lines.pop(0) + print >> f, shebang + print >> f + + # print the license + g = file(self.template) + for line in g.readlines(): + print >> f, '# %s' % line.rstrip() + g.close() + + # print the rest of the file + for line in lines: + print >> f, line.rstrip() + f.close() def isempty(self, path): """ @@ -56,7 +83,7 @@ class MPL(License): """Mozilla Public License""" template = 'MPL' # could be implicit here - variables = [ 'author' ] + variables = [ 'author', 'email' ] def pre(self, variables): variables['year'] = datetime.now().year
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/licenser/licenses/MPL Mon May 10 12:17:38 2010 -0700 @@ -0,0 +1,36 @@ +***** BEGIN LICENSE BLOCK ***** +Version: MPL 1.1/GPL 2.0/LGPL 2.1 + +The contents of this file are subject to the Mozilla Public License Version +1.1 (the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +for the specific language governing rights and limitations under the +License. + +The Original Code is mozilla.org code. + +The Initial Developer of the Original Code is +Mozilla.org. +Portions created by the Initial Developer are Copyright (C) ${year} +the Initial Developer. All Rights Reserved. + +Contributor(s): + ${author} <${email}> (Original author) + +Alternatively, the contents of this file may be used under the terms of +either of the GNU General Public License Version 2 or later (the "GPL"), +or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +in which case the provisions of the GPL or the LGPL are applicable instead +of those above. If you wish to allow use of your version of this file only +under the terms of either the GPL or the LGPL, and not to allow others to +use your version of this file under the terms of the MPL, indicate your +decision by deleting the provisions above and replace them with the notice +and other provisions required by the GPL or the LGPL. If you do not delete +the provisions above, a recipient may use your version of this file under +the terms of any one of the MPL, the GPL or the LGPL. + +***** END LICENSE BLOCK *****
--- a/licenser/main.py Mon May 10 11:46:49 2010 -0700 +++ b/licenser/main.py Mon May 10 12:17:38 2010 -0700 @@ -22,7 +22,7 @@ licenses[entry_point.name] = license return licenses -def print_licenses(self, licenses): +def print_licenses(licenses): for i in sorted(licenses.keys()): doc = getattr(licenses[i], '__doc__') if doc: @@ -34,12 +34,15 @@ 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('-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, help="list available licenses") + parser.add_option('-p', '--print', dest='_print', + action='store_true', default=False, + help="print the chosen license") options, args = parser.parse_args(args) licenses = license_list() @@ -54,11 +57,15 @@ print_licenses(licenses) license = licenses[options.license]() + + if options._print: + license.print_license() + sys.exit(0) - + variables = license.obtain_variables() for directory in args: - filelist = files(directory) + license.interpolate(directory, variables) if __name__ == '__main__': main()