From 3af57b5c16f81e9def6aa3e108d3395ea17ca143 Mon Sep 17 00:00:00 2001 From: pin Date: Fri, 30 Jul 2010 12:35:57 +0000 Subject: [PATCH 1/1] =?utf8?q?D=C3=A9sactivation=20du=20logging=20dans=20d?= =?utf8?q?es=20fichiers=20par=20positionnement=20de=20la=20variable=20'WIN?= =?utf8?q?WII=5FNO=5FLOG'.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@306 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/minwii/log.py | 53 +++++++++++++++++++++++--------------------- src/minwii/logapp.py | 12 ++++++---- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/minwii/log.py b/src/minwii/log.py index 9e40e01..e612491 100755 --- a/src/minwii/log.py +++ b/src/minwii/log.py @@ -25,34 +25,37 @@ hiddenEvents = {pygame.MOUSEMOTION:True, if not os.path.exists(logsdir) : os.mkdir(logsdir) - -class MinWiiStreamHandler(logging.StreamHandler) : - logfile = None - stream = None - env = [] +if os.environ.has_key('WINWII_NO_LOG') : + class MinWiiStreamHandler(logging.Handler) : + def emit(record) : pass +else : + class MinWiiStreamHandler(logging.StreamHandler) : + logfile = None + stream = None + env = [] - def __init__(self) : - logging.Handler.__init__(self) - if self.stream is None : - self.setNewStream() + def __init__(self) : + logging.Handler.__init__(self) + if self.stream is None : + self.setNewStream() - @classmethod - def setNewStream(cls) : - if cls.stream and not cls.stream.closed : - cls.stream.close() - logfile = os.path.join(logsdir, datetime.datetime.now().strftime('%Y-%m-%d-%H_%M_%S.log')) - cls.stream = open(logfile, 'a') + @classmethod + def setNewStream(cls) : + if cls.stream and not cls.stream.closed : + cls.stream.close() + logfile = os.path.join(logsdir, datetime.datetime.now().strftime('%Y-%m-%d-%H_%M_%S.log')) + cls.stream = open(logfile, 'a') - def emit(self, record) : - if record.name == 'minwii.env' : - if record.getMessage()=='NEW_LOG_FILE' : - self.setNewStream() - for rec in self.env : - logging.StreamHandler.emit(self, rec) - return - else : - self.env.append(record) - logging.StreamHandler.emit(self, record) + def emit(self, record) : + if record.name == 'minwii.env' : + if record.getMessage()=='NEW_LOG_FILE' : + self.setNewStream() + for rec in self.env : + logging.StreamHandler.emit(self, rec) + return + else : + self.env.append(record) + logging.StreamHandler.emit(self, record) class EventLoggerAdapter(logging.LoggerAdapter) : diff --git a/src/minwii/logapp.py b/src/minwii/logapp.py index a97e849..1210bf6 100755 --- a/src/minwii/logapp.py +++ b/src/minwii/logapp.py @@ -6,10 +6,11 @@ $Id$ $URL$ """ +import os +os.environ['WINWII_NO_LOG'] = '1' from Tkinter import * import tkFileDialog from glob import glob -import os from os.path import join as pjoin from os.path import basename from os.path import getsize @@ -237,7 +238,10 @@ class ResultsFrame(Frame) : msg.grid() +def main() : + app = Application() + app.master.title("Analyseur des sessions MINWii") + app.mainloop() -app = Application() -app.master.title("Analyseur des sessions MINWii") -app.mainloop() +if __name__ == '__main__' : + main() \ No newline at end of file -- 2.20.1