Moved stderr and stdin handlers to only be installed for cli application; allows Gramps libraries to be used in other REPLs
This commit is contained in:
parent
ffa92451f9
commit
d5b93c52be
@ -423,24 +423,6 @@ class GrampsLocale(object):
|
||||
self.encoding = (locale.getpreferredencoding()
|
||||
or sys.getdefaultencoding())
|
||||
LOG.debug("Setting encoding to %s", self.encoding)
|
||||
#Ensure that output is encoded correctly to stdout and stderr. This is
|
||||
#much less cumbersome and error-prone than encoding individual outputs
|
||||
#and better handles the differences between Python 2 and Python 3:
|
||||
try:
|
||||
_encoding = sys.stdout.encoding or sys.getdefaultencoding()
|
||||
except:
|
||||
_encoding = "UTF-8"
|
||||
if sys.version_info[0] < 3:
|
||||
sys.stdout = codecs.getwriter(_encoding)(sys.stdout,
|
||||
'backslashreplace')
|
||||
sys.stderr = codecs.getwriter(_encoding)(sys.stderr,
|
||||
'backslashreplace')
|
||||
else:
|
||||
sys.stdout = codecs.getwriter(_encoding)(sys.stdout.detach(),
|
||||
'backslashreplace')
|
||||
sys.stderr = codecs.getwriter(_encoding)(sys.stderr.detach(),
|
||||
'backslashreplace')
|
||||
|
||||
|
||||
# Make sure that self.lang and self.language are reflected
|
||||
# back into the environment for Gtk to use when its
|
||||
|
@ -434,6 +434,25 @@ def run():
|
||||
startgtkloop(error, argpars)
|
||||
else:
|
||||
#CLI use of GRAMPS
|
||||
|
||||
#Ensure that output is encoded correctly to stdout and
|
||||
#stderr. This is much less cumbersome and error-prone than
|
||||
#encoding individual outputs and better handles the
|
||||
#differences between Python 2 and Python 3:
|
||||
try:
|
||||
_encoding = sys.stdout.encoding or sys.getdefaultencoding()
|
||||
except:
|
||||
_encoding = "UTF-8"
|
||||
if sys.version_info[0] < 3:
|
||||
sys.stdout = codecs.getwriter(_encoding)(sys.stdout,
|
||||
'backslashreplace')
|
||||
sys.stderr = codecs.getwriter(_encoding)(sys.stderr,
|
||||
'backslashreplace')
|
||||
else:
|
||||
sys.stdout = codecs.getwriter(_encoding)(sys.stdout.detach(),
|
||||
'backslashreplace')
|
||||
sys.stderr = codecs.getwriter(_encoding)(sys.stderr.detach(),
|
||||
'backslashreplace')
|
||||
argpars.print_help()
|
||||
argpars.print_usage()
|
||||
from .cli.grampscli import startcli
|
||||
|
Loading…
Reference in New Issue
Block a user