Browse Source

Merge pull request #207 from adswa/helptab

Add diagnostic infos helper to help tag
Michael Hanke 2 years ago
parent
commit
1a88d13a36
2 changed files with 61 additions and 1 deletions
  1. 55 1
      datalad_gooey/app.py
  2. 6 0
      datalad_gooey/resources/ui/main_window.ui

+ 55 - 1
datalad_gooey/app.py

@@ -20,15 +20,22 @@ from PySide6.QtCore import (
     QObject,
     Qt,
     Signal,
+    Slot,
 )
 from PySide6.QtGui import (
     QAction,
     QCursor,
+    QGuiApplication,
 )
 
 from datalad import cfg as dlcfg
 from datalad import __version__ as dlversion
 import datalad.ui as dlui
+from datalad.interface.base import Interface
+from datalad.local.wtf import (
+    _render_report,
+    WTF,
+)
 from datalad.utils import chpwd
 
 from .utils import (
@@ -64,7 +71,8 @@ class GooeyApp(QObject):
         'actionCheck_for_new_version': QAction,
         'actionReport_a_problem': QAction,
         'actionAbout': QAction,
-        'actionGetHelp': QAction
+        'actionGetHelp': QAction,
+        'actionDiagnostic_infos': QAction,
     }
 
     execute_dataladcmd = Signal(str, MappingProxyType, MappingProxyType)
@@ -158,6 +166,11 @@ class GooeyApp(QObject):
             self._get_help)
         self.main_window.actionAbout.triggered.connect(
             self._get_info)
+        self.main_window.actionDiagnostic_infos.triggered.connect(
+            self._get_diagnostic_info)
+        # connect the diagnostic WTF helper
+        self._cmdexec.results_received.connect(
+            self._app_cmdexec_results_handler)
         # reset the command configuration tab whenever the item selection in
         # tree view changed.
         # This behavior was originally requested in
@@ -312,6 +325,47 @@ class GooeyApp(QObject):
               'datalad.org</a>.'
         mbox(self.main_window, title, msg)
 
+    def _get_diagnostic_info(self):
+        self.execute_dataladcmd.emit(
+            'wtf',
+            MappingProxyType(dict(
+                result_renderer='disabled',
+                on_failure='ignore',
+                return_type='generator',
+            )),
+            MappingProxyType(dict(
+                preferred_result_interval=0.2,
+                result_override=dict(
+                    secret_handshake=True,
+                ),
+            )),
+        )
+
+
+    @Slot(Interface, list)
+    def _app_cmdexec_results_handler(self, cls, res):
+        if cls != WTF:
+            return
+        for r in res:
+            self._wtf_result_receiver(r)
+
+    def _wtf_result_receiver(self, res):
+        if not res['action'] == 'wtf':
+            return
+        if not res.get('secret_handshake'):
+            return
+        if res['status'] != 'ok':
+            msg = "Internal error creating diagnostic information"
+        else:
+            msg = "Diagnostic information was copied to clipboard"
+            infos = _render_report(res)
+            clipboard = QGuiApplication.clipboard()
+            clipboard.setText(
+                f'<details><summary>Diagnostic infos</summary>\n\n'
+                f'```\n {infos}```\n</details>')
+        mbox = QMessageBox.information
+        mbox(self.main_window, 'Diagnostic infos', msg)
+
     def _connect_menu_view(self, menu: QMenu):
         for cfgvar, menuname, subject in (
                 ('datalad.gooey.active-suite', 'menuSuite', 'suite'),

+ 6 - 0
datalad_gooey/resources/ui/main_window.ui

@@ -258,6 +258,7 @@
     <addaction name="actionReport_a_problem"/>
     <addaction name="actionAbout"/>
     <addaction name="actionGetHelp"/>
+    <addaction name="actionDiagnostic_infos"/>
    </widget>
    <addaction name="menuFile"/>
    <addaction name="menuDataset"/>
@@ -309,6 +310,11 @@
     <string>Get help</string>
    </property>
   </action>
+  <action name="actionDiagnostic_infos">
+   <property name="text">
+    <string>Diagnostic infos</string>
+   </property>
+  </action>
  </widget>
  <resources/>
  <connections>