[Nvda-dev] commit r1893 - in trunk: . source

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Nvda-dev] commit r1893 - in trunk: . source

NVDA Subversion
Author: jteh
Date: Wed Apr  9 09:43:23 2008
New Revision: 1893

Log:
  Disable wxPython's redirection of stdout/stderr to a window. This means that the "wxPython: stdout/stderr" window will no longer appear.
  Introduced logObj.StreamRedirector, which redirects an output stream to a logger.
  StreamRedirector is now used to redirect stdout and stderr to the standard NVDA logger. Stdout output is logged as warnings. Stderr output is logged as errors. This means that stdout/stderr output can now be found in nvda.log and the error sound will be heard if there is output to stderr. stderr.log is no longer created or used.
  Implements #56.


Modified:
   trunk/   (props changed)
   trunk/source/core.py
   trunk/source/logObj.py
   trunk/source/nvda.pyw

Modified: trunk/source/core.py
==============================================================================
--- trunk/source/core.py (original)
+++ trunk/source/core.py Wed Apr  9 09:43:23 2008
@@ -99,7 +99,7 @@
  except:
  globalVars.log.warning("Could not set language to %s"%lang)
  globalVars.log.debug("Creating wx application instance")
- app = wx.App()
+ app = wx.App(redirect=False)
  import queueHandler
  import gui
  globalVars.log.debug("Initializing GUI")

Modified: trunk/source/logObj.py
==============================================================================
--- trunk/source/logObj.py (original)
+++ trunk/source/logObj.py Wed Apr  9 09:43:23 2008
@@ -1,4 +1,5 @@
 import os
+import sys
 import logging
 import inspect
 import winsound
@@ -47,11 +48,13 @@
 
 class Logger(logging.Logger):
 
- def _log(self, level, msg, args, exc_info=None, extra=None):
+ def _log(self, level, msg, args, exc_info=None, extra=None, codepath=None):
  if not extra:
  extra={}
- f=inspect.currentframe().f_back.f_back
- extra["codepath"]=getCodePath(f)
+ if not codepath:
+ f=inspect.currentframe().f_back.f_back
+ codepath=getCodePath(f)
+ extra["codepath"] = codepath
  return logging.Logger._log(self,level, msg, args, exc_info, extra)
 
 class FileHandler(logging.FileHandler):
@@ -60,3 +63,36 @@
  if record.levelno>=logging.ERROR:
  winsound.PlaySound("waves\\error.wav",winsound.SND_FILENAME|winsound.SND_PURGE|winsound.SND_ASYNC)
  return logging.FileHandler.handle(self,record)
+
+class StreamRedirector(object):
+ """Redirects an output stream to a logger.
+ """
+
+ def __init__(self, name, logger, level):
+ """Constructor.
+ @param name: The name of the stream to be used in the log output.
+ @param logger: The logger to which to log.
+ @type logger: L{Logger}
+ @param level: The level at which to log.
+ @type level: int
+ """
+ self.name = name
+ self.logger = logger
+ self.level = level
+
+ def write(self, text):
+ text = text.rstrip()
+ if not text:
+ return
+ self.logger.log(self.level, text, codepath=self.name)
+
+ def flush(self):
+ pass
+
+def redirectStdout(logger):
+ """Redirect stdout and stderr to a given logger.
+ @param logger: The logger to which to redirect.
+ @type logger: L{Logger}
+ """
+ sys.stdout = StreamRedirector("stdout", logger, logging.WARNING)
+ sys.stderr = StreamRedirector("stderr", logger, logging.ERROR)

Modified: trunk/source/nvda.pyw
==============================================================================
--- trunk/source/nvda.pyw (original)
+++ trunk/source/nvda.pyw Wed Apr  9 09:43:23 2008
@@ -53,11 +53,9 @@
  sys.path.append(sys.prefix)
  os.chdir(sys.prefix)
  logFileName='%s\\nvda.log'%tempfile.gettempdir()
- stderrFileName='%s\\nvda_stderr.log'%tempfile.gettempdir()
 else:
  os.chdir(sys.path[0])
  logFileName='nvda.log'
- stderrFileName='stderr.log'
 
 #Localization settings
 locale.setlocale(locale.LC_ALL,'')
@@ -111,13 +109,6 @@
 #import pychecker.checker
 #Initial logging and logging code
 
-stderrFile=codecs.open(stderrFileName,"w","utf-8","ignore")
-if stderrFile is None:
- sys.exit()
-sys.stderr=stderrFile
-sys.stdout=stderrFile
-
-
 logLevel=globalVars.appArgs.logLevel
 if logLevel<=0:
  logLevel=logging.WARN
@@ -126,6 +117,7 @@
 logFormatter=logging.Formatter("%(levelname)s - %(codepath)s:\n%(message)s")
 logHandler.setFormatter(logFormatter)
 log.addHandler(logHandler)
+logObj.redirectStdout(log)
 globalVars.log=log
 if not globalVars.appArgs.minimal:
  winsound.PlaySound("waves\\start.wav",winsound.SND_FILENAME|winsound.SND_ASYNC)