def main(): parser = optparse.OptionParser(usage=makeHelp([])) config.toOptionParser(parser=parser) parser.disable_interspersed_args() # For future support of commands with args. if len(sys.argv) >= 2 and not sys.argv[1].startswith("-"): configFilename = sys.argv.pop(1) try: fp = open(configFilename) except EnvironmentError, e: util.error("Could not open configuration file %r: %s" % (configFilename, e)) config.read(configFilename) config.readenv() # config.writefp(sys.stdout) cmds = [getattr(commands, name)(config) for name in commands.commands] for child in config.commands.arbitrary.children(): cmds.append(commands.ArbitraryCommand(config, name)) parser.set_usage(makeHelp(cmds, configFilename))
def main(): parser = optparse.OptionParser(usage=makeHelp([])) config.toOptionParser(parser=parser) parser.disable_interspersed_args( ) # For future support of commands with args. if len(sys.argv) >= 2 and not sys.argv[1].startswith('-'): configFilename = sys.argv.pop(1) try: fp = open(configFilename) except EnvironmentError, e: util.error('Could not open configuration file %r: %s' % (configFilename, e)) config.read(configFilename) config.readenv() #config.writefp(sys.stdout) cmds = [getattr(commands, name)(config) for name in commands.commands] for child in config.commands.arbitrary.children(): cmds.append(commands.ArbitraryCommand(config, name)) parser.set_usage(makeHelp(cmds, configFilename))
parser.error("A configuration file must be provided.") (options, args) = parser.parse_args() try: commandName = args.pop(0) except (ValueError, IndexError): # Unpack list of wrong size parser.error("A command must be provided.") if configFilename.startswith("/"): absoluteConfigFilename = configFilename else: absoluteConfigFilename = os.path.join(os.getcwd(), configFilename) syslog.openlog("%s %s" % (os.path.basename(sys.argv[0]), absoluteConfigFilename)) try: (command,) = [cmd for cmd in cmds if cmd.name == commandName] except ValueError: # unpack list of wrong size parser.error("Invalid command: %r" % commandName) try: command.checkConfig(config) except commands.InvalidConfiguration, e: util.error("Invalid configuration: %s" % e) environ = makeEnvironment(config) command.run(args, environ) if __name__ == "__main__": main()
(options, args) = parser.parse_args() try: commandName = args.pop(0) except (ValueError, IndexError): # Unpack list of wrong size parser.error('A command must be provided.') if configFilename.startswith('/'): absoluteConfigFilename = configFilename else: absoluteConfigFilename = os.path.join(os.getcwd(), configFilename) syslog.openlog('%s %s' % (os.path.basename(sys.argv[0]), absoluteConfigFilename)) try: (command, ) = [cmd for cmd in cmds if cmd.name == commandName] except ValueError: # unpack list of wrong size parser.error('Invalid command: %r' % commandName) try: command.checkConfig(config) except commands.InvalidConfiguration, e: util.error('Invalid configuration: %s' % e) environ = makeEnvironment(config) command.run(args, environ) if __name__ == '__main__': main()