def __init__(self, archive_format=ZIP, prefix=None, description=None, predicate=None, client_id=None): """CollectionArchiveGenerator constructor. Args: archive_format: May be ArchiveCollectionGenerator.ZIP or ArchiveCollectionGenerator.TAR_GZ. Defaults to ZIP. prefix: Name of the folder inside the archive that will contain all the generated data. description: String describing archive's contents. It will be included into the auto-generated MANIFEST file. Defaults to 'Files archive collection'. predicate: If not None, only the files matching the predicate will be archived, all others will be skipped. The predicate receives a db.ClientPath as input. client_id: The client_id to use when exporting a flow results collection. Raises: ValueError: if prefix is None. """ super(Aff4CollectionArchiveGenerator, self).__init__() if archive_format == self.ZIP: self.archive_generator = utils.StreamingZipGenerator( compression=zipfile.ZIP_DEFLATED) elif archive_format == self.TAR_GZ: self.archive_generator = utils.StreamingTarGenerator() else: raise ValueError("Unknown archive format: %s" % archive_format) if not prefix: raise ValueError("Prefix can't be None.") self.prefix = prefix self.description = description or "Files archive collection" self.total_files = 0 self.archived_files = 0 self.ignored_files = [] self.failed_files = [] self.predicate = predicate or (lambda _: True) self.client_id = client_id
def __init__(self, flow: rdf_flow_objects.Flow, archive_format: ArchiveFormat): self.flow = flow self.archive_format = archive_format if archive_format == ArchiveFormat.ZIP: self.archive_generator = utils.StreamingZipGenerator( compression=zipfile.ZIP_DEFLATED) extension = "zip" elif archive_format == ArchiveFormat.TAR_GZ: self.archive_generator = utils.StreamingTarGenerator() extension = "tar.gz" else: raise ValueError(f"Unknown archive format: {archive_format}") self.prefix = "{}_{}_{}".format( flow.client_id.replace(".", "_"), flow.flow_id, flow.flow_class_name) self.filename = f"{self.prefix}.{extension}" self.num_archived_files = 0