diff --git a/src/scon/analyze.py b/src/scon/analyze.py index f0438d6..978ac27 100644 --- a/src/scon/analyze.py +++ b/src/scon/analyze.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('~'), @@ -78,9 +78,12 @@ if __name__ == '__main__': print((l.values['log'])) logf.clean(True) # additional cleanup: - logf.chat_log.lines = [] - logf.game_log.lines = [] - logf.combat_log.lines = [] + if logf.chat_log: + logf.chat_log.lines = [] + if logf.game_log: + logf.game_log.lines = [] + if logf.combat_log: + logf.combat_log.lines = [] print('Analysis complete:') print(('#'*20+' RexCombat ' + '#' *20)) print(rex_combat) diff --git a/src/scon/logs/base.py b/src/scon/logs/base.py index 439de57..f74cda2 100644 --- a/src/scon/logs/base.py +++ b/src/scon/logs/base.py @@ -33,10 +33,12 @@ L_NET = 'NET' # Not supported in near future. L_CHAT = 'CHAT' class Log(object): - __slots__ = ['matcher', 'trash', 'reviewed'] + __slots__ = ['trash', 'reviewed'] matcher = None - trash = False - reviewed = False + + def __init__(self): + self.trash = False + self.reviewed = False @classmethod def is_handler(cls, log): @@ -60,6 +62,8 @@ class Log(object): class Stacktrace(Log): ''' Special Log to catch error reports ''' + __slots__ = ['trash', 'reviewed', 'message'] + def __init__(self, values=None): super(Stacktrace, self).__init__() self.message = values or '' diff --git a/src/scon/logs/chat.py b/src/scon/logs/chat.py index 18768fc..7c58b16 100644 --- a/src/scon/logs/chat.py +++ b/src/scon/logs/chat.py @@ -14,7 +14,7 @@ between 33-33-33 and FF-33 FF-33 FF-33 """ class ChatLog(Log): - __slots__ = ['matcher', 'trash', '_match_id', 'values'] + __slots__ = Log.__slots__ + ['_match_id', 'values'] @classmethod def is_handler(cls, log): @@ -27,6 +27,7 @@ class ChatLog(Log): return False def __init__(self, values=None): + super(ChatLog, self).__init__() self.values = values or {} self.reviewed = False diff --git a/src/scon/logs/combat.py b/src/scon/logs/combat.py index a75fde8..1756d4d 100644 --- a/src/scon/logs/combat.py +++ b/src/scon/logs/combat.py @@ -38,6 +38,7 @@ class CombatLog(Log): return False def __init__(self, values=None): + super(CombatLog, self).__init__() self.values = values or {} self.reviewed = False diff --git a/src/scon/logs/game.py b/src/scon/logs/game.py index cac5de9..eb86f93 100644 --- a/src/scon/logs/game.py +++ b/src/scon/logs/game.py @@ -52,7 +52,7 @@ Interesting Lines: """ class GameLog(Log): - __slots__ = ['matcher', 'trash', '_match_id', 'values'] + __slots__ = Log.__slots__ + [ '_match_id', 'values'] @classmethod def is_handler(cls, log): if log.get('logtype', None) == '': # we handle only logs with empty logtype. @@ -64,6 +64,7 @@ class GameLog(Log): return False def __init__(self, values=None): + super(GameLog, self).__init__() self.values = values self.reviewed = False @@ -95,7 +96,7 @@ class GameLog(Log): return self.values.get('log', 'Unknown Game Log') class WarningLog(Log): - __slots__ = ['trash',] + # has no slots, always trash. trash = True @classmethod @@ -105,17 +106,19 @@ class WarningLog(Log): return False def __init__(self, values=None): - pass + self.trash = True ######################################################################################################## # Individual logs. class SteamInitialization(GameLog): + __slots__ = GameLog.__slots__ matcher = [ re.compile(r"^Steam\sinitialized\sappId\s(?P\d+),\suserSteamID\s(?P\d+)\|(?P\d+)\|(?P\w+),\suserName\s'(?P[^']+)'"), ] class MasterServerSession(GameLog): + __slots__ = GameLog.__slots__ matcher = [ re.compile(r"^MasterServerSession\:\sconnect\sto\sdedicated\sserver(?:,\s|session\s(?P\d+)|at addr (?P\d+\.\d+\.\d+\.\d+)\|(?P\d+))+"), re.compile(r"^MasterServerSession:\sconnect\sto\sZoneInstance,\ssession\s(?P\d+),\sat\saddr\s(?P\d+\.\d+\.\d+\.\d+)\|(?P\d+),\szoneId\s(?P\d+)"), @@ -129,6 +132,7 @@ class MasterServerSession(GameLog): class ClientInfo(GameLog): + __slots__ = GameLog.__slots__ # Note: clinfo holds the subtype of this packet. matcher = [ # connecting; addr, port @@ -163,6 +167,7 @@ class ClientInfo(GameLog): class StartingLevel(GameLog): + __slots__ = GameLog.__slots__ # level, gametype, unknown_gametype matcher = [ re.compile(r"^======\sstarting\slevel\:\s'(?P[^']+)'(?:\s|client|(?PKingOfTheHill)|(?P[^\s]+))+======"), @@ -176,6 +181,7 @@ class StartingLevel(GameLog): class LevelStarted(GameLog): + __slots__ = GameLog.__slots__ matcher = [] @classmethod diff --git a/src/scon/logs/logfile.py b/src/scon/logs/logfile.py index aded160..cb5caa8 100644 --- a/src/scon/logs/logfile.py +++ b/src/scon/logs/logfile.py @@ -9,7 +9,7 @@ data by setting the LogFile._data yourself. """ from .logstream import LogStream - +import io, logging class LogFile(LogStream): def __init__(self, fname=None, @@ -22,8 +22,10 @@ class LogFile(LogStream): def read(self, fname=None): fname = fname or self.fname try: - f = open(fname, 'r') + f = io.open(fname, 'r', ) self.set_data(f.read()) + except Exception as e: + logging.error("Error %s reading file %s " % (e, fname, )) finally: f.close()