def main(args): try: epilog = '\nCommands:\n' import __main__ keys = __main__.__dict__.keys() keys.sort() for command in keys: if command.startswith('pub'): epilog += __main__.__dict__[command].__doc__ + '\n' parser = optparse.OptionParser(\ usage='%prog [options] command\n\nVersion\n %prog version ' \ + str(dws.__version__), formatter=dws.CommandsFormatter(), epilog=epilog) parser.add_option('--help-book', dest='helpBook', action='store_true', help='Print help in docbook format') parser.add_option('--version', dest='version', action='store_true', help='Print version information') parser.add_option('-n', dest='noexecute', action='store_true', help='Do not execute, run informative only.') parser.add_option('-v', dest='verbose', action='store_true', help='Verbose mode') options, args = parser.parse_args() if options.version: sys.stdout.write(args[0] + ' version ' + str(dws.__version__) \ + '\n') sys.exit(0) if options.helpBook: help_text = dws.StringIO() parser.print_help(help_text) dws.helpBook(help_text) sys.exit(0) if options.noexecute: global DO_NOT_EXECUTE DO_NOT_EXECUTE = True if options.verbose: global VERBOSE VERBOSE = True arg = args.pop(0) command = 'pub' + arg.capitalize() if command in __main__.__dict__: __main__.__dict__[command](args) else: raise dws.Error(args[0] + ' ' + arg + ' does not exist.\n') except dws.Error as err: sys.stderr.write(str(err)) sys.exit(err.code)
parser.add_option('-n', dest='noexecute', action='store_true', help='Do not execute, run informative only.') parser.add_option('-v', dest='verbose', action='store_true', help='Verbose mode') options, args = parser.parse_args() if options.version: sys.stdout.write(sys.argv[0] + ' version ' + str(__version__) \ + '\n') sys.exit(0) if options.helpBook: import cStringIO help = cStringIO.StringIO() parser.print_help(help) dws.helpBook(help) sys.exit(0) if options.noexecute: doNotExecute = True if options.verbose: verbose = True arg = args.pop(0) command = 'pub' + arg.capitalize() if command in __main__.__dict__: __main__.__dict__[command](args) else: raise dws.Error(sys.argv[0] + ' ' + arg + ' does not exist.\n') except dws.Error as err: sys.stderr.write(str(err))
+ '\n') sys.exit(0) if options.helpBook: import cStringIO # We donot want to install dws.py alongside dws in *binDir* and rely # on the search path to find it. Thus dws is imported directly through # a load_source() command here. dwsDerivePath \ = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'dws') if os.path.exists(dwsDerivePath): import imp dws = imp.load_source('dws',dwsDerivePath) else: import tero as dws help = cStringIO.StringIO() parser.print_help(help) dws.helpBook(help) sys.exit(0) if len(args) < 1: parser.print_help() sys.exit(1) timeout = 10 if options.timeout: timeout = int(options.timeout) sys.exit(timeoutCommand(args, timeout, options.showPID))