diff --git a/selfprivacy_api/root_daemon/__init__.py b/selfprivacy_api/root_daemon/__init__.py new file mode 100644 index 0000000..f95e79e --- /dev/null +++ b/selfprivacy_api/root_daemon/__init__.py @@ -0,0 +1 @@ +SOCKET_PATH = "/tmp/socket_test.s" diff --git a/selfprivacy_api/root_daemon.py b/selfprivacy_api/root_daemon/daemon.py similarity index 93% rename from selfprivacy_api/root_daemon.py rename to selfprivacy_api/root_daemon/daemon.py index 9fef32b..607a432 100644 --- a/selfprivacy_api/root_daemon.py +++ b/selfprivacy_api/root_daemon/daemon.py @@ -9,7 +9,10 @@ import socket as socket_module import subprocess from typing import Optional -SOCKET_PATH = "/tmp/socket_test.s" +from . import SOCKET_PATH + +# from selfprivacy_api.services.templated_service import SP_MODULES_DEFENITIONS_PATH + BUFFER_SIZE = 1024 services = [ @@ -53,6 +56,14 @@ CHOWN_COMMAND = "chown selfprivacy" # ] +def sync_with_dynamic_services(): + """ + We need to look at the file, then fetch service names + and preferably service folders + + """ + + def get_available_commands() -> List[str]: """ Generate all commands with combinatorics. diff --git a/selfprivacy_api/utils/root_interface.py b/selfprivacy_api/root_daemon/root_interface.py similarity index 89% rename from selfprivacy_api/utils/root_interface.py rename to selfprivacy_api/root_daemon/root_interface.py index 8c61b43..de93002 100644 --- a/selfprivacy_api/utils/root_interface.py +++ b/selfprivacy_api/root_daemon/root_interface.py @@ -1,8 +1,9 @@ from typing import List from time import sleep +import socket as socket_module # from subprocess import check_output -from selfprivacy_api.root_daemon import SOCKET_PATH, socket_module +from selfprivacy_api.root_daemon import SOCKET_PATH from tests.test_common import get_test_mode diff --git a/selfprivacy_api/services/service.py b/selfprivacy_api/services/service.py index d841f26..60ae754 100644 --- a/selfprivacy_api/services/service.py +++ b/selfprivacy_api/services/service.py @@ -5,7 +5,7 @@ import logging from typing import List, Optional from os.path import exists from subprocess import run -from selfprivacy_api.utils.root_interface import call_root_function +from selfprivacy_api.root_daemon.root_interface import call_root_function from selfprivacy_api import utils from selfprivacy_api.services.config_item import ServiceConfigItem diff --git a/tests/test_root_daemon.py b/tests/test_root_daemon.py index f171e25..9999b2d 100644 --- a/tests/test_root_daemon.py +++ b/tests/test_root_daemon.py @@ -1,23 +1,23 @@ import pytest -import os -import asyncio -import threading import subprocess +from typing import List +from time import sleep -from selfprivacy_api.root_daemon import ( +from os import path +from os.path import join, exists +from os import chdir + +import selfprivacy_api +import tests + +from selfprivacy_api.root_daemon.daemon import ( get_available_commands, init, - main, service_commands, services, ) -import selfprivacy_api -import selfprivacy_api.root_daemon as root_daemon -from selfprivacy_api.utils.root_interface import call_root_function -from os.path import join, exists - -from typing import List -from time import sleep +import selfprivacy_api.root_daemon.daemon as root_daemon +from selfprivacy_api.root_daemon.root_interface import call_root_function @pytest.fixture() @@ -48,16 +48,35 @@ def test_init(): assert sock is not None +def get_root_sp_directory() -> str: + package_file = selfprivacy_api.__file__ + tests_file = tests.__file__ + sp_dir = path.commonpath([package_file, tests_file]) + + # raise ValueError(sp_dir,package_file, tests_file) + + return sp_dir + + def start_root_demon(): - root_daemon_file = selfprivacy_api.root_daemon.__file__ + + old_dir = path.abspath(path.curdir) + chdir(get_root_sp_directory()) + + assert path.abspath(path.curdir) == get_root_sp_directory() + # this is a prototype of how we need to run it` - proc = subprocess.Popen(args=["python", root_daemon_file], shell=False) + proc = subprocess.Popen( + args=["python", "-m", "selfprivacy_api.root_daemon.daemon"], shell=False + ) # check that it did not error out sleep(0.3) finished = proc.poll() assert finished is None + chdir(old_dir) + return proc