|
|
@@ -90,7 +90,7 @@ class Config(dict): |
|
|
|
except (ValueError, AssertionError) as e: |
|
|
|
raise InvalidConfig('Invalid log format: parsing failed') from e |
|
|
|
if 'storage' in obj: |
|
|
|
if any(x != 'path' for x in obj['storage']): |
|
|
|
if any(x not in ('path', 'flushTime') for x in obj['storage']): |
|
|
|
raise InvalidConfig('Unknown key found in storage section') |
|
|
|
if 'path' in obj['storage']: |
|
|
|
obj['storage']['path'] = os.path.abspath(os.path.join(os.path.dirname(self._filename), obj['storage']['path'])) |
|
|
@@ -100,6 +100,9 @@ class Config(dict): |
|
|
|
f.close() |
|
|
|
except (OSError, IOError) as e: |
|
|
|
raise InvalidConfig('Invalid storage path: not writable') from e |
|
|
|
if 'flushTime' in obj['storage']: |
|
|
|
if not isinstance(obj['storage']['flushTime'], (int, float)) or obj['storage']['flushTime'] <= 0: |
|
|
|
raise InvalidConfig('Invalid storage flushTime: must be a positive int or float') |
|
|
|
if 'irc' in obj: |
|
|
|
if any(x not in ('host', 'port', 'ssl', 'nick', 'real', 'certfile', 'certkeyfile') for x in obj['irc']): |
|
|
|
raise InvalidConfig('Unknown key found in irc section') |
|
|
@@ -216,7 +219,7 @@ class Config(dict): |
|
|
|
raise InvalidConfig(f'Invalid channel {key!r} extrasearchchannels: refers to auth-required channel whose auth differs from this channel\'s') |
|
|
|
|
|
|
|
# Default values |
|
|
|
finalObj = {'logging': {'level': 'INFO', 'format': '{asctime} {levelname} {name} {message}'}, 'storage': {'path': os.path.abspath(os.path.dirname(self._filename))}, 'irc': {'host': 'irc.hackint.org', 'port': 6697, 'ssl': 'yes', 'nick': 'irclogbot', 'real': 'I am an irclog bot.', 'certfile': None, 'certkeyfile': None}, 'web': {'host': '127.0.0.1', 'port': 8080}, 'channels': {}} |
|
|
|
finalObj = {'logging': {'level': 'INFO', 'format': '{asctime} {levelname} {name} {message}'}, 'storage': {'path': os.path.abspath(os.path.dirname(self._filename)), 'flushTime': 60}, 'irc': {'host': 'irc.hackint.org', 'port': 6697, 'ssl': 'yes', 'nick': 'irclogbot', 'real': 'I am an irclog bot.', 'certfile': None, 'certkeyfile': None}, 'web': {'host': '127.0.0.1', 'port': 8080}, 'channels': {}} |
|
|
|
# Default values for channels are already set above. |
|
|
|
|
|
|
|
# Merge in what was read from the config file and set keys on self |
|
|
@@ -735,7 +738,7 @@ class Storage: |
|
|
|
|
|
|
|
async def flush_files(self, flushExitEvent): |
|
|
|
while True: |
|
|
|
await asyncio.wait({flushExitEvent.wait()}, timeout = 60) |
|
|
|
await asyncio.wait({flushExitEvent.wait()}, timeout = self.config['storage']['flushTime']) |
|
|
|
self.logger.debug('Flushing files') |
|
|
|
for _, f in self.files.values(): |
|
|
|
f.flush() |
|
|
|