[gnome-builder] support: add action to generate support information



commit 9360f967787465280404d181401410c4814ee41c
Author: Christian Hergert <christian hergert me>
Date:   Fri Dec 26 17:13:22 2014 -0800

    support: add action to generate support information
    
    This script will get us some general information to help us track down
    a bug. It is intended to be attached to a bug report.
    
    We probably want to include some runtime logs as well. We will append to
    this as we find we need more information.

 src/app/gb-application.c   |   52 +++++++++++++++++
 src/gnome-builder.mk       |    3 +
 src/resources/gtk/menus.ui |   26 ++++++++-
 src/support/gb-support.c   |  131 ++++++++++++++++++++++++++++++++++++++++++++
 src/support/gb-support.h   |   30 ++++++++++
 5 files changed, 241 insertions(+), 1 deletions(-)
---
diff --git a/src/app/gb-application.c b/src/app/gb-application.c
index 816e463..4a8a009 100644
--- a/src/app/gb-application.c
+++ b/src/app/gb-application.c
@@ -31,6 +31,7 @@
 #include "gb-log.h"
 #include "gb-keybindings.h"
 #include "gb-preferences-window.h"
+#include "gb-support.h"
 #include "gb-resources.h"
 #include "gb-workbench.h"
 
@@ -442,10 +443,61 @@ gb_application_activate_preferences_action (GSimpleAction *action,
 }
 
 static void
