Commit b57c810d authored by segfault's avatar segfault

Move service initialization from onionkitd to OnionService.__init__()

parent a6c92979
......@@ -41,17 +41,13 @@ _ = translation.gettext
import os
from importlib.machinery import SourceFileLoader
from typing import List
SERVICES_DIR = os.path.join(DATA_DIR, "services")
# Only required for type hints
from typing import TYPE_CHECKING, List
if TYPE_CHECKING:
from onionkit.service import OnionService
def import_services() -> List["OnionService"]:
services = list() # type: List[OnionService]
def get_service_classes() -> List[type]:
classes = list() # type: List[type]
paths = glob.glob(os.path.join(SERVICES_DIR, "*.py"))
paths.sort()
......@@ -59,5 +55,5 @@ def import_services() -> List["OnionService"]:
name = os.path.basename(path)
loader = SourceFileLoader(name, path)
module_ = loader.load_module()
services.append(module_.service_class())
return services
classes.append(module_.service_class)
return classes
......@@ -113,6 +113,11 @@ class OnionService(DBusObject, metaclass=abc.ABCMeta):
self.container = ContainerManager(self.Name, self.state_dir, self.update_transaction_status,
self.update_transaction_progress)
self.set_initial_status()
if self.IsInstalled:
self.initialize_options()
# ----- Exported functions ----- #
def Install(self):
......
......@@ -13,7 +13,7 @@ gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gio
import onionkit.logger
from onionkit import import_services
from onionkit import get_service_classes
from onionkit.dbus.object import DBusObject
from onionkit.dbus.bus import bus
......@@ -109,13 +109,11 @@ def main():
OnionKit().register()
for service in import_services():
service.register()
service.set_initial_status()
for service_class in get_service_classes():
# Initialize the service
service = service_class()
if service.IsInstalled:
service.initialize_options()
service.register()
if "Autostart" in service.options_dict and service.options_dict["Autostart"].Value:
GLib.idle_add(service.Start())
......
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