[services-systemd] Refactor getting config

- Don't create temporary variables
 - Change API slightly to accomodate more (kinds of) suffixes
main
Adriaan de Groot 7 years ago
parent 0520fc3b7e
commit 5d6e07712b

@ -27,7 +27,7 @@ def systemctl(targets, command, suffix):
"""
For each entry in @p targets, run "systemctl <command> <thing>",
where <thing> 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

@ -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 <name>.service
# services:
# - name: "NetworkManager"
# mandatory: true
# - name: "cups"
# mandatory: false
#
# # Enables <name>.target
# targets:
# - name: "graphical"
# mandatory: true
#
# # Disables <name>.service
# disable:
# - name: "pacman-init"
# mandatory: false

Loading…
Cancel
Save