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.
"""
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)

View File

@ -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 ''

View File

@ -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

View File

@ -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

View File

@ -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<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):
__slots__ = GameLog.__slots__
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\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):
__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<level>[^']+)'(?:\s|client|(?P<gametype>KingOfTheHill)|(?P<unknown_gametype>[^\s]+))+======"),
@ -176,6 +181,7 @@ class StartingLevel(GameLog):
class LevelStarted(GameLog):
__slots__ = GameLog.__slots__
matcher = []
@classmethod

View File

@ -9,7 +9,7 @@
data by setting the LogFile<instance>._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()