Reload all extractors' config after saving changes in the settings dialog

This commit is contained in:
Manuel Cortez 2019-06-24 09:41:22 -05:00
parent bb411e7bbc
commit d33205e84e
4 changed files with 19 additions and 6 deletions

View File

@ -21,7 +21,7 @@ class configuration(object):
if str(i["id"]) == current_output_device: if str(i["id"]) == current_output_device:
self.view.set_value("general", "output_device", i["name"]) self.view.set_value("general", "output_device", i["name"])
break break
extractors = get_extractors() extractors = get_extractors(import_all=True)
for i in extractors: for i in extractors:
if hasattr(i, "settings"): if hasattr(i, "settings"):
panel = getattr(i, "settings")(self.view.notebook) panel = getattr(i, "settings")(self.view.notebook)

View File

@ -92,6 +92,7 @@ class Controller(object):
# Event functions. These functions will call other functions in a thread and are bound to widget events. # Event functions. These functions will call other functions in a thread and are bound to widget events.
def on_settings(self, *args, **kwargs): def on_settings(self, *args, **kwargs):
settings = configuration.configuration() settings = configuration.configuration()
self.reload_extractors()
def on_search(self, *args, **kwargs): def on_search(self, *args, **kwargs):
wx.CallAfter(self.search) wx.CallAfter(self.search)
@ -258,3 +259,8 @@ class Controller(object):
else: else:
self.change_status(u"") self.change_status(u"")
wx.CallAfter(self.window.list.SetFocus) wx.CallAfter(self.window.list.SetFocus)
def reload_extractors(self):
extractors = [i.interface.name for i in get_extractors()]
self.window.extractor.SetItems(extractors)
self.window.extractor.SetValue(extractors[0])

View File

@ -14,7 +14,6 @@ log = logging.getLogger("extractors.zaycev.net")
class interface(base.baseInterface): class interface(base.baseInterface):
name = "zaycev.net" name = "zaycev.net"
enabled = config.app["services"]["zaycev"].get("enabled") enabled = config.app["services"]["zaycev"].get("enabled")
print(enabled)
def search(self, text, page=1): def search(self, text, page=1):
if text == "" or text == None: if text == "" or text == None:

View File

@ -4,6 +4,8 @@ import requests
import threading import threading
import logging import logging
import types import types
import extractors
from importlib import reload
from pubsub import pub from pubsub import pub
log = logging.getLogger("utils") log = logging.getLogger("utils")
@ -70,9 +72,15 @@ def download_file(url, local_filename):
log.debug("Download finished successfully") log.debug("Download finished successfully")
return local_filename return local_filename
def get_extractors(): def get_extractors(import_all=False):
""" Function for importing everything wich is located in the extractors package and has a class named interface.""" """ Function for importing everything wich is located in the extractors package and has a class named interface."""
import extractors
module_type = types.ModuleType module_type = types.ModuleType
# first of all, import all classes for the package so we can reload everything if they have changes in config.
_classes = [m for m in extractors.__dict__.values() if type(m) == module_type and hasattr(m, 'interface')]
for cls in _classes:
reload(cls)
if not import_all:
classes = [m for m in extractors.__dict__.values() if type(m) == module_type and hasattr(m, 'interface') and m.interface.enabled != False] classes = [m for m in extractors.__dict__.values() if type(m) == module_type and hasattr(m, 'interface') and m.interface.enabled != False]
else:
classes = [m for m in extractors.__dict__.values() if type(m) == module_type and hasattr(m, 'interface')]
return classes#sorted(classes, key=lambda c: c.name) return classes#sorted(classes, key=lambda c: c.name)