Changeset 3316
- Timestamp:
- 02/02/08 14:05:12 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/commandline.py
r3315 r3316 39 39 """ 40 40 self.examples = [] 41 kwargs["version"] = "%s (PyKota) %s" % (os.path.basename(sys.argv[0]), 42 version.__version__) 41 43 optparse.OptionParser.__init__(self, *args, **kwargs) 42 44 self.disable_interspersed_args() 45 self.remove_version_and_help() 43 46 self.add_generic_options() 44 47 … … 56 59 return "".join(result) 57 60 58 def parse_args(self, args=None, values=None) :59 """Parses command line arguments, and handles -v|--version as well."""60 (options, arguments) = optparse.OptionParser.parse_args(self, args, values)61 self.handle_generic_options(options)62 return (options, arguments)63 64 61 # 65 62 # Below are PyKota specific additions … … 98 95 self.examples.append(("%prog " + command, doc)) 99 96 97 def remove_version_and_help(self) : 98 """Removes the default definitions for options version and help.""" 99 for o in ("-h", "-help", "--help", "-v", "-version", "--version") : 100 try : 101 self.remove_option(o) 102 except ValueError : 103 pass 104 100 105 def add_generic_options(self) : 101 106 """Adds options which are common to all PyKota command line tools.""" 107 self.add_option("-h", "--help", 108 action="help", 109 help=_("show this help message and exit")) 102 110 self.add_option("-v", "--version", 103 action="store_true", 104 dest="version", 111 action="version", 105 112 help=_("show the version number and exit")) 106 107 def handle_generic_options(self, options) :108 """Handles options which are common to all PyKota command line tools."""109 if options.version :110 sys.stdout.write("%s (PyKota) %s\n" % (os.path.basename(sys.argv[0]),111 version.__version__))112 sys.exit(0)