From 55d631e77aaa4f8aef05fe2c58ac386c8d403200 Mon Sep 17 00:00:00 2001 From: calvin Date: Thu, 16 Jun 2005 13:04:16 +0000 Subject: [PATCH] add --license option git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2663 e7d03fd6-7b0d-0410-9947-9c21f3af8025 --- gui/simple-glade-codegen.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/gui/simple-glade-codegen.py b/gui/simple-glade-codegen.py index b01d6d4b..65e60e3f 100644 --- a/gui/simple-glade-codegen.py +++ b/gui/simple-glade-codegen.py @@ -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