Py3 compatibility update 3
- zip files correctly read, currently hardcoded encoding - file encoding hardcoded generally - various fixes
This commit is contained in:
parent
3bde3a7570
commit
50b15b218b
@ -29,7 +29,9 @@ if __name__ == '__main__':
|
||||
datefmt='%Y-%m-%d %H:%M:%S')
|
||||
coll = LogSessionCollector(os.path.join(os.path.expanduser('~'),
|
||||
'Documents', 'My Games', 'sc'))
|
||||
logging.info('Collecting Sessions...')
|
||||
coll.collect_unique()
|
||||
logging.info('collected %s sessions.' % (len(coll.sessions)))
|
||||
#f = open('output.txt', 'w')
|
||||
rex_combat = {}
|
||||
rex_game = {}
|
||||
@ -50,6 +52,8 @@ if __name__ == '__main__':
|
||||
if not isinstance(l, combat.UserEvent):
|
||||
if not LOG_GOOD:
|
||||
print((l.values['log']))
|
||||
else:
|
||||
logging.debug('No combat log in %s' % logf.idstr)
|
||||
if logf.game_log:
|
||||
for l in logf.game_log.lines:
|
||||
if isinstance(l, dict):
|
||||
@ -63,6 +67,8 @@ if __name__ == '__main__':
|
||||
rex_game[l.__class__.__name__] = rex_game.get(l.__class__.__name__, 0) + 1
|
||||
if not LOG_GOOD:
|
||||
print((l.values['log']))
|
||||
else:
|
||||
logging.debug('No game log in %s' % logf.idstr)
|
||||
if logf.chat_log:
|
||||
for l in logf.chat_log.lines:
|
||||
if isinstance(l, dict):
|
||||
@ -76,6 +82,8 @@ if __name__ == '__main__':
|
||||
rex_chat[l.__class__.__name__] = rex_chat.get(l.__class__.__name__, 0) + 1
|
||||
if not LOG_GOOD:
|
||||
print((l.values['log']))
|
||||
else:
|
||||
logging.debug('No chat log in %s' % logf.idstr)
|
||||
logf.clean(True)
|
||||
# additional cleanup:
|
||||
if logf.chat_log:
|
||||
|
@ -4,10 +4,10 @@
|
||||
Tool to analyze Logs in general.
|
||||
"""
|
||||
import os, sys, logging
|
||||
from .logs.logfiles import LogFileResolver as LogFile
|
||||
from .logs import combat, game, chat
|
||||
from .logs.session import LogSessionCollector
|
||||
from .logs.game import ClientInfo
|
||||
from logs.logfiles import LogFileResolver as LogFile
|
||||
from logs import combat, game, chat
|
||||
from logs.session import LogSessionCollector
|
||||
from logs.game import ClientInfo
|
||||
|
||||
# for windows its kinda this:
|
||||
settings = {'root_path': os.path.join(os.path.expanduser('~'),
|
||||
|
@ -16,8 +16,8 @@
|
||||
"""
|
||||
#from win32com.shell import shell, shellcon
|
||||
import os, sys, logging
|
||||
from .logs.logfiles import LogFileResolver as LogFile
|
||||
from .logs import combat
|
||||
from logs.logfiles import LogFileResolver as LogFile
|
||||
from logs import combat
|
||||
|
||||
# for windows its kinda this:
|
||||
settings = {'root_path': os.path.join(os.path.expanduser('~'),
|
||||
|
@ -22,7 +22,7 @@ class LogFile(LogStream):
|
||||
def read(self, fname=None):
|
||||
fname = fname or self.fname
|
||||
try:
|
||||
f = io.open(fname, 'r', )
|
||||
f = io.open(fname, 'r', encoding="iso8859-1")
|
||||
self.set_data(f.read())
|
||||
except Exception as e:
|
||||
logging.error("Error %s reading file %s " % (e, fname, ))
|
||||
|
@ -118,7 +118,7 @@ class LogStream(object):
|
||||
#if isinstance(self._last_object, Stacktrace) and line.startswith('\t'):
|
||||
# logging.debug('Workaround: %s, worked: %s' % (line, self._last_object.append(line)))
|
||||
# return
|
||||
if self._last_object is not None:
|
||||
if self._last_object is not None and isinstance(self._last_object, Log):
|
||||
self._last_object.unpack()
|
||||
if self._last_object.append(line):
|
||||
return
|
||||
@ -127,6 +127,10 @@ class LogStream(object):
|
||||
elif isinstance(line, dict):
|
||||
# Unresolved Log.
|
||||
o = self.resolve(line)
|
||||
# this is where the whole thing gets polluted with weird dicts.
|
||||
# what exactly should resolve do!?
|
||||
# by default it returns what its given, if unknown.
|
||||
# #@TODO @XXX @CRITICAL
|
||||
self._last_object = o
|
||||
else:
|
||||
self._last_object = o
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Logging Session.
|
||||
"""
|
||||
import zipfile, logging, os
|
||||
import zipfile, logging, os, io
|
||||
from .logfiles import CombatLogFile, GameLogFile, ChatLogFile
|
||||
|
||||
class LogSession(object):
|
||||
@ -63,7 +63,8 @@ class LogFileSession(LogSession):
|
||||
v = self._validate_files_exist()
|
||||
if v > 0:
|
||||
self.idstr = os.path.split(self.directory)[1].lower()
|
||||
except:
|
||||
except Exception as e:
|
||||
logging.error("exception in logfilesession.validate %s" % e)
|
||||
return False
|
||||
return v
|
||||
|
||||
@ -71,6 +72,7 @@ class LogFileSession(LogSession):
|
||||
''' parses the logfiles '''
|
||||
# perform simple validation.
|
||||
if self._zip_source is None:
|
||||
logging.error('_zip_source is None!')
|
||||
self.validate(False)
|
||||
if self._zip_source:
|
||||
self._unzip_logs(files)
|
||||
@ -110,22 +112,23 @@ class LogFileSession(LogSession):
|
||||
if fn:
|
||||
if fn == 'combat.log' and (not files or fn in files) and not 'combat.log' in self.files_parsed:
|
||||
self.combat_log = CombatLogFile(fn)
|
||||
self.combat_log.set_data(z.read(filename))
|
||||
self.combat_log.set_data(io.TextIOWrapper(io.BytesIO(z.read(filename)), encoding='iso8859-1').read())
|
||||
self.combat_log.parse()
|
||||
self.files_parsed.append('combat.log')
|
||||
elif fn == 'game.log' and (not files or fn in files) and not 'game.log' in self.files_parsed:
|
||||
self.game_log = GameLogFile(fn)
|
||||
self.game_log.set_data(z.read(filename))
|
||||
self.game_log.set_data(io.TextIOWrapper(io.BytesIO(z.read(filename)), encoding='iso8859-1').read())
|
||||
self.game_log.parse()
|
||||
self.files_parsed.append('game.log')
|
||||
elif fn == 'chat.log' and (not files or fn in files) and not 'chat.log' in self.files_parsed:
|
||||
self.chat_log = ChatLogFile(fn)
|
||||
self.chat_log.set_data(z.read(filename))
|
||||
self.chat_log.set_data(io.TextIOWrapper(io.BytesIO(z.read(filename)), encoding='iso8859-1').read())
|
||||
self.chat_log.parse()
|
||||
self.files_parsed.append('chat.log')
|
||||
except:
|
||||
except Exception as e:
|
||||
self._error = True
|
||||
return
|
||||
logging.error('_unzip logs encountered error %s' % e)
|
||||
raise
|
||||
finally:
|
||||
z.close()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user