2323# This will get replaced with a git SHA1 when you do a git archive
2424__revision__ = '$Format:%H$'
2525
26- import datetime
2726import os
28- from sextante .core .SextanteUtils import SextanteUtils
29- from sextante .core .SextanteConfig import SextanteConfig
3027import codecs
28+ import datetime
3129from PyQt4 import QtGui
30+
31+ from sextante .core .SextanteUtils import SextanteUtils
32+ from sextante .core .SextanteConfig import SextanteConfig
33+
3234class SextanteLog ():
3335
3436 LOG_ERROR = "ERROR"
3537 LOG_INFO = "INFO"
3638 LOG_WARNING = "WARNING"
3739 LOG_ALGORITHM = "ALGORITHM"
40+ DATE_FORMAT = u"%a %b %d %Y %H:%M:%S" .encode ("utf-8" )
3841 recentAlgs = []
3942
4043 @staticmethod
4144 def startLogging ():
4245 if os .path .isfile (SextanteLog .logFilename ()):
43- logfile = open (SextanteLog .logFilename (), "a" )
46+ logfile = codecs . open (SextanteLog .logFilename (), "a" , encoding = "utf-8 " )
4447 else :
45- logfile = open (SextanteLog .logFilename (), "w" )
46- logfile .write ("Started logging at " + datetime .datetime .now ().strftime ("%a %b %d %Y %H:%M:%S " ) + "\n " )
48+ logfile = codecs . open (SextanteLog .logFilename (), "w" , encoding = "utf-8 " )
49+ logfile .write ("Started logging at " + datetime .datetime .now ().strftime (SextanteLog . DATE_FORMAT ). decode ( "utf-8 " ) + "\n " )
4750 logfile .close ()
4851
4952 @staticmethod
5053 def logFilename ():
5154 batchfile = SextanteUtils .userFolder () + os .sep + "sextante_qgis.log"
5255 return batchfile
5356
54-
5557 @staticmethod
5658 def addToLog (msgtype , msg ):
5759 try : #it seems that this fails sometimes depending on the msg added:
@@ -63,8 +65,8 @@ def addToLog(msgtype, msg):
6365 text = a
6466 else :
6567 text = msg .replace ("\n " , "|" )
66- line = msgtype + "|" + datetime .datetime .now ().strftime ("%a %b %d %Y %H:%M:%S " ) + "|" + text + "\n "
67- logfile = open (SextanteLog .logFilename (), "a" )
68+ line = msgtype + "|" + datetime .datetime .now ().strftime (SextanteLog . DATE_FORMAT ). decode ( "utf-8 " ) + "|" + text + "\n "
69+ logfile = codecs . open (SextanteLog .logFilename (), "a" , encoding = "utf-8 " )
6870 #logfile = codecs.open(SextanteLog.logFilename(), "a", encoding='utf-8')
6971 logfile .write (line )
7072 logfile .close ()
@@ -78,7 +80,6 @@ def addToLog(msgtype, msg):
7880 except :
7981 pass
8082
81-
8283 @staticmethod
8384 def getLogEntries ():
8485 entries = {}
@@ -115,7 +116,6 @@ def getLogEntries():
115116 entries [SextanteLog .LOG_WARNING ] = warnings
116117 return entries
117118
118-
119119 @staticmethod
120120 def getRecentAlgorithms ():
121121 recentAlgsSetting = SextanteConfig .getSetting (SextanteConfig .RECENT_ALGORITHMS )
@@ -125,14 +125,11 @@ def getRecentAlgorithms():
125125 pass
126126 return SextanteLog .recentAlgs
127127
128-
129128 @staticmethod
130129 def clearLog ():
131130 os .unlink (SextanteLog .logFilename ())
132131 SextanteLog .startLogging ()
133132
134-
135-
136133class LogEntry ():
137134 def __init__ (self , date , text ):
138135 self .date = date
@@ -141,8 +138,6 @@ def __init__(self, date, text):
141138import re
142139import time
143140
144-
145-
146141#===============================================================================
147142
148143#this code has been take from pytailer
@@ -173,7 +168,7 @@ class Tailer(object):
173168
174169 def __init__ (self , filename , read_size = 1024 , end = False ):
175170 self .read_size = read_size
176- self .file = open (filename )
171+ self .file = codecs . open (filename , encoding = "utf-8" )
177172 self .start_pos = self .file .tell ()
178173 if end :
179174 self .seek_end ()
@@ -259,8 +254,6 @@ def tail(self, lines=10):
259254 else :
260255 return []
261256
262-
263-
264257 def __iter__ (self ):
265258 return self .follow ()
266259
@@ -269,7 +262,3 @@ def close(self):
269262
270263def tail (file , lines = 200 ):
271264 return Tailer (file ).tail (lines )
272-
273-
274-
275-
0 commit comments