changing stuff to be py3 compatible.

This commit is contained in:
Gabor Körber 2017-05-16 19:22:51 +02:00
parent 149fc122d0
commit 3bde3a7570
6 changed files with 33 additions and 16 deletions

View File

@ -4,10 +4,10 @@
Tool to analyze Logs in general. Tool to analyze Logs in general.
""" """
import os, sys, logging import os, sys, logging
from .logs.logfiles import LogFileResolver as LogFile from logs.logfiles import LogFileResolver as LogFile
from .logs import combat, game, chat from logs import combat, game, chat
from .logs.session import LogSessionCollector from logs.session import LogSessionCollector
from .logs.game import ClientInfo from logs.game import ClientInfo
# for windows its kinda this: # for windows its kinda this:
settings = {'root_path': os.path.join(os.path.expanduser('~'), settings = {'root_path': os.path.join(os.path.expanduser('~'),
@ -78,8 +78,11 @@ if __name__ == '__main__':
print((l.values['log'])) print((l.values['log']))
logf.clean(True) logf.clean(True)
# additional cleanup: # additional cleanup:
if logf.chat_log:
logf.chat_log.lines = [] logf.chat_log.lines = []
if logf.game_log:
logf.game_log.lines = [] logf.game_log.lines = []
if logf.combat_log:
logf.combat_log.lines = [] logf.combat_log.lines = []
print('Analysis complete:') print('Analysis complete:')
print(('#'*20+' RexCombat ' + '#' *20)) print(('#'*20+' RexCombat ' + '#' *20))

View File

@ -33,10 +33,12 @@ L_NET = 'NET' # Not supported in near future.
L_CHAT = 'CHAT' L_CHAT = 'CHAT'
class Log(object): class Log(object):
__slots__ = ['matcher', 'trash', 'reviewed'] __slots__ = ['trash', 'reviewed']
matcher = None matcher = None
trash = False
reviewed = False def __init__(self):
self.trash = False
self.reviewed = False
@classmethod @classmethod
def is_handler(cls, log): def is_handler(cls, log):
@ -60,6 +62,8 @@ class Log(object):
class Stacktrace(Log): class Stacktrace(Log):
''' Special Log to catch error reports ''' ''' Special Log to catch error reports '''
__slots__ = ['trash', 'reviewed', 'message']
def __init__(self, values=None): def __init__(self, values=None):
super(Stacktrace, self).__init__() super(Stacktrace, self).__init__()
self.message = values or '' self.message = values or ''

View File

@ -14,7 +14,7 @@ between 33-33-33 and FF-33 FF-33 FF-33
""" """
class ChatLog(Log): class ChatLog(Log):
__slots__ = ['matcher', 'trash', '_match_id', 'values'] __slots__ = Log.__slots__ + ['_match_id', 'values']
@classmethod @classmethod
def is_handler(cls, log): def is_handler(cls, log):
@ -27,6 +27,7 @@ class ChatLog(Log):
return False return False
def __init__(self, values=None): def __init__(self, values=None):
super(ChatLog, self).__init__()
self.values = values or {} self.values = values or {}
self.reviewed = False self.reviewed = False

View File

@ -38,6 +38,7 @@ class CombatLog(Log):
return False return False
def __init__(self, values=None): def __init__(self, values=None):
super(CombatLog, self).__init__()
self.values = values or {} self.values = values or {}
self.reviewed = False self.reviewed = False

View File

@ -52,7 +52,7 @@ Interesting Lines:
""" """
class GameLog(Log): class GameLog(Log):
__slots__ = ['matcher', 'trash', '_match_id', 'values'] __slots__ = Log.__slots__ + [ '_match_id', 'values']
@classmethod @classmethod
def is_handler(cls, log): def is_handler(cls, log):
if log.get('logtype', None) == '': # we handle only logs with empty logtype. if log.get('logtype', None) == '': # we handle only logs with empty logtype.
@ -64,6 +64,7 @@ class GameLog(Log):
return False return False
def __init__(self, values=None): def __init__(self, values=None):
super(GameLog, self).__init__()
self.values = values self.values = values
self.reviewed = False self.reviewed = False
@ -95,7 +96,7 @@ class GameLog(Log):
return self.values.get('log', 'Unknown Game Log') return self.values.get('log', 'Unknown Game Log')
class WarningLog(Log): class WarningLog(Log):
__slots__ = ['trash',] # has no slots, always trash.
trash = True trash = True
@classmethod @classmethod
@ -105,17 +106,19 @@ class WarningLog(Log):
return False return False
def __init__(self, values=None): def __init__(self, values=None):
pass self.trash = True
######################################################################################################## ########################################################################################################
# Individual logs. # Individual logs.
class SteamInitialization(GameLog): class SteamInitialization(GameLog):
__slots__ = GameLog.__slots__
matcher = [ matcher = [
re.compile(r"^Steam\sinitialized\sappId\s(?P<steam_app_id>\d+),\suserSteamID\s(?P<steam_id_universe>\d+)\|(?P<steam_id_type>\d+)\|(?P<steam_id_account_hex>\w+),\suserName\s'(?P<steam_username>[^']+)'"), re.compile(r"^Steam\sinitialized\sappId\s(?P<steam_app_id>\d+),\suserSteamID\s(?P<steam_id_universe>\d+)\|(?P<steam_id_type>\d+)\|(?P<steam_id_account_hex>\w+),\suserName\s'(?P<steam_username>[^']+)'"),
] ]
class MasterServerSession(GameLog): class MasterServerSession(GameLog):
__slots__ = GameLog.__slots__
matcher = [ matcher = [
re.compile(r"^MasterServerSession\:\sconnect\sto\sdedicated\sserver(?:,\s|session\s(?P<session_id>\d+)|at addr (?P<addr>\d+\.\d+\.\d+\.\d+)\|(?P<port>\d+))+"), re.compile(r"^MasterServerSession\:\sconnect\sto\sdedicated\sserver(?:,\s|session\s(?P<session_id>\d+)|at addr (?P<addr>\d+\.\d+\.\d+\.\d+)\|(?P<port>\d+))+"),
re.compile(r"^MasterServerSession:\sconnect\sto\sZoneInstance,\ssession\s(?P<session_id>\d+),\sat\saddr\s(?P<addr>\d+\.\d+\.\d+\.\d+)\|(?P<port>\d+),\szoneId\s(?P<zone_id>\d+)"), re.compile(r"^MasterServerSession:\sconnect\sto\sZoneInstance,\ssession\s(?P<session_id>\d+),\sat\saddr\s(?P<addr>\d+\.\d+\.\d+\.\d+)\|(?P<port>\d+),\szoneId\s(?P<zone_id>\d+)"),
@ -129,6 +132,7 @@ class MasterServerSession(GameLog):
class ClientInfo(GameLog): class ClientInfo(GameLog):
__slots__ = GameLog.__slots__
# Note: clinfo holds the subtype of this packet. # Note: clinfo holds the subtype of this packet.
matcher = [ matcher = [
# connecting; addr, port # connecting; addr, port
@ -163,6 +167,7 @@ class ClientInfo(GameLog):
class StartingLevel(GameLog): class StartingLevel(GameLog):
__slots__ = GameLog.__slots__
# level, gametype, unknown_gametype # level, gametype, unknown_gametype
matcher = [ matcher = [
re.compile(r"^======\sstarting\slevel\:\s'(?P<level>[^']+)'(?:\s|client|(?P<gametype>KingOfTheHill)|(?P<unknown_gametype>[^\s]+))+======"), re.compile(r"^======\sstarting\slevel\:\s'(?P<level>[^']+)'(?:\s|client|(?P<gametype>KingOfTheHill)|(?P<unknown_gametype>[^\s]+))+======"),
@ -176,6 +181,7 @@ class StartingLevel(GameLog):
class LevelStarted(GameLog): class LevelStarted(GameLog):
__slots__ = GameLog.__slots__
matcher = [] matcher = []
@classmethod @classmethod

View File

@ -9,7 +9,7 @@
data by setting the LogFile<instance>._data yourself. data by setting the LogFile<instance>._data yourself.
""" """
from .logstream import LogStream from .logstream import LogStream
import io, logging
class LogFile(LogStream): class LogFile(LogStream):
def __init__(self, fname=None, def __init__(self, fname=None,
@ -22,8 +22,10 @@ class LogFile(LogStream):
def read(self, fname=None): def read(self, fname=None):
fname = fname or self.fname fname = fname or self.fname
try: try:
f = open(fname, 'r') f = io.open(fname, 'r', )
self.set_data(f.read()) self.set_data(f.read())
except Exception as e:
logging.error("Error %s reading file %s " % (e, fname, ))
finally: finally:
f.close() f.close()