Commit 067b72c7 authored by Martin Matějek's avatar Martin Matějek

Simplify file loading with glob

parent 1042945a
import glob
import os import os
import logging import logging
...@@ -52,15 +53,12 @@ class NotificationStorage: ...@@ -52,15 +53,12 @@ class NotificationStorage:
def load(self, storage_dir): def load(self, storage_dir):
"""Deserialize all notifications from FS""" """Deserialize all notifications from FS"""
logger.debug("Deserializing notifications from '%s'", storage_dir) logger.debug("Deserializing notifications from '%s'", storage_dir)
for _, _, files in os.walk(storage_dir): for filepath in glob.glob(os.path.join(storage_dir, '*.json')):
for f in files: n = Notification.from_file(filepath)
if not f.startswith('.') and f.endswith('.json'):
filepath = os.path.join(storage_dir, f) if n:
n = Notification.from_file(filepath) self.notifications[n.notif_id] = n
self.shortid_map[n.notif_id[:self.SHORTID_LENGTH]] = n.notif_id
if n:
self.notifications[n.notif_id] = n
self.shortid_map[n.notif_id[:self.SHORTID_LENGTH]] = n.notif_id
def valid_id(self, msgid): def valid_id(self, msgid):
"""Check if msgid is valid and message with that id exists""" """Check if msgid is valid and message with that id exists"""
......
import glob
import os import os
import logging import logging
...@@ -22,19 +23,13 @@ class PluginStorage: ...@@ -22,19 +23,13 @@ class PluginStorage:
self.load() self.load()
def plugin_file_path(self, f):
"""Return full path of plugin file"""
return os.path.join(self.plugin_dir, f)
def load(self): def load(self):
"""Load plugins from FS""" """Load plugins from FS"""
for _, _, files in os.walk(self.plugin_dir): for filepath in glob.glob(os.path.join(self.plugin_dir, '*.yml')):
for f in files: p = Plugin.from_file(filepath)
if not f.startswith('.') and f.endswith('.yml'):
p = Plugin.from_file(self.plugin_file_path(f))
if p: if p:
self.plugins[p.name] = p self.plugins[p.name] = p
def get_plugin(self, name): def get_plugin(self, name):
"""Return plugin specified by name""" """Return plugin specified by name"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment