Example #1
0
    def handle_create_parser(self) -> None:
        temp_parser = Parser()

        # Render text
        self.current_end = 0
        self.messages = constants.CREATE_PARSER_MESSAGES
        self.previous_render = None  # Force render
        self.render_text_in_output()
        # Get type
        self.activate_prompt()
        parser_type = None
        while parser_type not in {'regex', 'split'}:
            self.activate_prompt()
            parser_type = self.box.gather().strip()

        # Handle next step
        self.messages = [f'Parser type {parser_type}']
        self.messages.append(constants.PARSER_SET_NAME)
        self.previous_render = None  # Force render
        self.render_text_in_output()
        # Get name
        self.activate_prompt()
        parser_name = self.box.gather().strip()

        # Handle next step
        self.messages.append(f'Parser name {parser_name}')
        self.messages.append(constants.PARSER_SET_EXAMPLE)
        self.previous_render = None  # Force render
        self.render_text_in_output()
        # Get example
        self.activate_prompt()
        parser_example = self.box.gather().strip()

        # Handle next step
        self.messages.append(f'Parser example {parser_example}')
        self.messages.append(constants.PARSER_SET_PATTERN)
        self.previous_render = None  # Force render
        self.render_text_in_output()
        # Get pattern
        self.activate_prompt()
        parser_pattern = self.box.gather()

        # Set the parser's data
        temp_parser.set_pattern(parser_pattern, parser_type, parser_name,
                                parser_example, {})

        # Determine the analytics dict
        parts = temp_parser.parse(parser_example)
        analytics = {part: 'count' for part in parts}

        # Set the parser's data with analytics
        temp_parser.set_pattern(parser_pattern, parser_type, parser_name,
                                parser_example, analytics)

        self.messages = temp_parser.as_list()
        self.messages.append(constants.SAVE_CURRENT_PATTERN)
        self.previous_render = None  # Force render
        self.render_text_in_output()
        self.activate_prompt()
        final_res = self.box.gather().strip()
        if final_res == ':q':
            return
        temp_parser.save()
        self.messages = []
Example #2
0
def handle_create_parser(logria: 'Logria') -> None:  # type: ignore
    """
    Get user input to create a session
    """
    temp_parser = Parser()

    # Render text
    logria.current_end = 0
    logria.messages = constants.CREATE_PARSER_MESSAGES
    logria.redraw()
    # Get type
    logria.activate_prompt()
    parser_type: str = ''
    while parser_type not in {'regex', 'split'}:
        logria.activate_prompt()
        parser_type = logria.box.gather().strip()
        if parser_type == ':q':
            logria.stop()
            return

    # Handle next step
    logria.messages = [f'Parser type {parser_type}']
    logria.messages.append(constants.PARSER_SET_NAME)
    logria.redraw()
    # Get name
    logria.activate_prompt()
    parser_name = logria.box.gather().strip()
    if parser_name == ':q':
        logria.stop()
        return

    # Handle next step
    logria.messages.append(f'Parser name {parser_name}')
    logria.messages.append(constants.PARSER_SET_EXAMPLE)
    logria.redraw()
    # Get example
    logria.activate_prompt()
    parser_example = logria.box.gather().strip()
    if parser_example == ':q':
        logria.stop()
        return

    # Handle next step
    logria.messages.append(f'Parser example {parser_example}')
    logria.messages.append(constants.PARSER_SET_PATTERN)
    logria.redraw()
    # Get pattern
    logria.activate_prompt()
    parser_pattern = logria.box.gather()
    if parser_pattern == ':q':
        logria.stop()
        return

    # Set the parser's data
    temp_parser.set_pattern(parser_pattern, parser_type, parser_name,
                            parser_example, {})

    # Determine the analytics dict
    parts = temp_parser.parse(parser_example)
    analytics = {part: 'count' for part in parts}

    # Set the parser's data with analytics
    temp_parser.set_pattern(parser_pattern, parser_type, parser_name,
                            parser_example, analytics)

    logria.messages = temp_parser.as_list()
    logria.messages.append(constants.SAVE_CURRENT_PATTERN)
    logria.redraw()
    logria.activate_prompt()
    final_res = logria.box.gather().strip()
    if final_res == ':q':
        return
    temp_parser.save()
    logria.messages = []