Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[sextante] support for non-ASCII characters in SEXTANTE log
  • Loading branch information
alexbruy committed Apr 16, 2013
1 parent d6e5960 commit 7f158b8
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions python/plugins/sextante/core/SextanteLog.py
Expand Up @@ -23,35 +23,37 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import datetime
import os
from sextante.core.SextanteUtils import SextanteUtils
from sextante.core.SextanteConfig import SextanteConfig
import codecs
import datetime
from PyQt4 import QtGui

from sextante.core.SextanteUtils import SextanteUtils
from sextante.core.SextanteConfig import SextanteConfig

class SextanteLog():

LOG_ERROR = "ERROR"
LOG_INFO = "INFO"
LOG_WARNING = "WARNING"
LOG_ALGORITHM = "ALGORITHM"
DATE_FORMAT = u"%a %b %d %Y %H:%M:%S".encode("utf-8")
recentAlgs = []

@staticmethod
def startLogging():
if os.path.isfile(SextanteLog.logFilename()):
logfile = open(SextanteLog.logFilename(), "a")
logfile = codecs.open(SextanteLog.logFilename(), "a", encoding="utf-8")
else:
logfile = open(SextanteLog.logFilename(), "w")
logfile.write("Started logging at " + datetime.datetime.now().strftime("%a %b %d %Y %H:%M:%S") + "\n")
logfile = codecs.open(SextanteLog.logFilename(), "w", encoding="utf-8")
logfile.write("Started logging at " + datetime.datetime.now().strftime(SextanteLog.DATE_FORMAT).decode("utf-8") + "\n")
logfile.close()

@staticmethod
def logFilename():
batchfile = SextanteUtils.userFolder() + os.sep + "sextante_qgis.log"
return batchfile


@staticmethod
def addToLog(msgtype, msg):
try: #it seems that this fails sometimes depending on the msg added:
Expand All @@ -63,8 +65,8 @@ def addToLog(msgtype, msg):
text = a
else:
text = msg.replace("\n", "|")
line = msgtype + "|" + datetime.datetime.now().strftime("%a %b %d %Y %H:%M:%S") + "|" + text + "\n"
logfile = open(SextanteLog.logFilename(), "a")
line = msgtype + "|" + datetime.datetime.now().strftime(SextanteLog.DATE_FORMAT).decode("utf-8") + "|" + text + "\n"
logfile = codecs.open(SextanteLog.logFilename(), "a", encoding="utf-8")
#logfile = codecs.open(SextanteLog.logFilename(), "a", encoding='utf-8')
logfile.write(line)
logfile.close()
Expand All @@ -78,7 +80,6 @@ def addToLog(msgtype, msg):
except:
pass


@staticmethod
def getLogEntries():
entries={}
Expand Down Expand Up @@ -115,7 +116,6 @@ def getLogEntries():
entries[SextanteLog.LOG_WARNING] = warnings
return entries


@staticmethod
def getRecentAlgorithms():
recentAlgsSetting = SextanteConfig.getSetting(SextanteConfig.RECENT_ALGORITHMS)
Expand All @@ -125,14 +125,11 @@ def getRecentAlgorithms():
pass
return SextanteLog.recentAlgs


@staticmethod
def clearLog():
os.unlink(SextanteLog.logFilename())
SextanteLog.startLogging()



class LogEntry():
def __init__(self, date, text):
self.date = date
Expand All @@ -141,8 +138,6 @@ def __init__(self, date, text):
import re
import time



#===============================================================================

#this code has been take from pytailer
Expand Down Expand Up @@ -173,7 +168,7 @@ class Tailer(object):

def __init__(self, filename, read_size=1024, end=False):
self.read_size = read_size
self.file = open(filename)
self.file = codecs.open(filename, encoding="utf-8")
self.start_pos = self.file.tell()
if end:
self.seek_end()
Expand Down Expand Up @@ -259,8 +254,6 @@ def tail(self, lines=10):
else:
return []



def __iter__(self):
return self.follow()

Expand All @@ -269,7 +262,3 @@ def close(self):

def tail(file, lines=200):
return Tailer(file).tail(lines)




0 comments on commit 7f158b8

Please sign in to comment.