From b25095001bcda15e2a4b045b2d9d7402d8a460c3 Mon Sep 17 00:00:00 2001 From: Gabor Guzmics Date: Mon, 22 May 2017 16:17:57 +0200 Subject: [PATCH] refactoring, some readmes. --- src/scon/archive/__init__.py | 0 src/scon/config/settings.py | 35 ++++++++++++++++------- src/scon/dj/readme.rst | 5 ++++ src/scon/game/readme.rst | 10 +++++++ src/scon/{archive => gui}/localbrowser.py | 0 src/scon/gui/readme.rst | 1 + src/scon/logs/readme.rst | 28 ++++++++++++++++++ src/scon/qlogviewer.py | 10 ++++--- 8 files changed, 75 insertions(+), 14 deletions(-) delete mode 100644 src/scon/archive/__init__.py create mode 100644 src/scon/dj/readme.rst create mode 100644 src/scon/game/readme.rst rename src/scon/{archive => gui}/localbrowser.py (100%) create mode 100644 src/scon/gui/readme.rst create mode 100644 src/scon/logs/readme.rst diff --git a/src/scon/archive/__init__.py b/src/scon/archive/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/scon/config/settings.py b/src/scon/config/settings.py index 6f1053b..38b6820 100644 --- a/src/scon/config/settings.py +++ b/src/scon/config/settings.py @@ -1,9 +1,16 @@ import os import platform -class Settings(dict): +class Settings(dict): + # note that settings is a dict. def autodetect(self, path=None): - # autodetect settings. + """ autodetects config_path, returns True on success. + if a path is given, it is set to it, as far as it exists. + """ + # this code is mostly in here to remember how to check Operation Systems, + # if the project ever needs releasable binaries. + # following code tries autodetecting star conflict user file folder + # d = path system = platform.system() if system == 'Windows' or system.startswith('CYGWIN_NT'): @@ -13,19 +20,27 @@ class Settings(dict): 'My Games', 'StarConflict',) elif system == 'Linux': - raise NotImplementedError("Implement Linux!") + d = d or os.path.join(os.path.expanduser('~'), '.local', 'share', 'starconflict') elif system == 'Darwin': - raise NotImplementedError("Implement Mac!") + if not d: + raise NotImplementedError("Implement Mac!") else: - raise NotImplementedError("Unknown System! %s" % platform.system()) + if not d: + raise NotImplementedError("Unknown System! %s" % platform.system()) if not os.path.exists(d) or not os.path.isdir(d): - raise Exception("Configuration Autodetection failed. ") - self['root_path'] = d + return False + self['config_path'] = os.path.abspath(d) + return True - def get_path(self): - return self.get('root_path', None) + def get_config_path(self): + """ gets the config_path if set, otherwise None. """ + return self.get('config_path', None) def get_logs_path(self): - return os.path.join(self.get_path, 'logs') + """ gets the logfolder in the config_path or None. """ + p = self.get_config_path() + if p: + return os.path.join(p, 'logs') + return None settings = Settings() diff --git a/src/scon/dj/readme.rst b/src/scon/dj/readme.rst new file mode 100644 index 0000000..2b7f716 --- /dev/null +++ b/src/scon/dj/readme.rst @@ -0,0 +1,5 @@ +DJ Module +--------- + +This is a small django project inside scon, considered deprecated. +You might fish some stuff in here. \ No newline at end of file diff --git a/src/scon/game/readme.rst b/src/scon/game/readme.rst new file mode 100644 index 0000000..6e2d4c7 --- /dev/null +++ b/src/scon/game/readme.rst @@ -0,0 +1,10 @@ +Game Submodule +-------------- + +This is the submodule that is intended to make a higher level api for scon. +While scon.logs is dealing with the parsing itself, scon.game should offer tools to quickly understand common parts of the data. +This includes: + - determining the user + - creating base classes for different game modes + +*This Level of the API is work in progress and atm. not usable in this package* \ No newline at end of file diff --git a/src/scon/archive/localbrowser.py b/src/scon/gui/localbrowser.py similarity index 100% rename from src/scon/archive/localbrowser.py rename to src/scon/gui/localbrowser.py diff --git a/src/scon/gui/readme.rst b/src/scon/gui/readme.rst new file mode 100644 index 0000000..d476366 --- /dev/null +++ b/src/scon/gui/readme.rst @@ -0,0 +1 @@ +Atm. the GUI submodule is only a few example scripts and tests. diff --git a/src/scon/logs/readme.rst b/src/scon/logs/readme.rst new file mode 100644 index 0000000..183b76e --- /dev/null +++ b/src/scon/logs/readme.rst @@ -0,0 +1,28 @@ +Logs Submodule +============== + +The Logs Submodule is the core parsing mechanism in Scon. +It defines classes for opening logfiles from zips, directories, or as a stream, and are intended to be used by higher level apis to adjust to the wanted log retrieval scenario, while keeping the base logic how logs are interpreted unified. + +For the programmer, following submodules are of particular interest + +Game +---- + +Contains all the Packets occuring in game.log; from an interpretation perspective, this holds data of joining games. + +Combat +------ + +Contains all the Combat Packets, occuring during gameplay of any sort. From an interpretation perspective, this holds the juicy data about pew pew. + +Chat +---- + +Contains chat packets. + +Session +------- + +This is the module holding the session collector, trying to make it easy to access your logs and parse them. + diff --git a/src/scon/qlogviewer.py b/src/scon/qlogviewer.py index dd6d3e1..b8159d1 100644 --- a/src/scon/qlogviewer.py +++ b/src/scon/qlogviewer.py @@ -19,7 +19,6 @@ class SessionTreeView(Qt.QTreeView): #child_item.clicked.connect(self.onClickItem) parent.appendRow(child_item) if isinstance(children, dict): - if isinstance(children[child], dict): self._populateTree(children[child], child_item) @@ -47,6 +46,7 @@ class SessionTreeView(Qt.QTreeView): session.parse_files(['game.log']) info_object = Qt.QStandardItem('game.log - %s' % len(session.game_log.lines)) info_object.setEditable(False) + game_sessions = 0 item.appendRow(info_object) # # add all starting events @@ -54,11 +54,13 @@ class SessionTreeView(Qt.QTreeView): if isinstance(line, game.StartingLevel): line.unpack() v = line.values - o = Qt.QStandardItem("Level '%s' gametype '%s'" %( v.get('level'), - v.get('gametype', '') )) + level = v.get('level') + o = Qt.QStandardItem("Level '%s' gametype '%s'" %( level, v.get('gametype', '') )) + if 'mainmenu' not in level: + game_sessions += 1 o.setEditable(False) info_object.appendRow(o) - + info_object.setText('game.log - %s games' % (game_sessions,)) return session.parse_files(['combat.log']) info_object = Qt.QStandardItem('combat.log - %s' % len(session.combat_log.lines))