Skip to content

Log event parser #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
970110b
dlvax commit
ewjax Aug 1, 2022
807cb50
small edits
ewjax Aug 1, 2022
77ecb8f
cleaned up Parser inheritance
ewjax Aug 1, 2022
223b14e
small edit
ewjax Aug 1, 2022
fa4fa89
editorial
ewjax Aug 1, 2022
e84d05a
addressing some PEP warnings
ewjax Aug 1, 2022
7d31933
PR comments.
ewjax Aug 2, 2022
25490a1
PR comments:
ewjax Aug 2, 2022
8258728
added 'slice' to melee regexp
ewjax Aug 4, 2022
d12a058
Merge remote-tracking branch 'upstream/master' into dlvax
ewjax Aug 12, 2022
c046203
updated coordinates of bank in Crystal caverns
ewjax Oct 7, 2022
656e57e
Merge branch 'dlvax'
ewjax Oct 7, 2022
0e46812
Merge remote-tracking branch 'upstream/master'
ewjax Oct 7, 2022
c22d5a1
build of upstream/master working. Added Makefile.
ewjax Oct 7, 2022
a209abe
added LogEventParser functionality
ewjax Oct 8, 2022
bb183c5
separated TOD into TODHI and TODLO for high and low fidelity events
ewjax Oct 8, 2022
bff0fe7
bug fix
ewjax Oct 8, 2022
a7e3ebb
configure LogEvents so they know which rsyslog server they are speaki…
ewjax Oct 11, 2022
c2e269c
bug fix for TODHI to only show known targets, not all targets
ewjax Oct 12, 2022
67a50a9
small edits to config file management
ewjax Oct 13, 2022
fe780f2
version number label
ewjax Oct 13, 2022
06e309c
version number
ewjax Oct 14, 2022
70965c1
load correct websocket library, and fix the TOD regex
ewjax Oct 16, 2022
c430d93
Merge remote-tracking branch 'upstream/master' into LogEventParser
ewjax Oct 18, 2022
12b9724
merge upstream/master changes that fix websocket library issue
ewjax Oct 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# PyCharm

.idea/
.vscode/
working/
.vbump.ini

# Byte-compiled / optimized / DLL files
__pycache__/
Expand All @@ -15,6 +16,8 @@ __pycache__/

# Distribution / packaging
.Python
.venv/
.nparse.venv/
env/
venv/
bin/
Expand Down Expand Up @@ -65,3 +68,4 @@ docs/_build/
wiki/
old/
nparse.config.json

58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

PACKAGE=nparse

##############################################################################
# do this while not in venv
venv:
python -m venv .$(PACKAGE).venv

venv.clean:
rm -rfd .$(PACKAGE).venv



##############################################################################
# do these while in venv
run: libs.quiet
py $(PACKAGE).py


# libs make targets ###########################
libs: requirements.txt
pip install -r requirements.txt

libs.quiet: requirements.txt
pip install -q -r requirements.txt

libs.clean:
pip uninstall -r requirements.txt


# exe make targets ###########################
exe: libs
pyinstaller nparse_py.spec

exe.clean:
rm -rfd build
rm dist/$(PACKAGE).exe


