diff --git a/src/scon/analyze.py b/src/scon/analyze.py index 978ac27..534c82c 100644 --- a/src/scon/analyze.py +++ b/src/scon/analyze.py @@ -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: diff --git a/src/scon/battle.py b/src/scon/battle.py index c88f37b..609f8f5 100644 --- a/src/scon/battle.py +++ b/src/scon/battle.py @@ -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('~'), diff --git a/src/scon/brainstorm.py b/src/scon/brainstorm.py index f908b89..db3be2f 100644 --- a/src/scon/brainstorm.py +++ b/src/scon/brainstorm.py @@ -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('~'), diff --git a/src/scon/logs/logfile.py b/src/scon/logs/logfile.py index cb5caa8..e32098f 100644 --- a/src/scon/logs/logfile.py +++ b/src/scon/logs/logfile.py @@ -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, )) diff --git a/src/scon/logs/logstream.py b/src/scon/logs/logstream.py index 4f2419e..44641a4 100644 --- a/src/scon/logs/logstream.py +++ b/src/scon/logs/logstream.py @@ -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 diff --git a/src/scon/logs/session.py b/src/scon/logs/session.py index bd6a1ca..0321ee4 100644 --- a/src/scon/logs/session.py +++ b/src/scon/logs/session.py @@ -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()