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

Simplify file loading with glob

parent 1042945a
import glob
import os
import logging
......@@ -52,15 +53,12 @@ class NotificationStorage:
def load(self, storage_dir):
"""Deserialize all notifications from FS"""
logger.debug("Deserializing notifications from '%s'", storage_dir)
for _, _, files in os.walk(storage_dir):
for f in files:
if not f.startswith('.') and f.endswith('.json'):
filepath = os.path.join(storage_dir, f)
n = Notification.from_file(filepath)
if n:
self.notifications[n.notif_id] = n
self.shortid_map[n.notif_id[:self.SHORTID_LENGTH]] = n.notif_id
for filepath in glob.glob(os.path.join(storage_dir, '*.json')):
n = Notification.from_file(filepath)
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):
"""Check if msgid is valid and message with that id exists"""
......
import glob
import os
import logging
......@@ -22,19 +23,13 @@ class PluginStorage:
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):
"""Load plugins from FS"""
for _, _, files in os.walk(self.plugin_dir):
for f in files:
if not f.startswith('.') and f.endswith('.yml'):
p = Plugin.from_file(self.plugin_file_path(f))
for filepath in glob.glob(os.path.join(self.plugin_dir, '*.yml')):
p = Plugin.from_file(filepath)
if p:
self.plugins[p.name] = p
if p:
self.plugins[p.name] = p
def get_plugin(self, 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