Esempio n. 1
0
def tabledata_from_dictlist(name, data):
    keys = set()
    for x in data:
        if type(x) == dict:
            for key in x.keys():
                keys.add(key)
        else:
            for key in x.__dict__.keys():
                keys.add(key)

    headers = list(keys)
    headers.sort()
    rows = []

    for obj in data:
        row_data = []
        for key in headers:
            if type(obj) == dict:
                target = obj
            else:
                target = obj.__dict__
            if key in target:
                row_data.append(target[key])
            else:
                row_data.append(None)
        rows.append(row_data)

    return tabledata.TableData(name, headers, rows)
Esempio n. 2
0
    def _write_table(self):
        self._verify_value_matrix()
        self._preprocess()

        table_data = tabledata.TableData(
            self.table_name, self.header_list,
            [[value_dp.data for value_dp in value_dp_list]
             for value_dp_list in self._table_value_dp_matrix])
        self.stream.create_table_from_tabledata(
            tabledata.SQLiteTableDataSanitizer(table_data).sanitize())
Esempio n. 3
0
    def _write_table(self):
        self._verify_value_matrix()
        self._preprocess()

        table_data = tabledata.TableData(
            self.table_name,
            self.headers,
            [[value_dp.data for value_dp in value_dp_list]
             for value_dp_list in self._table_value_dp_matrix],
            type_hints=self.type_hints,
        )
        self.stream.create_table_from_tabledata(table_data)
Esempio n. 4
0
def db_list(app, output_format, out_):
    """List all data."""
    headers = ["name", "dbkey", "s-type", "s-input"]
    rows = []
    for db in app.dbconfig.dbs.values():
        rows.append([
            db.value_of('name'),
            db.value_of('dbkey'),
            db.value_of('source.type'),
            db.value_of('source.input')
        ])
    td = tabledata.TableData("databases", headers, rows)
    writer = pytablewriter.TableWriterFactory.create_from_format_name(
        output_format)
    writer.from_tabledata(td)
    writer.stream = out_
    writer.write_table()
Esempio n. 5
0
    def _write_table(self, **kwargs) -> None:
        try:
            self._verify_value_matrix()
        except EmptyValueError:
            self._logger.logger.debug("no tabular data found")
            return

        self._preprocess()

        table_data = tabledata.TableData(
            self.table_name,
            self.headers,
            [[value_dp.data for value_dp in value_dp_list]
             for value_dp_list in self._table_value_dp_matrix],
            type_hints=self.type_hints,
            max_workers=self.max_workers,
        )
        self.stream.create_table_from_tabledata(table_data)
Esempio n. 6
0
    def _write_table(self, **kwargs) -> None:
        if not self.is_opened():
            self._logger.logger.error("required to open(file_path) first.")
            return

        try:
            self._verify_value_matrix()
        except EmptyValueError:
            self._logger.logger.debug("no tabular data found")
            return

        self._preprocess()

        table_data = tabledata.TableData(
            self.table_name,
            self.headers,
            [
                [value_dp.data for value_dp in value_dp_list]
                for value_dp_list in self._table_value_dp_matrix
            ],
            type_hints=self.type_hints,
            max_workers=self.max_workers,
        )
        table_data.as_dataframe().to_pickle(self.__filepath)