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

# 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 shutil
import gzip
from sylib.export import datasource as importdatasource


[docs] class DataArchiveGz(importdatasource.DatasourceArchiveBase): """Compressor for GZIP files""" EXPORTER_NAME = "GZIP Compressor" FILENAME_EXTENSION = 'gz' @staticmethod def hide_filename(): return True def export_data(self, in_datasource, filename, progress=None): in_file = in_datasource.decode_path() with open(in_file, 'rb') as i_f, gzip.open(filename, 'wb') as o_f: shutil.copyfileobj(i_f, o_f) return [filename] def create_filenames(self, input_list, filename, *args): return ['{}.{}'.format( os.path.basename(path.decode_path()), self.FILENAME_EXTENSION) for path in input_list]