Source code for sylib.export.table

# This file is part of Sympathy for Data.
# Copyright (c) 2017, Combine Control Systems AB
#
# SYMPATHY FOR DATA COMMERCIAL LICENSE
# You should have received a link to the License with Sympathy for Data.
import os
from sympathy.api import exporters
from sympathy.api.exceptions import sywarn, NoDataError


def check_filenames(filenames, input_length: int):
    filenames = list(filenames)
    return len(filenames) == len(set(filenames)) == input_length


[docs] class TableDataExporterBase(exporters.DataExporterBase): @staticmethod def plugin_base_name(): return 'Export Table' def create_filenames(self, input_list, filename, *args): """ Base implementation of create_filenames. Please override for custom behavior. """ if not self.file_based(): return super().create_filenames(input_list, filename) elif ('table_names' in self._parameters and self._parameters['table_names'].value): ext = self._parameters['filename_extension'].value if ext != '': ext = '{}{}'.format(os.path.extsep, ext) try: filenames = ['{}{}'.format( t.get_name(), ext) for t in input_list if t.get_name() is not None] if check_filenames(filenames, len(input_list)): return (filename for filename in filenames) else: sywarn( 'The Tables in the incoming list do not ' 'have unique names. The table names are ' 'therefore not used as filenames.') except (OSError, NoDataError): pass return super().create_filenames( input_list, filename, *args)