def __init__(self, host, port, version, effective_user=None, use_sasl=False): '''SocketRpcChannel to connect to a socket server on a user defined port. It possible to define version and effective user for the communication.''' self.host = host self.port = port self.sock = None self.call_id = -3 # First time (when the connection context is sent, the call_id should be -3, otherwise start with 0 and increment) self.version = version self.client_id = str(uuid.uuid4()) self.use_sasl = use_sasl if self.use_sasl: if not _kerberos_available: raise Exception( "Kerberos libs not found. Please install snakebite using 'pip install snakebite[kerberos]'" ) kerberos = Kerberos() self.effective_user = effective_user or kerberos.user_principal( ).name else: self.effective_user = effective_user or get_current_username()
def _add_subparsers(self): default_dir = os.path.join("/user", get_current_username()) #sub-options arg_parsers = {} for opt_name, opt_data in self.SUB_OPTS.items(): arg_parsers[opt_name] = argparse.ArgumentParser(add_help=False) arg_parsers[opt_name].add_argument(opt_data['short'], opt_data['long'], help=opt_data['help'], action=opt_data['action']) subcommand_help_parser = argparse.ArgumentParser(add_help=False) subcommand_help_parser.add_argument('-H', '--help', action='store_true') # NOTE: args and dirs are logically equivalent except for default val. # Difference in naming gives more valuable error/help output. # 0 or more dirs positional_arg_parsers = {} positional_arg_parsers['[dirs]'] = argparse.ArgumentParser(add_help=False) positional_arg_parsers['[dirs]'].add_argument('dir', nargs='*', default=[default_dir], help="[dirs]") # 1 or more dirs positional_arg_parsers['dir [dirs]'] = argparse.ArgumentParser(add_help=False) positional_arg_parsers['dir [dirs]'].add_argument('dir', nargs='+', default=[default_dir], help="dir [dirs]") # 2 dirs positional_arg_parsers['src dst'] = argparse.ArgumentParser(add_help=False) positional_arg_parsers['src dst'].add_argument('src_dst', nargs=2, default=[default_dir], help="src dst") # 1 or more args positional_arg_parsers['[args]'] = argparse.ArgumentParser(add_help=False) positional_arg_parsers['[args]'].add_argument('arg', nargs='*', help="[args]") # 1 arg positional_arg_parsers['arg'] = argparse.ArgumentParser(add_help=False) positional_arg_parsers['arg'].add_argument('single_arg', default=default_dir, help="arg") # 1 (integer) arg positional_arg_parsers['(int) arg'] = argparse.ArgumentParser(add_help=False) positional_arg_parsers['(int) arg'].add_argument('single_int_arg', default='0', help="(integer) arg", type=int) subparsers = self.parser.add_subparsers() for cmd_name, cmd_info in Commands.methods.items(): parents = [arg_parsers[opt] for opt in cmd_info['allowed_opts'] if opt in arg_parsers] parents += [subcommand_help_parser] if 'req_args' in cmd_info and not cmd_info['req_args'] is None: parents += [positional_arg_parsers[arg] for arg in cmd_info['req_args']] command_parser = subparsers.add_parser(cmd_name, add_help=False, parents=parents) command_parser.set_defaults(command=cmd_name)
def __init__(self, host, port, version, effective_user=None, use_sasl=False): '''SocketRpcChannel to connect to a socket server on a user defined port. It possible to define version and effective user for the communication.''' self.host = host self.port = port self.sock = None self.call_id = -3 # First time (when the connection context is sent, the call_id should be -3, otherwise start with 0 and increment) self.version = version self.client_id = str(uuid.uuid4()) self.use_sasl = use_sasl if self.use_sasl: kerberos = Kerberos() self.effective_user = effective_user or kerberos.user_principal().name else: self.effective_user = effective_user or get_current_username()
def __init__(self, host, port, version, effective_user=None, use_sasl=False, hdfs_namenode_principal=None): '''SocketRpcChannel to connect to a socket server on a user defined port. It possible to define version and effective user for the communication.''' self.host = host self.port = port self.sock = None self.call_id = -3 # First time (when the connection context is sent, the call_id should be -3, otherwise start with 0 and increment) self.version = version self.client_id = str(uuid.uuid4()) self.use_sasl = use_sasl self.hdfs_namenode_principal = hdfs_namenode_principal if self.use_sasl: if not _kerberos_available: raise FatalException("Kerberos libs not found. Please install snakebite using 'pip install snakebite[kerberos]'") kerberos = Kerberos() self.effective_user = effective_user or kerberos.user_principal().name else: self.effective_user = effective_user or get_current_username()
def setUp(self): self.parser = CommandLineParser() self.default_dir = os.path.join("/user", get_current_username())
def setUp(self): super(DeleteWithTrashTest, self).setUp() self.client.use_trash = True self.username = get_current_username() self.trash_location = "/user/%s/.Trash/Current" % self.username