From 50f0e431eecf07470079bdf037fa800884ce8138 Mon Sep 17 00:00:00 2001 From: Romain Failliot Date: Thu, 18 Nov 2021 11:27:37 -0500 Subject: [PATCH 1/3] Add log options: log_print_output and log_print_stack --- io.github.mightycreak.Diffuse.yml | 6 ++++-- meson_options.txt | 2 ++ src/constants.py.in | 3 +++ src/meson.build | 2 ++ src/utils.py | 10 +++++++++- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/io.github.mightycreak.Diffuse.yml b/io.github.mightycreak.Diffuse.yml index 0fdea81..914fef1 100644 --- a/io.github.mightycreak.Diffuse.yml +++ b/io.github.mightycreak.Diffuse.yml @@ -4,16 +4,18 @@ runtime-version: '3.38' sdk: org.gnome.Sdk command: diffuse finish-args: + - --filesystem=home + - --share=ipc - --socket=wayland - --socket=fallback-x11 - - --share=ipc - - --filesystem=home - --talk-name=org.freedesktop.Flatpak modules: - name: diffuse builddir: true buildsystem: meson config-opts: + - -Dlog_print_output=true + - -Dlog_print_stack=true - -Duse_flatpak=true sources: - type: dir diff --git a/meson_options.txt b/meson_options.txt index 6857b44..0f4bed8 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,3 @@ +option('log_print_output', type: 'boolean', value: false) +option('log_print_stack', type: 'boolean', value: false) option('use_flatpak', type: 'boolean', value: false) diff --git a/src/constants.py.in b/src/constants.py.in index d5d4e77..0cae624 100644 --- a/src/constants.py.in +++ b/src/constants.py.in @@ -24,4 +24,7 @@ COPYRIGHT = '''{copyright} © 2006-2019 Derrick Moser WEBSITE = 'https://mightycreak.github.io/diffuse/' sysconfigdir = '@sysconfigdir@' + use_flatpak = @use_flatpak@ +log_print_output = @log_print_output@ +log_print_stack = @log_print_stack@ diff --git a/src/meson.build b/src/meson.build index f5e5ad7..d463101 100644 --- a/src/meson.build +++ b/src/meson.build @@ -10,6 +10,8 @@ conf.set('VERSION', meson.project_version()) conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir'))) conf.set('pkgdatadir', pkgdatadir) conf.set('sysconfigdir', sysconfdir) +conf.set('log_print_output', get_option('log_print_output')) +conf.set('log_print_stack', get_option('log_print_stack')) conf.set('use_flatpak', get_option('use_flatpak')) configure_file( diff --git a/src/utils.py b/src/utils.py index f9554f2..dbd2fdd 100644 --- a/src/utils.py +++ b/src/utils.py @@ -21,6 +21,7 @@ import os import sys import locale import subprocess +import traceback import gi @@ -43,12 +44,19 @@ class MessageDialog(Gtk.MessageDialog): def isWindows(): return os.name == 'nt' +def _logPrintOutput(msg): + if constants.log_print_output: + print(msg, file=sys.stderr) + if constants.log_print_stack: + traceback.print_stack() + # convenience function to display debug messages def logDebug(s): - pass #sys.stderr.write(f'{constants.APP_NAME}: {s}\n') + _logPrintOutput(f'DEBUG: {s}') # report error messages def logError(s): + _logPrintOutput(f'ERROR: {s}') m = MessageDialog(None, Gtk.MessageType.ERROR, s) m.run() m.destroy() From 08942ea0260fffff0e846593211b0dfe6e950dbf Mon Sep 17 00:00:00 2001 From: Romain Failliot Date: Thu, 18 Nov 2021 12:05:10 -0500 Subject: [PATCH 2/3] Create new utils.logErrorAndDialog function --- src/main.py | 32 ++++++++------------------------ src/utils.py | 18 +++++++++++------- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/main.py b/src/main.py index a749a3b..321bfa6 100644 --- a/src/main.py +++ b/src/main.py @@ -905,9 +905,7 @@ class Preferences: f.write(s) f.close() except IOError: - m = utils.MessageDialog(parent, Gtk.MessageType.ERROR, _('Error writing %s.') % (self.path, )) - m.run() - m.destroy() + utils.logErrorAndDialog(_('Error writing %s.') % (self.path, ), parent) dialog.destroy() return accept @@ -6950,9 +6948,7 @@ class Diffuse(Gtk.Window): msg = _('Error reading revision %(rev)s of %(file)s.') % { 'rev': rev, 'file': name } else: msg = _('Error reading %s.') % (name, ) - dialog = utils.MessageDialog(self.get_toplevel(), Gtk.MessageType.ERROR, msg) - dialog.run() - dialog.destroy() + utils.logErrorAndDialog(msg, self.get_toplevel()) return # update the panes contents, last modified time, and title self.replaceContents(f, ss) @@ -7114,13 +7110,9 @@ class Diffuse(Gtk.Window): self.setSyntax(syntax) return True except (UnicodeEncodeError, LookupError): - dialog = utils.MessageDialog(self.get_toplevel(), Gtk.MessageType.ERROR, _('Error encoding to %s.') % (encoding, )) - dialog.run() - dialog.destroy() + utils.logErrorAndDialog(_('Error encoding to %s.') % (encoding, ), self.get_toplevel()) except IOError: - dialog = utils.MessageDialog(self.get_toplevel(), Gtk.MessageType.ERROR, _('Error writing %s.') % (name, )) - dialog.run() - dialog.destroy() + utils.logErrorAndDialog(_('Error writing %s.') % (name, ), self.get_toplevel()) return False # callback for save file menu item @@ -7782,9 +7774,7 @@ class Diffuse(Gtk.Window): viewer.load(i, FileInfo(name, encoding, vcs, rev)) viewer.setOptions(options) except (IOError, OSError, WindowsError): - dialog = utils.MessageDialog(self.get_toplevel(), Gtk.MessageType.ERROR, _('Error retrieving commits for %s.') % (dn, )) - dialog.run() - dialog.destroy() + utils.logErrorAndDialog(_('Error retrieving commits for %s.') % (dn, ), self.get_toplevel()) # create a new viewer for each modified file found in 'items' def createModifiedFileTabs(self, items, labels, options): @@ -7813,9 +7803,7 @@ class Diffuse(Gtk.Window): viewer.load(i, FileInfo(name, encoding, vcs, rev)) viewer.setOptions(options) except (IOError, OSError, WindowsError): - dialog = utils.MessageDialog(self.get_toplevel(), Gtk.MessageType.ERROR, _('Error retrieving modifications for %s.') % (dn, )) - dialog.run() - dialog.destroy() + utils.logErrorAndDialog(_('Error retrieving modifications for %s.') % (dn, ), self.get_toplevel()) # close all tabs without differences def closeOnSame(self): @@ -7874,9 +7862,7 @@ class Diffuse(Gtk.Window): self.notebook.set_current_page(n) self.getCurrentViewer().grab_focus() else: - m = utils.MessageDialog(parent, Gtk.MessageType.ERROR, _('No modified files found.')) - m.run() - m.destroy() + utils.logErrorAndDialog(_('No modified files found.'), parent) # callback for the open commit menu item def open_commit_cb(self, widget, data): @@ -7894,9 +7880,7 @@ class Diffuse(Gtk.Window): self.notebook.set_current_page(n) self.getCurrentViewer().grab_focus() else: - m = utils.MessageDialog(parent, Gtk.MessageType.ERROR, _('No committed files found.')) - m.run() - m.destroy() + utils.logErrorAndDialog(_('No committed files found.'), parent) # callback for the reload file menu item def reload_file_cb(self, widget, data): diff --git a/src/utils.py b/src/utils.py index dbd2fdd..08ebf04 100644 --- a/src/utils.py +++ b/src/utils.py @@ -51,15 +51,19 @@ def _logPrintOutput(msg): traceback.print_stack() # convenience function to display debug messages -def logDebug(s): - _logPrintOutput(f'DEBUG: {s}') +def logDebug(msg): + _logPrintOutput(f'DEBUG: {msg}') # report error messages -def logError(s): - _logPrintOutput(f'ERROR: {s}') - m = MessageDialog(None, Gtk.MessageType.ERROR, s) - m.run() - m.destroy() +def logError(msg): + _logPrintOutput(f'ERROR: {msg}') + +# report error messages and show dialog +def logErrorAndDialog(msg,parent=None): + logError(msg) + dialog = MessageDialog(parent, Gtk.MessageType.ERROR, msg) + dialog.run() + dialog.destroy() # create nested subdirectories and return the complete path def make_subdirs(p, ss): From 701b3453b5a87b578985e74fc1671843da1d3f86 Mon Sep 17 00:00:00 2001 From: Romain Failliot Date: Thu, 18 Nov 2021 12:08:23 -0500 Subject: [PATCH 3/3] Edit CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60c38c7..98cd38a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- New options: log_print_output and log_print_stack, to print the log messages + on the output and code stack +- New log function: utils.logErrorAndDialog, to both log and show a dialog + message ### Changed