# install make targets ###########################
#DIRS=dist/data dist/xxx
DIRS=dist/data dist/data/maps dist/data/spells
install: exe
$(shell mkdir $(DIRS))
cp -r ./data/maps/* ./dist/data/maps/
cp -r ./data/spells/* ./dist/data/spells/

install.clean:
rm -rfd $(DIRS)


# general make targets ###########################

all: libs exe install

all.clean: libs.clean exe.clean install.clean

clean: all.clean
2 changes: 1 addition & 1 deletion data/maps/map_files/Crystal_1.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
P -298.0000, 184.0000, 0.0000, 127, 64, 0, 2, Bank
P -298.0000, 192.0000, -384, 127, 64, 0, 2, Bank
P -758.0000, 265.0000, 0.0000, 127, 64, 0, 2, Broken_Bridge
P 939.1472, 589.2308, -538.4664, 127, 0, 0, 2, Queen
P -692.0000, 176.0000, 0.0000, 127, 64, 0, 2, Waterfall
Expand Down
34 changes: 34 additions & 0 deletions helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
import sys

import requests
import json

import psutil

from datetime import datetime, timedelta

from .parser import Parser # noqa: F401
from .parser import ParserWindow # noqa: F401


Expand Down Expand Up @@ -100,3 +106,31 @@ def text_time_to_seconds(text_time):
pass

return timedelta(hours=hours, minutes=minutes, seconds=seconds).total_seconds()


def get_eqgame_pid_list() -> list[int]:
"""
get list of process ID's for eqgame.exe, using psutil module

Returns:
object: list of process ID's (in case multiple versions of eqgame.exe are somehow running)
"""

pid_list = list()
for p in psutil.process_iter(['name']):
if p.info['name'] == 'eqgame.exe':
pid_list.append(p.pid)
return pid_list


def starprint(line: str) -> None:
"""
utility function to print with leading and trailing ** indicators

Args:
line: text to be printed

Returns:
None:
"""
print(f'** {line.rstrip():<100} **')
28 changes: 27 additions & 1 deletion helpers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from glob import glob
import json

# global data
data = {}
_filename = ''
_filename: str = ''
char_name: str = ''
APP_EXIT = False


Expand Down Expand Up @@ -285,6 +287,30 @@ def verify_settings():
False
)

# deathloopvaccine
data['deathloopvaccine'] = data.get('deathloopvaccine', {})
data['deathloopvaccine']['toggled'] = get_setting(
data['deathloopvaccine'].get('toggled', True),
True
)
data['deathloopvaccine']['deaths'] = get_setting(
data['deathloopvaccine'].get('deaths', 4),
4
)
data['deathloopvaccine']['seconds'] = get_setting(
data['deathloopvaccine'].get('seconds', 120),
120
)

# logeventparser
# todo - replace this general LogEventParser.toggled setting, with one for each LogEvent type
section_name = 'LogEventParser'
data[section_name] = data.get(section_name, {})
data[section_name]['toggled'] = get_setting(
data[section_name].get('toggled', True),
True
)


def get_setting(setting, default, func=None):
try:
Expand Down
12 changes: 10 additions & 2 deletions helpers/logreader.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import os
import datetime
from glob import glob
from typing import Optional

from PyQt6.QtCore import QFileSystemWatcher, pyqtSignal

from helpers import config
from helpers import location_service
from helpers import strip_timestamp
import parsers

# pointer to the LogEventParser object, so this code can update the character name when the logfile changes
theLogEventParser: Optional[parsers.LogEventParser] = None


class LogReader(QFileSystemWatcher):
Expand Down Expand Up @@ -45,9 +50,12 @@ def _file_changed_safe_wrap(self, changed_file):
def _file_changed(self, changed_file):
if changed_file != self._stats['log_file']:
self._stats['log_file'] = changed_file
char_name = os.path.basename(changed_file).split("_")[1]
config.char_name = os.path.basename(changed_file).split("_")[1]
# use the global pointer to update the charname
if theLogEventParser:
theLogEventParser.set_char_name(config.char_name)
if not config.data['sharing']['player_name_override']:
config.data['sharing']['player_name'] = char_name
config.data['sharing']['player_name'] = config.char_name
location_service.SIGNALS.config_updated.emit()
with open(self._stats['log_file'], 'rb') as log:
log.seek(0, os.SEEK_END)
Expand Down
63 changes: 46 additions & 17 deletions helpers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,54 @@
QPushButton, QVBoxLayout, QWidget)

from helpers import config
from datetime import datetime


class ParserWindow(QFrame):
class Parser:

def __init__(self):
super().__init__()
self.name = 'Parser' # could this be self.__class__.__name__ instead?
self._visible = False

def isVisible(self) -> bool:
return self._visible

def hide(self):
self._visible = False

def show(self):
self._visible = True

# main parsing logic here - derived classed should override this to perform their particular parsing tasks
def parse(self, timestamp: datetime, text: str) -> None:

# default behavior = simply print passed info
# this strftime mask will recreate the EQ log file timestamp format
line = f'[{timestamp.strftime("%a %b %d %H:%M:%S %Y")}] ' + text
print(f'[{self.name}]:{line}')

def toggle(self, _=None) -> None:
if self.isVisible():
self.hide()
config.data[self.name]['toggled'] = False
else:
self.set_flags()
self.show()
config.data[self.name]['toggled'] = True
config.save()

def shutdown(self) -> None:
pass

def set_flags(self) -> None:
pass

def settings_updated(self) -> None:
pass


class ParserWindow(QFrame, Parser):

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -90,16 +135,6 @@ def _toggle_frame(self):
def set_title(self, title):
self._title.setText(title)

def toggle(self, _=None):
if self.isVisible():
self.hide()
config.data[self.name]['toggled'] = False
else:
self.set_flags()
self.show()
config.data[self.name]['toggled'] = True
config.save()

def closeEvent(self, _):
if config.APP_EXIT:
return
Expand All @@ -124,9 +159,3 @@ def enterEvent(self, event):
def leaveEvent(self, event):
self._menu.setVisible(False)
QFrame.leaveEvent(self, event)

def shutdown(self):
pass

def settings_updated(self):
pass
21 changes: 15 additions & 6 deletions nparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
config.data['general']['qt_scale_factor'] / 100)


CURRENT_VERSION = '0.6.6-rc1'
CURRENT_VERSION = '0.6.6-rc1-rlog14'
if config.data['general']['update_check']:
ONLINE_VERSION = get_version()
else:
Expand Down Expand Up @@ -75,12 +75,20 @@ def _load_parsers(self):
"maps": parsers.Maps(),
"spells": parsers.Spells(),
"discord": parsers.Discord(),
"deathloopvaccine": parsers.DeathLoopVaccine(),
"LogEventParser": parsers.LogEventParser(),
}
self._parsers = [
self._parsers_dict["maps"],
self._parsers_dict["spells"],
self._parsers_dict["discord"],
self._parsers_dict["deathloopvaccine"],
self._parsers_dict["LogEventParser"],
]

# save a pointer to the LogEventParser so the logreader can update the char name when needed
logreader.theLogEventParser = self._parsers_dict['LogEventParser']

for parser in self._parsers:
if parser.name in config.data.keys() and 'geometry' in config.data[parser.name].keys():
g = config.data[parser.name]['geometry']
Expand Down Expand Up @@ -193,11 +201,12 @@ def _menu(self, event):

# save parser geometry
for parser in self._parsers:
g = parser.geometry()
config.data[parser.name]['geometry'] = [
g.x(), g.y(), g.width(), g.height()
]
config.save()
if parser.name in config.data.keys() and 'geometry' in config.data[parser.name].keys():
g = parser.geometry()
config.data[parser.name]['geometry'] = [
g.x(), g.y(), g.width(), g.height()
]
config.save()

self._system_tray.setVisible(False)
config.APP_EXIT = True
Expand Down
Loading