[displaymanager] use configparser and add better autologin handling
This commit is contained in:
parent
e2f26467ab
commit
0ceadc2b95
@ -24,6 +24,7 @@ import os
|
|||||||
import collections
|
import collections
|
||||||
import re
|
import re
|
||||||
import libcalamares
|
import libcalamares
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
|
||||||
DesktopEnvironment = collections.namedtuple('DesktopEnvironment', ['executable', 'desktop_file'])
|
DesktopEnvironment = collections.namedtuple('DesktopEnvironment', ['executable', 'desktop_file'])
|
||||||
@ -253,34 +254,23 @@ def set_autologin(username, displaymanagers, default_desktop_environment, root_m
|
|||||||
# Systems with Sddm as Desktop Manager
|
# Systems with Sddm as Desktop Manager
|
||||||
sddm_conf_path = os.path.join(root_mount_point, "etc/sddm.conf")
|
sddm_conf_path = os.path.join(root_mount_point, "etc/sddm.conf")
|
||||||
|
|
||||||
|
sddm_config = configparser.ConfigParser()
|
||||||
|
# Make everything case sensitive
|
||||||
|
sddm_config.optionxform = str
|
||||||
|
|
||||||
if os.path.isfile(sddm_conf_path):
|
if os.path.isfile(sddm_conf_path):
|
||||||
libcalamares.utils.debug('SDDM config file exists')
|
sddm_config.read(sddm_conf_path)
|
||||||
else:
|
|
||||||
libcalamares.utils.check_target_env_call(["sh", "-c", "sddm --example-config > /etc/sddm.conf"])
|
|
||||||
|
|
||||||
text = []
|
|
||||||
|
|
||||||
with open(sddm_conf_path, 'r') as sddm_conf:
|
|
||||||
text = sddm_conf.readlines()
|
|
||||||
|
|
||||||
with open(sddm_conf_path, 'w') as sddm_conf:
|
|
||||||
for line in text:
|
|
||||||
# User= line, possibly commented out
|
|
||||||
if re.match('\\s*(?:#\\s*)?User=', line):
|
|
||||||
if do_autologin:
|
if do_autologin:
|
||||||
line = 'User={!s}\n'.format(username)
|
username_hash = {'User': username}
|
||||||
|
if sddm_config['Autologin']:
|
||||||
|
sddm_config['Autologin'].update(username_hash)
|
||||||
else:
|
else:
|
||||||
line = '#User=\n'
|
sddm_config['Autologin'] = username_hash
|
||||||
|
|
||||||
# Session= line, commented out or with empty value
|
with open(sddm_conf_path, 'w') as sddm_config_file:
|
||||||
if re.match('\\s*#\\s*Session=|\\s*Session=$', line):
|
sddm_config.write(sddm_config_file, space_around_delimiters=False)
|
||||||
if default_desktop_environment is not None:
|
|
||||||
if do_autologin:
|
|
||||||
line = 'Session={!s}.desktop\n'.format(default_desktop_environment.desktop_file)
|
|
||||||
else:
|
|
||||||
line = '#Session={!s}.desktop\n'.format(default_desktop_environment.desktop_file)
|
|
||||||
|
|
||||||
sddm_conf.write(line)
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user