From c3d115b970aa663f9bfaee9a6add2a790957a1c9 Mon Sep 17 00:00:00 2001 From: AleaJactaEst Date: Tue, 9 Oct 2018 13:25:09 +0200 Subject: [PATCH] correct syntax to config with check pycodestyle --- pymanager/manager.py | 68 +++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/pymanager/manager.py b/pymanager/manager.py index e522f01..29fecb8 100755 --- a/pymanager/manager.py +++ b/pymanager/manager.py @@ -74,8 +74,8 @@ This script need configuration file (see below for model):: # size array/dict state size_max_filter = 1000 # search regex to add state (python regex) - add_filter = "^((.*)(setActiveCharForPlayer).*(: set active char )[\d]+( for )(?P.*)|(.*)(disconnectPlayer)(.+:.+<.+>){0,1}[\s]+(?P.*)[\s]+(is disconnected))" - del_filter = "^((.*)(setActiveCharForPlayer).*(: set active char )[\d]+( for )(?P.*)|(.*)(disconnectPlayer)(.+:.+<.+>){0,1}[\s]+(?P.*)[\s]+(is disconnected))" + add_filter = "^((.*)(setActiveCharForPlayer).*(: set active char )[0-9]+( for )(?P.*)|(.*)(disconnectPlayer)(.+:.+<.+>){0,1}[ ]+(?P.*)[ ]+(is disconnected))" + del_filter = "^((.*)(setActiveCharForPlayer).*(: set active char )[0-9]+( for )(?P.*)|(.*)(disconnectPlayer)(.+:.+<.+>){0,1}[ ]+(?P.*)[ ]+(is disconnected))" # autostart (when start OpenNelManager, launch this program) autostart = no # restart after crash @@ -635,12 +635,12 @@ class ManageCommand(): self.restart_delay = restart_delay self.threadRestart = None self.egs_filter = egs_filter - self.egs_filter_load_character = re.compile(".*(egs_plinfo).*(: LOADED User )'(?P[\d]+)' Character '(?P[^']+)' from BS stream file 'characters/([\d]+)/account_(?P[\d]+)_(?P[\d]+)_pdr.bin") - self.egs_filter_active_character = re.compile(".*(setActiveCharForPlayer).*(: set active char )(?P[\d]+)( for player )(?P[\d]+)") - self.egs_filter_sid = re.compile(".*(Mapping UID )(?P[\d]+)( => Sid )\((?P.*)\)") - self.egs_filter_client_ready = re.compile(".*(Updating IS_NEWBIE flag for character: )\((?P.*)\)") - self.egs_filter_disconnected = re.compile(".*(disconnectPlayer).+[\s]+(player )(?P[\d]+)[\s]+(is disconnected)") - self.egs_filter_admin = re.compile("(.*)(cbClientAdmin).*(: ADMIN)(: Player )\((?P.*)\)(?P.+)") + self.egs_filter_load_character = re.compile(r".*(egs_plinfo).*(: LOADED User )'(?P[\d]+)' Character '(?P[^']+)' from BS stream file 'characters/([\d]+)/account_(?P[\d]+)_(?P[\d]+)_pdr.bin") + self.egs_filter_active_character = re.compile(r".*(setActiveCharForPlayer).*(: set active char )(?P[\d]+)( for player )(?P[\d]+)") + self.egs_filter_sid = re.compile(r".*(Mapping UID )(?P[\d]+)( => Sid )[(](?P.*)[)]") + self.egs_filter_client_ready = re.compile(r".*(Updating IS_NEWBIE flag for character: )[(](?P.*)[)]") + self.egs_filter_disconnected = re.compile(r".*(disconnectPlayer).+[\s]+(player )(?P[\d]+)[\s]+(is disconnected)") + self.egs_filter_admin = re.compile(r"(.*)(cbClientAdmin).*(: ADMIN)(: Player )[(](?P.*)[)](?P.+)") # cbClientAdmin EGS-133 : ADMIN: Player (0x0000000021:00:00:86) tried to execute a no valid client admin command 'info' self.filter_load_character = {} self.filter_active_character = {} @@ -741,7 +741,7 @@ class ManageCommand(): if res: logging.debug("egs_filter_admin found") while len(self.filter_admin) >= self.maxlog: - print(self.pos_admin, self.pos_admin - self.maxlog ) + print(self.pos_admin, self.pos_admin - self.maxlog) del self.filter_admin[self.pos_admin - self.maxlog] try: dico = res.groupdict() @@ -753,7 +753,7 @@ class ManageCommand(): break except KeyError: pass - self.filter_admin.setdefault( self.pos_admin, {'when': now, 'SID': dico['SID'], 'ACTION': dico['ACTION'], 'USER': username}) + self.filter_admin.setdefault(self.pos_admin, {'when': now, 'SID': dico['SID'], 'ACTION': dico['ACTION'], 'USER': username}) except KeyError as e: logging.error('Missing key when admin player (%s)' % e) self.pos_admin = self.pos_admin + 1 @@ -787,7 +787,6 @@ class ManageCommand(): code = self.process.poll() if code is not None: logging.error("process %s down" % self.name) - #self.eventRunning.clear() crashed = True except AttributeError as e: logging.warning("process %s down (%s)" % (self.name, e)) @@ -802,7 +801,7 @@ class ManageCommand(): while self.eventRunningReader.is_set() and not wait_semaphore: time.sleep(1) wait_semaphore = self.semaphore.acquire(False) - if wait_semaphore == True: + if wait_semaphore: self.queueIn.put("STOPPED") self.semaphore.release() if self.activate_filter: @@ -821,7 +820,7 @@ class ManageCommand(): time.sleep(1) wait_semaphore = self.semaphore.acquire(False) logging.debug('Prepare restart service %s (step 2)' % (self.name)) - if wait_semaphore == True: + if wait_semaphore: logging.debug('Restart service %s' % (self.name)) self.queueIn.put("START") self.queueOut.get() @@ -889,8 +888,7 @@ class ManageCommand(): return 0 else: logging.error("%s crashed (return code:%d)" % (self.name, code)) - #self.semaphore - #self.queueIn.put("STOPPED") + # self.queueIn.put("STOPPED") return 2 else: logging.debug("%s status [stopped]" % (self.name)) @@ -976,26 +974,26 @@ class ManageCommand(): return self.filter def getconfig(self): - outjson = { 'activate_filter': str(self.activate_filter), - 'bufsize': str(self.bufsize), - 'size_max_filter': str(self.size_max_filter), - 'path': str(self.path), - 'add_filter': str(self.add_filter_cmd), - 'del_filter': str(self.del_filter_cmd), - 'command': str(self.command), - 'maxWaitEnd': str(self.maxWaitEnd), - 'waitDelay': str(self.waitDelay), - 'maxlog': str(self.maxlog), - 'filter': str(self.activate_filter), - 'egs': str(self.egs_filter) } + outjson = {'activate_filter': str(self.activate_filter), + 'bufsize': str(self.bufsize), + 'size_max_filter': str(self.size_max_filter), + 'path': str(self.path), + 'add_filter': str(self.add_filter_cmd), + 'del_filter': str(self.del_filter_cmd), + 'command': str(self.command), + 'maxWaitEnd': str(self.maxWaitEnd), + 'waitDelay': str(self.waitDelay), + 'maxlog': str(self.maxlog), + 'filter': str(self.activate_filter), + 'egs': str(self.egs_filter)} return outjson def getinfo(self): - outjson = { 'number_launch': str(self.number_start), - 'first_line': str(self.first_line), - 'last_line': str(self.last_line), - 'number_filter': len(self.filter), - 'player_connected': len(self.filter_active_character) } + outjson = {'number_launch': str(self.number_start), + 'first_line': str(self.first_line), + 'last_line': str(self.last_line), + 'number_filter': len(self.filter), + 'player_connected': len(self.filter_active_character)} return outjson def getplayer(self): @@ -1020,7 +1018,7 @@ class ManageCommand(): """ loop, run child (wait command) """ signal.signal(signal.SIGABRT, self.receive_signal) signal.signal(signal.SIGTERM, self.receive_signal) - statuscmd = {0:'started', 1:'stopped', 2:'crashed'} + statuscmd = {0: 'started', 1: 'stopped', 2: 'crashed'} loop = True if self.autostart: savedstate = self.start() @@ -1035,7 +1033,6 @@ class ManageCommand(): loop = False continue elif command == "START": - #if savedstate != 0: savedstate = self.start() self.queueOut.put({'state': statuscmd[savedstate]}) elif command == "STATUS": @@ -1080,7 +1077,6 @@ class ManageCommand(): self.stop() savedstate = 2 self.eventRunningRestart.clear() - #logging.warning("program (%s) is crashed" % self.name) try: self.threadRestart.terminate() self.threadRestart.join() @@ -1091,7 +1087,7 @@ class ManageCommand(): self.threadRestart.start() else: logging.warning("Bad command (%s)" % command) - self.queueOut.put( {"error" : "command unknown"} ) + self.queueOut.put({"error": "command unknown"}) logging.debug('Stop %s' % self.name) self.stop() logging.debug('prepare end')