Exemplo n.º 1
0
def force_encoding(encoding):
    """
    Force locale to use specific encoding and bind output streams to use it.
    """
    current_locale = locale.getlocale()[0] or locale.getdefaultlocale()[0]
    if current_locale:
        locale.setlocale(locale.LC_ALL, str(current_locale)+'.'+str(encoding))
    else:
        locale.setlocale(locale.LC_ALL, 'C')
    sys.stdout = encode_stream(sys.stdout, encoding)
    sys.stderr = encode_stream(sys.stderr, encoding)
Exemplo n.º 2
0
    def __init__(self, admin_cli):
        # remove stdout stream encoding while in 'shell' mode, becuase this breaks readline
        # (autocompletion and shell history). In 'shell' mode the stdout
        # is encoded just for time necessary for command execution see precmd a postcmd

        sys.stdout = stdout_origin
        self.stdout_with_codec = encode_stream(sys.stdout, "utf-8")

        self.completion_matches = None
        Cmd.__init__(self)
        self.admin_cli = admin_cli
        self.completion = Completion(self.admin_cli)
        try:
            Config()
            self.prompt = Config.parser.get('shell', 'prompt') + ' '
        except (ConfigFileError, ConfigParser.Error):
            self.prompt = 'katello> '

        try:
            # don't split on hyphens during tab completion (important for completing parameters)
            newdelims = readline.get_completer_delims()
            newdelims = re.sub('-', '', newdelims)
            readline.set_completer_delims(newdelims)

            if (Config.parser.get('shell', 'nohistory').lower() != 'true'):
                self.__init_history()
        except ConfigParser.Error:
            pass
        self.__init_commands()
Exemplo n.º 3
0
    def __init__(self, admin_cli):
        # remove stdout stream encoding while in 'shell' mode, becuase this breaks readline
        # (autocompletion and shell history). In 'shell' mode the stdout
        # is encoded just for time necessary for command execution see precmd a postcmd

        sys.stdout = stdout_origin
        self.stdout_with_codec = encode_stream(sys.stdout, "utf-8")

        self.completion_matches = None
        Cmd.__init__(self)
        self.admin_cli = admin_cli
        self.completion = Completion(self.admin_cli)
        try:
            Config()
            self.prompt = Config.parser.get('shell', 'prompt') + ' '
        except (ConfigFileError, ConfigParser.Error):
            self.prompt = 'katello> '

        try:
            # don't split on hyphens during tab completion (important for completing parameters)
            newdelims = readline.get_completer_delims()
            newdelims = re.sub('-', '', newdelims)
            readline.set_completer_delims(newdelims)

            if (Config.parser.get('shell', 'nohistory').lower() != 'true'):
                self.__init_history()
        except ConfigParser.Error:
            pass
        self.__init_commands()
Exemplo n.º 4
0
    def __init__(self, cli, prompt="> ", use_history=True, history_file=None):
        # remove stdout stream encoding while in 'shell' mode, becuase this breaks readline
        # (autocompletion and shell history). In 'shell' mode the stdout
        # is encoded just for time necessary for command execution see precmd a postcmd

        sys.stdout = stdout_origin
        self.stdout_with_codec = encode_stream(sys.stdout, "utf-8")

        self.completion_matches = None
        Cmd.__init__(self)
        self.cli = cli
        self.completion = Completion(self.cli.root_section)
        self.prompt = prompt
        self.history_file = history_file

        # don't split on hyphens during tab completion (important for completing parameters)
        newdelims = readline.get_completer_delims()
        newdelims = re.sub('-', '', newdelims)
        readline.set_completer_delims(newdelims)

        if use_history:
            self.__init_history()
        self.__init_commands()