From 5d6e07712b6831b2e759c06e3eeefdae2b2bc1bd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 27 Jun 2018 05:14:18 -0400 Subject: [PATCH] [services-systemd] Refactor getting config - Don't create temporary variables - Change API slightly to accomodate more (kinds of) suffixes --- src/modules/services-systemd/main.py | 14 ++++++-------- src/modules/services-systemd/services-systemd.conf | 6 +++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/modules/services-systemd/main.py b/src/modules/services-systemd/main.py index a2b2dd4f4..31d205318 100644 --- a/src/modules/services-systemd/main.py +++ b/src/modules/services-systemd/main.py @@ -27,7 +27,7 @@ def systemctl(targets, command, suffix): """ For each entry in @p targets, run "systemctl ", where is the entry's name plus the given @p suffix. - A dot is added between name and suffix. + (No dot is added between name and suffix; suffix may be empty) Returns a failure message, or None if this was successful. Services that are not mandatory have their failures suppressed @@ -35,7 +35,7 @@ def systemctl(targets, command, suffix): """ for svc in targets: ec = libcalamares.utils.target_env_call( - ['systemctl', command, "{}.{}".format(svc['name'], suffix)] + ['systemctl', command, "{}{}".format(svc['name'], suffix)] ) if ec != 0: @@ -57,24 +57,22 @@ def run(): """ Setup systemd services """ - services = libcalamares.job.configuration['services'] - targets = libcalamares.job.configuration['targets'] - disable = libcalamares.job.configuration['disable'] + cfg = libcalamares.job.configuration # note that the "systemctl enable" and "systemctl disable" commands used # here will work in a chroot; in fact, they are the only systemctl commands # that support that, see: # http://0pointer.de/blog/projects/changing-roots.html - r = systemctl(services, "enable", "service") + r = systemctl(cfg["services"], "enable", ".service") if r is not None: return r - r = systemctl(targets, "enable", "target") + r = systemctl(cfg["targets"], "enable", ".target") if r is not None: return r - r = systemctl(disable, "disable", "service") + r = systemctl(cfg["disable"], "disable", ".service") if r is not None: return r diff --git a/src/modules/services-systemd/services-systemd.conf b/src/modules/services-systemd/services-systemd.conf index eb971b222..64b95e125 100644 --- a/src/modules/services-systemd/services-systemd.conf +++ b/src/modules/services-systemd/services-systemd.conf @@ -12,7 +12,8 @@ # *services*, *targets* and *disable*. The value of each # key is a list of entries. Each entry has two keys: # - *name* is the (string) name of the service or target that is being -# changed. Use quotes. +# changed. Use quotes. Don't include ".target" or ".service" +# in the name. # - *mandatory* is a boolean option, which states whether the change # must be done successfully. If systemd reports an error while changing # a mandatory entry, the installation will fail. When mandatory is false, @@ -25,16 +26,19 @@ # # graphical target (e.g. so that SDDM runs for login), and # # finally disables pacman-init (an ArchLinux-only service). # # +# # Enables .service # services: # - name: "NetworkManager" # mandatory: true # - name: "cups" # mandatory: false # +# # Enables .target # targets: # - name: "graphical" # mandatory: true # +# # Disables .service # disable: # - name: "pacman-init" # mandatory: false