correct syntax to config with check pycodestyle

This commit is contained in:
AleaJactaEst 2018-10-09 13:25:09 +02:00
parent ef3cc5347d
commit c3d115b970

View file

@ -74,8 +74,8 @@ This script need configuration file (see below for model)::
# size array/dict state # size array/dict state
size_max_filter = 1000 size_max_filter = 1000
# search regex to add state (python regex) # search regex to add state (python regex)
add_filter = "^((.*)(setActiveCharForPlayer).*(: set active char )[\d]+( for )(?P<ActivePlayer>.*)|(.*)(disconnectPlayer)(.+:.+<.+>){0,1}[\s]+(?P<InactivePlayer>.*)[\s]+(is disconnected))" add_filter = "^((.*)(setActiveCharForPlayer).*(: set active char )[0-9]+( for )(?P<ActivePlayer>.*)|(.*)(disconnectPlayer)(.+:.+<.+>){0,1}[ ]+(?P<InactivePlayer>.*)[ ]+(is disconnected))"
del_filter = "^((.*)(setActiveCharForPlayer).*(: set active char )[\d]+( for )(?P<InactivePlayer>.*)|(.*)(disconnectPlayer)(.+:.+<.+>){0,1}[\s]+(?P<ActivePlayer>.*)[\s]+(is disconnected))" del_filter = "^((.*)(setActiveCharForPlayer).*(: set active char )[0-9]+( for )(?P<InactivePlayer>.*)|(.*)(disconnectPlayer)(.+:.+<.+>){0,1}[ ]+(?P<ActivePlayer>.*)[ ]+(is disconnected))"
# autostart (when start OpenNelManager, launch this program) # autostart (when start OpenNelManager, launch this program)
autostart = no autostart = no
# restart after crash # restart after crash
@ -635,12 +635,12 @@ class ManageCommand():
self.restart_delay = restart_delay self.restart_delay = restart_delay
self.threadRestart = None self.threadRestart = None
self.egs_filter = egs_filter self.egs_filter = egs_filter
self.egs_filter_load_character = re.compile(".*(egs_plinfo).*(: LOADED User )'(?P<UID>[\d]+)' Character '(?P<NameDomain>[^']+)' from BS stream file 'characters/([\d]+)/account_(?P<UIDBIS>[\d]+)_(?P<IDCHAR>[\d]+)_pdr.bin") self.egs_filter_load_character = re.compile(r".*(egs_plinfo).*(: LOADED User )'(?P<UID>[\d]+)' Character '(?P<NameDomain>[^']+)' from BS stream file 'characters/([\d]+)/account_(?P<UIDBIS>[\d]+)_(?P<IDCHAR>[\d]+)_pdr.bin")
self.egs_filter_active_character = re.compile(".*(setActiveCharForPlayer).*(: set active char )(?P<IDCHAR>[\d]+)( for player )(?P<UID>[\d]+)") self.egs_filter_active_character = re.compile(r".*(setActiveCharForPlayer).*(: set active char )(?P<IDCHAR>[\d]+)( for player )(?P<UID>[\d]+)")
self.egs_filter_sid = re.compile(".*(Mapping UID )(?P<UID>[\d]+)( => Sid )\((?P<SID>.*)\)") self.egs_filter_sid = re.compile(r".*(Mapping UID )(?P<UID>[\d]+)( => Sid )[(](?P<SID>.*)[)]")
self.egs_filter_client_ready = re.compile(".*(Updating IS_NEWBIE flag for character: )\((?P<ID>.*)\)") self.egs_filter_client_ready = re.compile(r".*(Updating IS_NEWBIE flag for character: )[(](?P<ID>.*)[)]")
self.egs_filter_disconnected = re.compile(".*(disconnectPlayer).+[\s]+(player )(?P<UID>[\d]+)[\s]+(is disconnected)") self.egs_filter_disconnected = re.compile(r".*(disconnectPlayer).+[\s]+(player )(?P<UID>[\d]+)[\s]+(is disconnected)")
self.egs_filter_admin = re.compile("(.*)(cbClientAdmin).*(: ADMIN)(: Player )\((?P<SID>.*)\)(?P<ACTION>.+)") self.egs_filter_admin = re.compile(r"(.*)(cbClientAdmin).*(: ADMIN)(: Player )[(](?P<SID>.*)[)](?P<ACTION>.+)")
# cbClientAdmin EGS-133 : ADMIN: Player (0x0000000021:00:00:86) tried to execute a no valid client admin command 'info' # 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_load_character = {}
self.filter_active_character = {} self.filter_active_character = {}
@ -741,7 +741,7 @@ class ManageCommand():
if res: if res:
logging.debug("egs_filter_admin found") logging.debug("egs_filter_admin found")
while len(self.filter_admin) >= self.maxlog: 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] del self.filter_admin[self.pos_admin - self.maxlog]
try: try:
dico = res.groupdict() dico = res.groupdict()
@ -753,7 +753,7 @@ class ManageCommand():
break break
except KeyError: except KeyError:
pass 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: except KeyError as e:
logging.error('Missing key when admin player (%s)' % e) logging.error('Missing key when admin player (%s)' % e)
self.pos_admin = self.pos_admin + 1 self.pos_admin = self.pos_admin + 1
@ -787,7 +787,6 @@ class ManageCommand():
code = self.process.poll() code = self.process.poll()
if code is not None: if code is not None:
logging.error("process %s down" % self.name) logging.error("process %s down" % self.name)
#self.eventRunning.clear()
crashed = True crashed = True
except AttributeError as e: except AttributeError as e:
logging.warning("process %s down (%s)" % (self.name, 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: while self.eventRunningReader.is_set() and not wait_semaphore:
time.sleep(1) time.sleep(1)
wait_semaphore = self.semaphore.acquire(False) wait_semaphore = self.semaphore.acquire(False)
if wait_semaphore == True: if wait_semaphore:
self.queueIn.put("STOPPED") self.queueIn.put("STOPPED")
self.semaphore.release() self.semaphore.release()
if self.activate_filter: if self.activate_filter:
@ -821,7 +820,7 @@ class ManageCommand():
time.sleep(1) time.sleep(1)
wait_semaphore = self.semaphore.acquire(False) wait_semaphore = self.semaphore.acquire(False)
logging.debug('Prepare restart service %s (step 2)' % (self.name)) logging.debug('Prepare restart service %s (step 2)' % (self.name))
if wait_semaphore == True: if wait_semaphore:
logging.debug('Restart service %s' % (self.name)) logging.debug('Restart service %s' % (self.name))
self.queueIn.put("START") self.queueIn.put("START")
self.queueOut.get() self.queueOut.get()
@ -889,8 +888,7 @@ class ManageCommand():
return 0 return 0
else: else:
logging.error("%s crashed (return code:%d)" % (self.name, code)) logging.error("%s crashed (return code:%d)" % (self.name, code))
#self.semaphore # self.queueIn.put("STOPPED")
#self.queueIn.put("STOPPED")
return 2 return 2
else: else:
logging.debug("%s status [stopped]" % (self.name)) logging.debug("%s status [stopped]" % (self.name))
@ -976,7 +974,7 @@ class ManageCommand():
return self.filter return self.filter
def getconfig(self): def getconfig(self):
outjson = { 'activate_filter': str(self.activate_filter), outjson = {'activate_filter': str(self.activate_filter),
'bufsize': str(self.bufsize), 'bufsize': str(self.bufsize),
'size_max_filter': str(self.size_max_filter), 'size_max_filter': str(self.size_max_filter),
'path': str(self.path), 'path': str(self.path),
@ -987,15 +985,15 @@ class ManageCommand():
'waitDelay': str(self.waitDelay), 'waitDelay': str(self.waitDelay),
'maxlog': str(self.maxlog), 'maxlog': str(self.maxlog),
'filter': str(self.activate_filter), 'filter': str(self.activate_filter),
'egs': str(self.egs_filter) } 'egs': str(self.egs_filter)}
return outjson return outjson
def getinfo(self): def getinfo(self):
outjson = { 'number_launch': str(self.number_start), outjson = {'number_launch': str(self.number_start),
'first_line': str(self.first_line), 'first_line': str(self.first_line),
'last_line': str(self.last_line), 'last_line': str(self.last_line),
'number_filter': len(self.filter), 'number_filter': len(self.filter),
'player_connected': len(self.filter_active_character) } 'player_connected': len(self.filter_active_character)}
return outjson return outjson
def getplayer(self): def getplayer(self):
@ -1020,7 +1018,7 @@ class ManageCommand():
""" loop, run child (wait command) """ """ loop, run child (wait command) """
signal.signal(signal.SIGABRT, self.receive_signal) signal.signal(signal.SIGABRT, self.receive_signal)
signal.signal(signal.SIGTERM, 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 loop = True
if self.autostart: if self.autostart:
savedstate = self.start() savedstate = self.start()
@ -1035,7 +1033,6 @@ class ManageCommand():
loop = False loop = False
continue continue
elif command == "START": elif command == "START":
#if savedstate != 0:
savedstate = self.start() savedstate = self.start()
self.queueOut.put({'state': statuscmd[savedstate]}) self.queueOut.put({'state': statuscmd[savedstate]})
elif command == "STATUS": elif command == "STATUS":
@ -1080,7 +1077,6 @@ class ManageCommand():
self.stop() self.stop()
savedstate = 2 savedstate = 2
self.eventRunningRestart.clear() self.eventRunningRestart.clear()
#logging.warning("program (%s) is crashed" % self.name)
try: try:
self.threadRestart.terminate() self.threadRestart.terminate()
self.threadRestart.join() self.threadRestart.join()
@ -1091,7 +1087,7 @@ class ManageCommand():
self.threadRestart.start() self.threadRestart.start()
else: else:
logging.warning("Bad command (%s)" % command) logging.warning("Bad command (%s)" % command)
self.queueOut.put( {"error" : "command unknown"} ) self.queueOut.put({"error": "command unknown"})
logging.debug('Stop %s' % self.name) logging.debug('Stop %s' % self.name)
self.stop() self.stop()
logging.debug('prepare end') logging.debug('prepare end')