use file system encoding for cmdline args

thanks to to wlhunag for the initial patch!
This commit is contained in:
Damien Elmes 2013-10-21 09:22:14 +09:00
parent 4a9c08014e
commit 184ea3503a
2 changed files with 9 additions and 7 deletions

View file

@ -1,10 +1,15 @@
# Copyright: Damien Elmes <anki@ichi2.net> # Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import getpass import getpass
import os
import sys
import optparse
import tempfile
import __builtin__
import locale
import gettext
import os, sys, optparse, atexit, tempfile, __builtin__
from aqt.qt import * from aqt.qt import *
import locale, gettext
import anki.lang import anki.lang
from anki.consts import HELP_SITE from anki.consts import HELP_SITE
from anki.lang import langDir from anki.lang import langDir
@ -157,6 +162,7 @@ class AnkiApp(QApplication):
sys.stderr.write(sock.errorString()) sys.stderr.write(sock.errorString())
return return
buf = sock.readAll() buf = sock.readAll()
buf = unicode(buf, sys.getfilesystemencoding(), "ignore")
self.emit(SIGNAL("appMsg"), buf) self.emit(SIGNAL("appMsg"), buf)
sock.disconnectFromServer() sock.disconnectFromServer()

View file

@ -64,7 +64,7 @@ class AnkiQt(QMainWindow):
"syncing and add-on loading.")) "syncing and add-on loading."))
# were we given a file to import? # were we given a file to import?
if args and args[0]: if args and args[0]:
self.onAppMsg(unicode(args[0], "utf8", "ignore")) self.onAppMsg(unicode(args[0], sys.getfilesystemencoding(), "ignore"))
# Load profile in a timer so we can let the window finish init and not # Load profile in a timer so we can let the window finish init and not
# close on profile load error. # close on profile load error.
self.progress.timer(10, self.setupProfile, False) self.progress.timer(10, self.setupProfile, False)
@ -1113,10 +1113,6 @@ will be lost. Continue?"""))
self.connect(self.app, SIGNAL("appMsg"), self.onAppMsg) self.connect(self.app, SIGNAL("appMsg"), self.onAppMsg)
def onAppMsg(self, buf): def onAppMsg(self, buf):
if not isinstance(buf, unicode):
# even though we're sending this as unicode up above,
# a bug report still came in that we were receiving a qbytearray
buf = unicode(buf, "utf8", "ignore")
if self.state == "startup": if self.state == "startup":
# try again in a second # try again in a second
return self.progress.timer(1000, lambda: self.onAppMsg(buf), False) return self.progress.timer(1000, lambda: self.onAppMsg(buf), False)