def create_context_and_executor(out, err, args): arg_parser = create_command_argument_parser(__file__) log = create_logger(True) options = arg_parser.parse_args(args) context = CommandContext(options.command, options.__dict__, out, err) hosts = check_hosts(options.__dict__, log, arg_parser.format_usage) return context, CommandExecutor(context, log, hosts)
def __init__( self, command, command_args, login_password, sudo_password, timeout = DEFAULT_TIMEOUT, expect_delay = DEFAULT_EXPECT_DELAY, debug_enabled = False, expect = None, expect_out = None ): self.login_password = login_password self.sudo_password = sudo_password self.timeout = timeout self.expect_delay = expect_delay self.log = create_logger(None, debug_enabled) self.expect_patterns = [ b('^Enter passphrase.+'), b('[Pp]assword[^\n]*:'), u('パスワード').encode('utf-8'), # TODO: japanese character expected as utf-8 ] if expect_out is None: #expect_out = StringIO() expect_out = BytesIO() if expect is None: self.expect = pexpect.spawn( command, command_args, timeout = timeout, logfile = expect_out ) else: self.expect = expect self.expect_out = expect_out self.log.debug("command = %s, command_args = %s" % (command, str(command_args)))
def __init__(self, script_path): self.script_path = script_path self.arg_parser = self.create_argument_parser(script_path) self.options = self.arg_parser.parse_args(sys.argv[1:]) conf_options = None if self.options.conf: conf_options = get_options_from_conf( os.path.basename(script_path), self.options.conf ) args = conf_options + sys.argv[1:] # Re-parse command line options because conf_options added self.options = self.arg_parser.parse_args(args) self.log = create_logger( None, self.options.debug or self.options.deep_debug, self.options.deep_debug ) if conf_options: self.log.debug("Applying options %s from %s" % (str(conf_options), self.options.conf))
def __init__(self, context, log=None): self.context = context if log is None: self.log = create_logger(context.options.get('debug')) else: self.log = log
def __init__(self, script_path): self.script_path = script_path self.arg_parser = self.create_argument_parser(script_path) self.options = self.arg_parser.parse_args() self.log = create_logger(self.options.debug)