Source code for sylib.library.plugins.export.datasource_exporters.plugin_tar_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 tarfile
from sylib.export import datasource as importdatasource
[docs]
class DataArchiveTar(importdatasource.DatasourceArchiveBase):
"""Archiver for TAR files. Takes all datasources in input and puts
them in one (uncompressed) TAR file. Folder structure is discarded.
"""
EXPORTER_NAME = "TAR Archiver"
FILENAME_EXTENSION = 'tar'
@staticmethod
def hide_filename():
return False
def export_data(self, in_datasources, location, progress=None):
if len(in_datasources):
with tarfile.open(location, 'w') as f:
for ds in in_datasources:
path = ds.decode_path()
f.add(path, os.path.basename(path))
return [location]
def create_filenames(self, input_list, filename, *args):
return super().create_filenames(
input_list, filename, *args)
def cardinality(self):
return self.many_to_one