mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-09 11:52:27 +03:00
Moved logfile regexp to class level constant
Regular expressions are expensive to recompile constantly, and while the python regexp library currently caches reuse, it only does so to a point and that is not a required behaviour. Compiling regexps once is simply best practice. On top of this, the regexp was duplicated in various places.
This commit is contained in:
parent
b010b8015d
commit
a6d6599c3b
10
monitor.py
10
monitor.py
@ -51,6 +51,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
_POLL = 1 # Polling is cheap, so do it often
|
_POLL = 1 # Polling is cheap, so do it often
|
||||||
_RE_CANONICALISE = re.compile(r'\$(.+)_name;')
|
_RE_CANONICALISE = re.compile(r'\$(.+)_name;')
|
||||||
_RE_CATEGORY = re.compile(r'\$MICRORESOURCE_CATEGORY_(.+);')
|
_RE_CATEGORY = re.compile(r'\$MICRORESOURCE_CATEGORY_(.+);')
|
||||||
|
_RE_LOGFILE = re.compile(r'^Journal(Beta)?\.[0-9]{12}\.[0-9]{2}\.log$')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
FileSystemEventHandler.__init__(self) # futureproofing - not need for current version of watchdog
|
FileSystemEventHandler.__init__(self) # futureproofing - not need for current version of watchdog
|
||||||
@ -132,7 +133,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
# Do this before setting up the observer in case the journal directory has gone away
|
# Do this before setting up the observer in case the journal directory has gone away
|
||||||
try:
|
try:
|
||||||
logfiles = sorted(
|
logfiles = sorted(
|
||||||
(x for x in listdir(self.currentdir) if re.search(r'^Journal(Beta)?\.[0-9]{12}\.[0-9]{2}\.log$', x)),
|
(x for x in listdir(self.currentdir) if self._RE_LOGFILE.search(x)),
|
||||||
key=lambda x: x.split('.')[1:]
|
key=lambda x: x.split('.')[1:]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -208,9 +209,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
|
|
||||||
def on_created(self, event):
|
def on_created(self, event):
|
||||||
# watchdog callback, e.g. client (re)started.
|
# watchdog callback, e.g. client (re)started.
|
||||||
if not event.is_directory and re.search(
|
if not event.is_directory and self._RE_LOGFILE.search(basename(event.src_path)):
|
||||||
r'^Journal(Beta)?\.[0-9]{12}\.[0-9]{2}\.log$', basename(event.src_path)
|
|
||||||
):
|
|
||||||
|
|
||||||
self.logfile = event.src_path
|
self.logfile = event.src_path
|
||||||
|
|
||||||
@ -282,8 +281,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
# Poll
|
# Poll
|
||||||
try:
|
try:
|
||||||
logfiles = sorted(
|
logfiles = sorted(
|
||||||
(x for x in listdir(self.currentdir) if
|
(x for x in listdir(self.currentdir) if self._RE_LOGFILE.search(x)),
|
||||||
re.search(r'^Journal(Beta)?\.[0-9]{12}\.[0-9]{2}\.log$', x)),
|
|
||||||
key=lambda x: x.split('.')[1:]
|
key=lambda x: x.split('.')[1:]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user