diff --git a/README.md b/README.md index c1d3fba..9f3337a 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,9 @@ Build packages are stored in a cache `/var/cache/decman`. By default decman keep ### Systemd units +> [!NOTE] +> Decman will only enable and disable systemd systemd. It will not start or stop them. + Decman can enable systemd services, system wide or for a specific user. Decman will enable all units defined in the source, and disable them when they are removed from the source. If a unit is not defined in the source, decman will not touch it. ### Files diff --git a/src/decman/app.py b/src/decman/app.py index c167441..5486122 100644 --- a/src/decman/app.py +++ b/src/decman/app.py @@ -218,6 +218,9 @@ def run(self): def _disable_units(self): to_disable = self.source.units_to_disable(self.store) l.print_list("Disabling systemd units:", to_disable) + if to_disable: + l.print_info( + "Disabled systemd units won't be stopped automatically.") if not self.only_print: self.systemctl.disable_units(to_disable) @@ -286,6 +289,9 @@ def _create_and_remove_files(self): def _enable_units(self): to_enable = self.source.units_to_enable(self.store) l.print_list("Enabling systemd units:", to_enable) + if to_enable: + l.print_info( + "Enabled systemd units won't be started automatically.") if not self.only_print: self.systemctl.enable_units(to_enable) diff --git a/src/decman/lib/__init__.py b/src/decman/lib/__init__.py index 9fd0574..8e2e521 100644 --- a/src/decman/lib/__init__.py +++ b/src/decman/lib/__init__.py @@ -680,11 +680,13 @@ def _all_units(self) -> set[str]: return result def _all_user_units(self) -> dict[str, set[str]]: - result = {} - result.update(self.systemd_user_units) - for module in self.modules: - if module.enabled: - result.update(module.systemd_user_units()) + result = self.systemd_user_units + for module in [m for m in self.modules if m.enabled]: + module_user_units: dict[str, list[str]] = module.systemd_user_units() + for user in module_user_units.keys(): + if user not in result: + result[user] = set() + result[user].update(module_user_units[user]) return result @@ -922,11 +924,11 @@ def __init__(self, stream): def run(self): while not self.done and not self._stream.closed: - output = self._stream.read() + output = self._stream.read(1000) if output: output = output.decode() self.output += output - print(output, end="") + print(output, end="", flush=True) time.sleep(0.1) diff --git a/tests/test_source_resolution.py b/tests/test_source_resolution.py index 4084d93..c4c887c 100644 --- a/tests/test_source_resolution.py +++ b/tests/test_source_resolution.py @@ -264,3 +264,49 @@ def test_packages_to_remove(self): self.source.packages_to_remove(self.currently_installed_packages), ["p4", "A4", "M_A1", "M_A2"], ) + +class TestModuleUserServices(unittest.TestCase): + + class ModuleWithUserServiceOne(Module): + + def __init__(self): + super().__init__("one", True, "0") + + def systemd_user_units(self) -> dict[str, list[str]]: + return { + "user": ['foo.service'] + } + + class ModuleWithUserServiceTwo(Module): + + def __init__(self): + super().__init__("two", True, "0") + + def systemd_user_units(self) -> dict[str, list[str]]: + return { + "user": ['bar.service'] + } + + def setUp(self) -> None: + self.source = Source( + pacman_packages=set(), + aur_packages=set(), + user_packages=set(), + ignored_packages=set(), + systemd_units=set(), + systemd_user_units={}, + files={}, + directories={}, + modules={ + self.ModuleWithUserServiceOne(), + self.ModuleWithUserServiceTwo() + }, + ) + self.store = Store() + + + def test_user_units_to_enable(self): + self.assertDictEqual( + self.source.user_units_to_enable(self.store), + {"user": ["foo.service", "bar.service"]}, + )