Merge pull request #108 from MightyCreak/add-log-options

Add log options
This commit is contained in:
Creak 2021-11-18 12:29:34 -05:00 committed by GitHub
commit 642ee96397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 32 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added ### 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 ### Changed

View File

@ -4,16 +4,18 @@ runtime-version: '3.38'
sdk: org.gnome.Sdk sdk: org.gnome.Sdk
command: diffuse command: diffuse
finish-args: finish-args:
- --filesystem=home
- --share=ipc
- --socket=wayland - --socket=wayland
- --socket=fallback-x11 - --socket=fallback-x11
- --share=ipc
- --filesystem=home
- --talk-name=org.freedesktop.Flatpak - --talk-name=org.freedesktop.Flatpak
modules: modules:
- name: diffuse - name: diffuse
builddir: true builddir: true
buildsystem: meson buildsystem: meson
config-opts: config-opts:
- -Dlog_print_output=true
- -Dlog_print_stack=true
- -Duse_flatpak=true - -Duse_flatpak=true
sources: sources:
- type: dir - type: dir

View File

@ -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) option('use_flatpak', type: 'boolean', value: false)

View File

@ -24,4 +24,7 @@ COPYRIGHT = '''{copyright} © 2006-2019 Derrick Moser
WEBSITE = 'https://mightycreak.github.io/diffuse/' WEBSITE = 'https://mightycreak.github.io/diffuse/'
sysconfigdir = '@sysconfigdir@' sysconfigdir = '@sysconfigdir@'
use_flatpak = @use_flatpak@ use_flatpak = @use_flatpak@
log_print_output = @log_print_output@
log_print_stack = @log_print_stack@

View File

@ -905,9 +905,7 @@ class Preferences:
f.write(s) f.write(s)
f.close() f.close()
except IOError: except IOError:
m = utils.MessageDialog(parent, Gtk.MessageType.ERROR, _('Error writing %s.') % (self.path, )) utils.logErrorAndDialog(_('Error writing %s.') % (self.path, ), parent)
m.run()
m.destroy()
dialog.destroy() dialog.destroy()
return accept return accept
@ -6950,9 +6948,7 @@ class Diffuse(Gtk.Window):
msg = _('Error reading revision %(rev)s of %(file)s.') % { 'rev': rev, 'file': name } msg = _('Error reading revision %(rev)s of %(file)s.') % { 'rev': rev, 'file': name }
else: else:
msg = _('Error reading %s.') % (name, ) msg = _('Error reading %s.') % (name, )
dialog = utils.MessageDialog(self.get_toplevel(), Gtk.MessageType.ERROR, msg) utils.logErrorAndDialog(msg, self.get_toplevel())
dialog.run()
dialog.destroy()
return return
# update the panes contents, last modified time, and title # update the panes contents, last modified time, and title
self.replaceContents(f, ss) self.replaceContents(f, ss)
@ -7114,13 +7110,9 @@ class Diffuse(Gtk.Window):
self.setSyntax(syntax) self.setSyntax(syntax)
return True return True
except (UnicodeEncodeError, LookupError): except (UnicodeEncodeError, LookupError):
dialog = utils.MessageDialog(self.get_toplevel(), Gtk.MessageType.ERROR, _('Error encoding to %s.') % (encoding, )) utils.logErrorAndDialog(_('Error encoding to %s.') % (encoding, ), self.get_toplevel())
dialog.run()
dialog.destroy()
except IOError: except IOError:
dialog = utils.MessageDialog(self.get_toplevel(), Gtk.MessageType.ERROR, _('Error writing %s.') % (name, )) utils.logErrorAndDialog(_('Error writing %s.') % (name, ), self.get_toplevel())
dialog.run()
dialog.destroy()
return False return False
# callback for save file menu item # callback for save file menu item
@ -7782,9 +7774,7 @@ class Diffuse(Gtk.Window):
viewer.load(i, FileInfo(name, encoding, vcs, rev)) viewer.load(i, FileInfo(name, encoding, vcs, rev))
viewer.setOptions(options) viewer.setOptions(options)
except (IOError, OSError, WindowsError): except (IOError, OSError, WindowsError):
dialog = utils.MessageDialog(self.get_toplevel(), Gtk.MessageType.ERROR, _('Error retrieving commits for %s.') % (dn, )) utils.logErrorAndDialog(_('Error retrieving commits for %s.') % (dn, ), self.get_toplevel())
dialog.run()
dialog.destroy()
# create a new viewer for each modified file found in 'items' # create a new viewer for each modified file found in 'items'
def createModifiedFileTabs(self, items, labels, options): def createModifiedFileTabs(self, items, labels, options):
@ -7813,9 +7803,7 @@ class Diffuse(Gtk.Window):
viewer.load(i, FileInfo(name, encoding, vcs, rev)) viewer.load(i, FileInfo(name, encoding, vcs, rev))
viewer.setOptions(options) viewer.setOptions(options)
except (IOError, OSError, WindowsError): except (IOError, OSError, WindowsError):
dialog = utils.MessageDialog(self.get_toplevel(), Gtk.MessageType.ERROR, _('Error retrieving modifications for %s.') % (dn, )) utils.logErrorAndDialog(_('Error retrieving modifications for %s.') % (dn, ), self.get_toplevel())
dialog.run()
dialog.destroy()
# close all tabs without differences # close all tabs without differences
def closeOnSame(self): def closeOnSame(self):
@ -7874,9 +7862,7 @@ class Diffuse(Gtk.Window):
self.notebook.set_current_page(n) self.notebook.set_current_page(n)
self.getCurrentViewer().grab_focus() self.getCurrentViewer().grab_focus()
else: else:
m = utils.MessageDialog(parent, Gtk.MessageType.ERROR, _('No modified files found.')) utils.logErrorAndDialog(_('No modified files found.'), parent)
m.run()
m.destroy()
# callback for the open commit menu item # callback for the open commit menu item
def open_commit_cb(self, widget, data): def open_commit_cb(self, widget, data):
@ -7894,9 +7880,7 @@ class Diffuse(Gtk.Window):
self.notebook.set_current_page(n) self.notebook.set_current_page(n)
self.getCurrentViewer().grab_focus() self.getCurrentViewer().grab_focus()
else: else:
m = utils.MessageDialog(parent, Gtk.MessageType.ERROR, _('No committed files found.')) utils.logErrorAndDialog(_('No committed files found.'), parent)
m.run()
m.destroy()
# callback for the reload file menu item # callback for the reload file menu item
def reload_file_cb(self, widget, data): def reload_file_cb(self, widget, data):

View File

@ -10,6 +10,8 @@ conf.set('VERSION', meson.project_version())
conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir'))) conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir')))
conf.set('pkgdatadir', pkgdatadir) conf.set('pkgdatadir', pkgdatadir)
conf.set('sysconfigdir', sysconfdir) 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')) conf.set('use_flatpak', get_option('use_flatpak'))
configure_file( configure_file(

View File

@ -21,6 +21,7 @@ import os
import sys import sys
import locale import locale
import subprocess import subprocess
import traceback
import gi import gi
@ -43,15 +44,26 @@ class MessageDialog(Gtk.MessageDialog):
def isWindows(): def isWindows():
return os.name == 'nt' 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 # convenience function to display debug messages
def logDebug(s): def logDebug(msg):
pass #sys.stderr.write(f'{constants.APP_NAME}: {s}\n') _logPrintOutput(f'DEBUG: {msg}')
# report error messages # report error messages
def logError(s): def logError(msg):
m = MessageDialog(None, Gtk.MessageType.ERROR, s) _logPrintOutput(f'ERROR: {msg}')
m.run()
m.destroy() # 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 # create nested subdirectories and return the complete path
def make_subdirs(p, ss): def make_subdirs(p, ss):