+gb_application_activate_support_action (GSimpleAction *action,
+                                        GVariant      *parameter,
+                                        gpointer       user_data)
+{
+  GbApplication *application = user_data;
+  GtkWidget *dialog;
+  gchar *text = NULL;
+  GList *windows;
+  GError *error = NULL;
+  gchar *str = NULL;
+  gchar *log_path = NULL;
+  gchar *name = NULL;
+
+  name = g_strdup_printf ("gnome-builder-%u.log", (int)getpid ());
+  log_path = g_build_filename (g_get_home_dir (), name, NULL);
+  g_free (name);
+
+  windows = gtk_application_get_windows (GTK_APPLICATION (application));
+
+  str = gb_get_support_log ();
+
+  if (!g_file_set_contents (log_path, str, -1, &error))
+    {
+      g_printerr ("%s\n", error->message);
+      goto cleanup;
+    }
+
+  text = g_strdup_printf (_("The support log file has been written to '%s'. "
+                            "Please provide this file as an attachment on "
+                            "your bug report or support request."),
+                            log_path);
+
+  g_message ("%s", text);
+
+  dialog = gtk_message_dialog_new (windows ? windows->data : NULL,
+                                   GTK_DIALOG_DESTROY_WITH_PARENT,
+                                   GTK_MESSAGE_INFO,
+                                   GTK_BUTTONS_CLOSE,
+                                   "%s", text);
+  gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_destroy (dialog);
+
+cleanup:
+  g_free (text);
+  g_clear_error (&error);
+  g_free (str);
+  g_free (log_path);
+}
+
+static void
 gb_application_register_actions (GbApplication *self)
 {
   static const GActionEntry action_entries[] = {
     { "preferences", gb_application_activate_preferences_action },
+    { "support", gb_application_activate_support_action },
     { "quit", gb_application_activate_quit_action },
   };
 
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 2ccf562..49d32f1 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -177,6 +177,8 @@ libgnome_builder_la_SOURCES = \
        src/snippets/gb-source-snippets-manager.h \
        src/snippets/gb-source-snippets.c \
        src/snippets/gb-source-snippets.h \
+       src/support/gb-support.c \
+       src/support/gb-support.h \
        src/theatrics/gb-box-theatric.c \
        src/theatrics/gb-box-theatric.h \
        src/tree/gb-tree-builder.c \
@@ -245,6 +247,7 @@ libgnome_builder_la_CFLAGS = \
        -I$(top_srcdir)/src/scrolledwindow \
        -I$(top_srcdir)/src/search \
        -I$(top_srcdir)/src/snippets \
+       -I$(top_srcdir)/src/support \
        -I$(top_srcdir)/src/tree \
        -I$(top_srcdir)/src/trie \
        -I$(top_srcdir)/src/theatrics \
diff --git a/src/resources/gtk/menus.ui b/src/resources/gtk/menus.ui
index c3326af..0c35037 100644
--- a/src/resources/gtk/menus.ui
+++ b/src/resources/gtk/menus.ui
@@ -16,9 +16,18 @@
         <attribute name="action">app.help</attribute>
       </item>
       <item>
-        <attribute name="label" translatable="yes">_About</attribute>
+        <attribute name="label" translatable="yes">_About Builder</attribute>
         <attribute name="action">win.about</attribute>
       </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">Generate Support Log</attribute>
+        <attribute name="action">app.support</attribute>
+      </item>
+    </section>
+    <section>
+      <attribute name="id">quit-section</attribute>
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
@@ -86,6 +95,21 @@
       <submenu>
         <attribute name="label" translatable="yes">Tools</attribute>
       </submenu>
+      <submenu>
+        <attribute name="label" translatable="yes">Help</attribute>
+        <item>
+          <attribute name="label" translatable="yes">_Help</attribute>
+          <attribute name="action">app.help</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_About Builder</attribute>
+          <attribute name="action">win.about</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">Generate Support Log</attribute>
+          <attribute name="action">app.support</attribute>
+        </item>
+      </submenu>
     </section>
     <section>
       <attribute name="id">close-section</attribute>
diff --git a/src/support/gb-support.c b/src/support/gb-support.c
new file mode 100644
index 0000000..98150c0
--- /dev/null
+++ b/src/support/gb-support.c
@@ -0,0 +1,131 @@
+/* gb-support.c
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtk/gtk.h>
+#include <string.h>
+
+#include "gb-support.h"
+
+gchar *
+gb_get_support_log (void)
+{
+  GChecksum *checksum;
+  GDateTime *now;
+  GString *str;
+  gchar *tmp;
+  gchar **env;
+  guint i;
+  guint n_monitors;
+
+  str = g_string_new (NULL);
+
+  /*
+   * Log host information.
+   */
+  g_string_append (str, "[runtime.host]\n");
+  g_string_append_printf (str, "hostname = \"%s\"\n", g_get_host_name ());
+  g_string_append_printf (str, "username = \"%s\"\n", g_get_user_name ());
+  g_string_append_printf (str, "codeset = \"%s\"\n", g_get_codeset ());
+  g_string_append_printf (str, "cpus = %u\n", g_get_num_processors ());
+  g_string_append_printf (str, "cache_dir = \"%s\"\n", g_get_user_cache_dir ());
+  g_string_append_printf (str, "data_dir = \"%s\"\n", g_get_user_data_dir ());
+  g_string_append_printf (str, "config_dir = \"%s\"\n", g_get_user_config_dir ());
+  g_string_append_printf (str, "runtime_dir = \"%s\"\n", g_get_user_runtime_dir ());
+  g_string_append_printf (str, "home_dir = \"%s\"\n", g_get_home_dir ());
+  g_string_append_printf (str, "tmp_dir = \"%s\"\n", g_get_tmp_dir ());
+  tmp = g_get_current_dir ();
+  g_string_append_printf (str, "current_dir = \"%s\"\n", tmp);
+  g_free (tmp);
+  now = g_date_time_new_now_utc ();
+  tmp = g_date_time_format (now, "%FT%H:%M:%SZ");
+  g_string_append_printf (str, "generated-at = \"%s\"\n", tmp);
+  g_free (tmp);
+  g_date_time_unref (now);
+  g_string_append (str, "\n");
+
+  /*
+   * Log various library versions to the log.
+   */
+  g_string_append (str, "[runtime.libraries]\n");
+  g_string_append_printf (str, "glib = \"%u.%u.%u\"\n",
+                          glib_major_version,
+                          glib_minor_version,
+                          glib_micro_version);
+  g_string_append_printf (str, "gtk = \"%u.%u.%u\"\n",
+                          gtk_get_major_version (),
+                          gtk_get_minor_version (),
+                          gtk_get_micro_version ());
+  g_string_append (str, "\n");
+
+  /*
+   * Log display server information.
+   */
+  g_string_append (str, "[runtime.display]\n");
+  g_string_append_printf (str, "name = \"%s\"\n",
+                          gdk_display_get_name (gdk_display_get_default ()));
+  n_monitors = gdk_screen_get_n_monitors (gdk_screen_get_default ());
+  g_string_append_printf (str, "n_monitors = %u\n", n_monitors);
+  for (i = 0; i < n_monitors; i++)
+    {
+      GdkRectangle geom;
+
+      gdk_screen_get_monitor_geometry (gdk_screen_get_default (),
+                                       i, &geom);
+      g_string_append_printf (str, "geometry[%u] = [%u,%u]\n",
+                              i, geom.width, geom.height);
+    }
+  g_string_append (str, "\n");
+
+  /*
+   * Log the environment variables.
+   */
+  g_string_append (str, "[runtime.environ]\n");
+  env = g_get_environ ();
+  for (i = 0; env [i]; i++)
+    {
+      const gchar *value;
+      gchar *escape;
+      gchar *key;
+
+      value = strchr (env [i], '=');
+      if (!value)
+        continue;
+
+      escape = g_strescape (env [i], NULL);
+      key = g_strndup (env [i], value - env [i]);
+
+      g_string_append_printf (str, "%s = \"%s\"\n", key, escape);
+
+      g_free (escape);
+      g_free (key);
+    }
+  g_strfreev (env);
+
+  g_string_append (str, "\n\n");
+
+  /*
+   * Add simple checksum for validation at the end.
+   * Not that anyone would alter the results or anything...
+   */
+  checksum = g_checksum_new (G_CHECKSUM_SHA256);
+  g_checksum_update (checksum, (const guint8 *)str->str, str->len);
+  g_string_append (str, g_checksum_get_string (checksum));
+  g_checksum_free (checksum);
+
+  return g_string_free (str, FALSE);
+}
diff --git a/src/support/gb-support.h b/src/support/gb-support.h
new file mode 100644
index 0000000..7ea7f2b
--- /dev/null
+++ b/src/support/gb-support.h
@@ -0,0 +1,30 @@
+/* gb-support.h
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GB_SUPPORT_H
+#define GB_SUPPORT_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gchar *gb_get_support_log (void);
+
+G_END_DECLS
+
+#endif /* GB_SUPPORT_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]