def Handle(self, args, token=None): flow_api_object, flow_results = self._GetFlow(args, token) description = ("Files downloaded by flow %s (%s) that ran on client %s by " "user %s on %s" % (flow_api_object.name, args.flow_id, args.client_id, flow_api_object.creator, flow_api_object.started_at)) target_file_prefix = "%s_flow_%s_%s" % ( args.client_id, flow_api_object.name, str( flow_api_object.flow_id).replace(":", "_")) if args.archive_format == args.ArchiveFormat.ZIP: archive_format = archive_generator.CollectionArchiveGenerator.ZIP file_extension = ".zip" elif args.archive_format == args.ArchiveFormat.TAR_GZ: archive_format = archive_generator.CollectionArchiveGenerator.TAR_GZ file_extension = ".tar.gz" else: raise ValueError("Unknown archive format: %s" % args.archive_format) generator = archive_generator.CompatCollectionArchiveGenerator( prefix=target_file_prefix, description=description, archive_format=archive_format, predicate=self._BuildPredicate(unicode(args.client_id), token=token), client_id=args.client_id.ToClientURN()) content_generator = self._WrapContentGenerator( generator, flow_results, args, token=token) return api_call_handler_base.ApiBinaryStream( target_file_prefix + file_extension, content_generator=content_generator)
def _GenerateArchive( self, collection, archive_format=archive_generator.CollectionArchiveGenerator.ZIP, predicate=None): fd_path = os.path.join(self.temp_dir, "archive") generator = archive_generator.CompatCollectionArchiveGenerator( archive_format=archive_format, predicate=predicate, prefix="test_prefix", description="Test description", client_id=self.client_id) with open(fd_path, "wb") as out_fd: for chunk in generator.Generate(collection, token=self.token): out_fd.write(chunk) return fd_path