Source code for sylib.library.plugins.export.datasource_exporters.plugin_gz_exporter

# This file is part of Sympathy for Data.
# Copyright (c) 2015, 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
import gzip
from sympathy.api.exceptions import SyDataError
from sylib.export import datasource as exportdatasource


[docs] class DataExtractGz(exportdatasource.DatasourceArchiveBase): """Extractor for GZIP files.""" EXPORTER_NAME = "GZIP Extractor" FILENAME_EXTENSION = None @staticmethod def hide_filename(): return True def export_data(self, in_datasource, filename, progress=None): gz_file = in_datasource.decode_path() try: with gzip.open(gz_file, 'rb') as f: content = f.read() except gzip.BadGzipFile as e: raise SyDataError(f"Error extracting, due to: {e}.") from e with open(filename, 'wb') as f: f.write(content) return [filename] def create_filenames(self, input_list, filename, *args): return [os.path.splitext(os.path.basename(path.decode_path()))[0] for path in input_list]