Exemplo n.º 1
0
    def _ParseIndex(self, preread, precompile):
        """Reads index file and stores entries in TextTable.
    For optimisation reasons, a second table is created with compiled entries.
    Args:
      preread: func, Pre-processing, applied to each field as it is read.
      precompile: func, Pre-compilation, applied to each field before compiling.
    Raises:
      IndexTableError: If the column headers has illegal column labels.
    """
        self.index = texttable.TextTable()
        self.index.CsvToTable(self._index_handle)

        if preread:
            for row in self.index:
                for col in row.header:
                    row[col] = preread(col, row[col])

        self.compiled = copy.deepcopy(self.index)

        for row in self.compiled:
            for col in row.header:
                if precompile:
                    row[col] = precompile(col, row[col])
                if row[col]:
                    row[col] = copyable_regex_object.CopyableRegexObject(
                        row[col])
Exemplo n.º 2
0
    def _ParseCmdItem(self, cmd_input, template_file=None):
        """Creates Texttable with output of command.
    Args:
      cmd_input: String, Device response.
      template_file: File object, template to parse with.
    Returns:
      TextTable containing command output.
    Raises:
      CliTableError: A template was not found for the given command.
    """
        # Build FSM machine from the template.
        fsm = textfsm.TextFSM(template_file)
        if not self._keys:
            self._keys = set(fsm.GetValuesByAttrib("Key"))

        # Pass raw data through FSM.
        table = texttable.TextTable()
        table.header = fsm.header

        # Fill TextTable from record entries.
        for record in fsm.ParseText(cmd_input):
            table.Append(record)
        return table