Skip to content

Commit

Permalink
Merge pull request #19644 from Ultimaker/CURA-12138-Export_for_suppor…
Browse files Browse the repository at this point in the history
…t_option

Cura 12138 export for support option
  • Loading branch information
HellAholic authored Oct 7, 2024
2 parents d7d5131 + faea6a2 commit b9344f2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
25 changes: 22 additions & 3 deletions plugins/3MFWriter/ThreeMFWorkspaceWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
from threading import Lock
import zipfile
from typing import Dict, Any
from pathlib import Path
from zipfile import ZipFile

from UM.Application import Application
from UM.Logger import Logger
from UM.PluginRegistry import PluginRegistry
from UM.Preferences import Preferences
from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Workspace.WorkspaceWriter import WorkspaceWriter
Expand All @@ -33,7 +36,7 @@ def setExportModel(self, model: SettingsExportModel) -> None:
if self._ucp_model != model:
self._ucp_model = model

def _write(self, stream, nodes, mode=WorkspaceWriter.OutputMode.BinaryMode):
def _write(self, stream, nodes, mode, include_log):
application = Application.getInstance()
machine_manager = application.getMachineManager()

Expand Down Expand Up @@ -79,6 +82,11 @@ def _write(self, stream, nodes, mode=WorkspaceWriter.OutputMode.BinaryMode):
if self._ucp_model is not None:
user_settings_data = self._getUserSettings(self._ucp_model)
ThreeMFWriter._storeMetadataJson(user_settings_data, archive, USER_SETTINGS_PATH)

# Write log file
if include_log:
ThreeMFWorkspaceWriter._writeLogFile(archive)

except PermissionError:
self.setInformation(catalog.i18nc("@error:zip", "No permission to write the workspace here."))
Logger.error("No permission to write workspace to this stream.")
Expand Down Expand Up @@ -125,8 +133,8 @@ def _write(self, stream, nodes, mode=WorkspaceWriter.OutputMode.BinaryMode):

return True

def write(self, stream, nodes, mode=WorkspaceWriter.OutputMode.BinaryMode):
success = self._write(stream, nodes, mode=WorkspaceWriter.OutputMode.BinaryMode)
def write(self, stream, nodes, mode=WorkspaceWriter.OutputMode.BinaryMode, **kwargs):
success = self._write(stream, nodes, WorkspaceWriter.OutputMode.BinaryMode, kwargs.get("include_log", False))
self._ucp_model = None
return success

Expand Down Expand Up @@ -191,6 +199,17 @@ def _writeContainerToArchive(container, archive):
Logger.error("File became inaccessible while writing to it: {archive_filename}".format(archive_filename = archive.fp.name))
return

@staticmethod
def _writeLogFile(archive: ZipFile) -> None:
"""Helper function that writes the Cura log file to the archive.
:param archive: The archive to write to.
"""
file_logger = PluginRegistry.getInstance().getPluginObject("FileLogger")
file_logger.flush()
for file_path in file_logger.getFilesPaths():
archive.write(file_path, arcname=f"log/{Path(file_path).name}")

@staticmethod
def _getUserSettings(model: SettingsExportModel) -> Dict[str, Dict[str, Any]]:
user_settings = {}
Expand Down
22 changes: 22 additions & 0 deletions resources/qml/Actions.qml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Item
property alias paste: pasteAction
property alias copy: copyAction
property alias cut: cutAction
property alias exportProjectForSupport: exportProjectForSupportAction

readonly property bool copy_paste_enabled: {
const all_enabled_packages = CuraApplication.getPackageManager().allEnabledPackages;
Expand Down Expand Up @@ -549,4 +550,25 @@ Item
text: "&Marketplace"
icon.name: "plugins_browse"
}

Action
{
id: exportProjectForSupportAction
text: catalog.i18nc("@action:inmenu menubar:help", "Export Package For Technical Support")
onTriggered:
{
var exportName = Qt.formatDateTime(new Date(), "'export-'yyyyMMdd-HHmmss")
var args = {
"filter_by_machine": false,
"file_type": "workspace",
"preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
"limit_mimetypes": ["application/vnd.ms-package.3dmanufacturing-3dmodel+xml"],
"silent_save": true,
"writer_args": {
"include_log": true
}
};
UM.OutputDeviceManager.requestWriteToDevice("local_file", exportName, args)
}
}
}
2 changes: 2 additions & 0 deletions resources/qml/Menus/HelpMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Cura.Menu
Cura.MenuItem { action: Cura.Actions.reportBug }
Cura.MenuItem { action: Cura.Actions.openSponsershipPage }
Cura.MenuSeparator { }
Cura.MenuItem { action: Cura.Actions.exportProjectForSupport }
Cura.MenuSeparator { }
Cura.MenuItem { action: Cura.Actions.whatsNew }
Cura.MenuItem { action: Cura.Actions.about }
}

0 comments on commit b9344f2

Please sign in to comment.