def _prepare_to_export()

in client/securedrop_client/gui/actions.py [0:0]


    def _prepare_to_export(self) -> None:
        """
        (Re-)generates the conversation transcript and opens a confirmation dialog to export it
        alongside all the (attached) files that are downloaded, in the manner
        of the existing ExportWizard.
        """
        transcript_location = (
            Path(self.controller.data_dir)
            .joinpath(self._source.journalist_filename)
            .joinpath(TRANSCRIPT_FILENAME)
        )

        transcript = ConversationTranscript(self._source)
        safe_mkdir(transcript_location.parent)

        with open(transcript_location, "w", encoding="utf-8") as f:
            f.write(str(transcript))
            # Let this context lapse to ensure the file contents
            # are written to disk.

        downloaded_file_locations = [
            file.location(self.controller.data_dir)
            for file in self._source.files
            if self.controller.downloaded_file_exists(file, silence_errors=True)
        ]

        file_locations = downloaded_file_locations + [transcript_location]

        # Open the files to prevent them from being removed while
        # the archive is being created. Once the file objects go
        # out of scope, any pending file removal will be performed
        # by the operating system.
        with ExitStack() as stack:
            export_device = Export()
            files = [stack.enter_context(open(file_location)) for file_location in file_locations]

            file_count = len(files)
            if file_count == 1:
                summary = TRANSCRIPT_FILENAME
            else:
                summary = _("all files and transcript")

            if self._destination == ExportDestination.WHISTLEFLOW:
                whistleflow_dialog = WhistleflowDialog(
                    export_device,
                    summary,
                    [str(file_location) for file_location in file_locations],
                )
                whistleflow_dialog.exec()
            else:
                wizard = ExportWizard(
                    export_device,
                    summary,
                    [str(file_location) for file_location in file_locations],
                    QApplication.activeWindow(),
                )
                wizard.exec()