def createTable(name, column_name=None, is_subtable=False): """ :param str name: str table name :param str or list column_name: column(s) to create :param bool is_subtable: true if table is a subtable :return: Table object """ if column_name is None: colnms = [] elif isinstance(column_name, list): colnms = column_name else: colnms = [column_name] table = DTTable(name) factor = 1 for colnm in colnms: column = cl.Column(colnm) values = [factor * n for n in range(5)] factor += 1 column.addCells(values, replace=True) table.addColumn(column) if not is_subtable: versioned_file = VersionedFile(TABLE_FILEPATH, TEST_DIR, MAX_VERSIONS) table.setVersionedFile(versioned_file) api_util.writeObjectToFile(table, TABLE_FILEPATH) return table
def create(self): """ Creates Table file and the table """ if os.path.exists(self._full_path): self.table = api_util.readObjectFromFile(self._full_path) self.table.setFilepath(self._full_path) # Set before write else: self.table = DTTable(self._table_name) self.table.setFilepath(self._full_path) # Set before write api_util.writeObjectToFile(self.table)