add --license option

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2663 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2005-06-16 13:04:16 +00:00
parent a2223358d1
commit 55d631e77a

View file

@ -19,14 +19,7 @@
#
# Changes by Bastian Kleineidam:
#
# - Added command line options:
# --charset STRING
# Specify output character set for generated files. The
# output files will be encoded with the given character set.
# --copyright STRING
# Add given copyright notice as comment
# --threads
# Call gtk.gdk.threads_init() in the main() routine
# - Added command line options (see usage() function)
# - Regenerate helper module if this code generator was modified
# - Use sys.executable as interpreter name
@ -51,13 +44,14 @@ from xml.sax._exceptions import SAXParseException
config = {
"charset": locale.getpreferredencoding(),
"copyright": u"Copyright (C) %d" % datetime.date.today().year,
"license": u"",
"threads": u"pass",
"interpreter": unicode(sys.executable)
}
def read_config (args):
preferred_encoding = config["charset"]
longopts = ["threads", "charset=", "copyright="]
longopts = ["threads", "charset=", "copyright=", "license="]
opts, args = getopt.getopt(args, "", longopts)
for opt, arg in opts:
if opt == "--threads":
@ -71,6 +65,13 @@ def read_config (args):
except LookupError:
raise getopt.GetoptError("Unknown charset %r" % arg)
config["charset"] = charset
elif opt == "--license":
fo = codecs.open(arg, "r", preferred_encoding)
try:
content = fo.read()
finally:
fo.close()
config["license"] = content
return args
@ -78,6 +79,7 @@ header_format = u"""\
#!%(interpreter)s
# -*- coding: %(charset)s -*-
# %(copyright)s
%(license)s
# Python module %(module)s.py
# Autogenerated from %(glade)s
@ -294,6 +296,7 @@ class SimpleGladeCodeWriter (xml.sax.handler.ContentHandler):
fo.write(self.code)
finally:
fo.close()
print "Wrote", self.output_file
except IOError, e:
print >> sys.stderr, "Error writing output:", e
return None
@ -311,6 +314,8 @@ Options:
Write files in given charset and add coding line.
--copyright=STRING
Write given copyright string after coding line.
--license=FILENAME
Add contents of given filename below copyright.
--threads
Call gtk.gdk.threads_init() before gtk.main().
""" % program
@ -403,7 +408,7 @@ def main (args):
fo.write(SimpleGladeApp_content % config)
finally:
fo.close()
print "Wrote", output_file
print "Wrote", helper_module
return 0