Simplify code to show GUI debug log

Fixes regression caused by Qt 5 behavior change that prevented the
debug log from being displayed in linux.
This commit is contained in:
Kovid Goyal 2014-08-19 09:51:23 +05:30
parent 736a16d335
commit 17f7b8a14f
2 changed files with 10 additions and 23 deletions

View File

@ -41,9 +41,6 @@ Everything after the -- is passed to the script.
help=_('Run the GUI with a debug console, logging to the'
' specified path. For internal use only, use the -g'
' option to run the GUI in debug mode'))
parser.add_option('--show-gui-debug', default=None,
help=_('Display the specified log file. For internal use'
' only.'))
parser.add_option('-w', '--viewer', default=False, action='store_true',
help=_('Run the ebook viewer in debug mode'))
parser.add_option('--paths', default=False, action='store_true',
@ -220,18 +217,6 @@ def main(args=sys.argv):
main(['calibre'])
elif opts.gui_debug is not None:
run_debug_gui(opts.gui_debug)
elif opts.show_gui_debug:
import time, re
time.sleep(1)
from calibre.gui2 import open_local_file
if iswindows:
with open(opts.show_gui_debug, 'r+b') as f:
raw = f.read()
raw = re.sub('(?<!\r)\n', '\r\n', raw)
f.seek(0)
f.truncate()
f.write(raw)
open_local_file(opts.show_gui_debug)
elif opts.viewer:
from calibre.gui2.viewer.main import main
main(['ebook-viewer'] + args[1:])

View File

@ -1,7 +1,7 @@
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import sys, os, time, socket, traceback
import sys, os, time, socket, traceback, re
from functools import partial
import apsw
@ -349,14 +349,16 @@ def run_gui(opts, args, listener, app, gui_debug=None):
pass
if getattr(runner.main, 'gui_debug', None) is not None:
e = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0]
import subprocess
creationflags = 0
debugfile = runner.main.gui_debug
from calibre.gui2 import open_local_file
if iswindows:
import win32process
creationflags = win32process.CREATE_NO_WINDOW
subprocess.Popen([e, '--show-gui-debug', runner.main.gui_debug],
creationflags=creationflags, stdout=open(os.devnull, 'w'),
stderr=subprocess.PIPE, stdin=open(os.devnull, 'r'))
with open(debugfile, 'r+b') as f:
raw = f.read()
raw = re.sub(b'(?<!\r)\n', b'\r\n', raw)
f.seek(0)
f.truncate()
f.write(raw)
open_local_file(debugfile)
return ret
def cant_start(msg=_('If you are sure it is not running')+', ',