[PEP 8] General Style Part 3

main
Gormogon 10 years ago
parent 09dc6bb5d7
commit 5c1ee7bbcb

@ -50,6 +50,7 @@ def get_bootloader_entry_name():
branding = libcalamares.globalstorage.value("branding")
return branding["bootloaderEntryName"]
def create_conf(uuid, conf_path):
distribution = get_bootloader_entry_name()
kernel = libcalamares.job.configuration["kernel"]
@ -128,9 +129,11 @@ def install_bootloader(boot_loader, fw_type):
file_name_sanitizer = str.maketrans(" /", "_-")
distribution_translated = distribution.translate(file_name_sanitizer)
conf_path = os.path.join(
install_efi_directory, "loader", "entries", "{!s}.conf".format(distribution_translated))
install_efi_directory, "loader", "entries",
"{!s}.conf".format(distribution_translated))
fallback_path = os.path.join(
install_efi_directory, "loader", "entries", "{!s}-fallback.conf".format(distribution_translated))
install_efi_directory, "loader", "entries",
"{!s}-fallback.conf".format(distribution_translated))
loader_path = os.path.join(
install_efi_directory, "loader", "loader.conf")
partitions = libcalamares.globalstorage.value("partitions")
@ -142,17 +145,17 @@ def install_bootloader(boot_loader, fw_type):
device = boot_device[:-1]
print(device)
subprocess.call(["sgdisk", "--typecode={!s}:EF00".format(boot_p), "{!s}".format(device)])
subprocess.call(
["gummiboot", "--path={!s}".format(install_efi_directory), "install"])
subprocess.call(["gummiboot", "--path={!s}".format(install_efi_directory), "install"])
create_conf(uuid, conf_path)
create_fallback(uuid, fallback_path)
create_loader(loader_path)
else:
install_path = boot_loader["installPath"]
check_chroot_call(
[libcalamares.job.configuration["grubInstall"], "--target=i386-pc", install_path])
check_chroot_call([libcalamares.job.configuration[
"grubMkconfig"], "-o", libcalamares.job.configuration["grubCfg"]])
[libcalamares.job.configuration["grubInstall"], "--target=i386-pc",
install_path])
check_chroot_call([libcalamares.job.configuration["grubMkconfig"], "-o",
libcalamares.job.configuration["grubCfg"]])
def run():

@ -30,8 +30,8 @@ import subprocess
DesktopEnvironment = collections.namedtuple('DesktopEnvironment', ['executable', 'desktop_file'])
desktop_environments = [
DesktopEnvironment('/usr/bin/startkde', 'plasma'), # KDE Plasma 5
DesktopEnvironment('/usr/bin/startkde', 'kde-plasma'), # KDE Plasma 4
DesktopEnvironment('/usr/bin/startkde', 'plasma'), # KDE Plasma 5
DesktopEnvironment('/usr/bin/startkde', 'kde-plasma'), # KDE Plasma 4
DesktopEnvironment('/usr/bin/gnome-session', 'gnome'),
DesktopEnvironment('/usr/bin/startxfce4', 'xfce'),
DesktopEnvironment('/usr/bin/cinnamon-session', 'cinnamon-session'),
@ -43,17 +43,25 @@ desktop_environments = [
DesktopEnvironment('/usr/bin/openbox-session', 'openbox')
]
def find_desktop_environment(root_mount_point):
for desktop_environment in desktop_environments:
if os.path.exists("{!s}{!s}".format(root_mount_point,desktop_environment.executable)) \
and os.path.exists("{!s}/usr/share/xsessions/{!s}.desktop".format(root_mount_point,desktop_environment.desktop_file)):
if os.path.exists(
"{!s}{!s}".format(root_mount_point, desktop_environment.executable)) \
and os.path.exists("{!s}/usr/share/xsessions/{!s}.desktop".format(root_mount_point,
desktop_environment.desktop_file)):
return desktop_environment
return None
def have_dm(dm_name, root_mount_point):
return os.path.exists("{!s}/usr/bin/{!s}".format(root_mount_point,dm_name)) or os.path.exists("{!s}/usr/sbin/{!s}".format(root_mount_point,dm_name))
return os.path.exists(
"{!s}/usr/bin/{!s}".format(root_mount_point, dm_name)) or os.path.exists(
"{!s}/usr/sbin/{!s}".format(root_mount_point, dm_name))
def set_autologin(username, displaymanagers, default_desktop_environment, root_mount_point):
def set_autologin(username, displaymanagers, default_desktop_environment,
root_mount_point):
""" Enables automatic login for the installed desktop managers """
if "mdm" in displaymanagers:
@ -95,12 +103,15 @@ def set_autologin(username, displaymanagers, default_desktop_environment, root_m
gdm_conf.write('AutomaticLoginEnable=True\n')
if os.path.exists("{!s}/var/lib/AccountsService/users".format(root_mount_point)):
os.system(
"echo \"[User]\" > {!s}/var/lib/AccountsService/users/{!s}".format(root_mount_point,username))
"echo \"[User]\" > {!s}/var/lib/AccountsService/users/{!s}".format(
root_mount_point, username))
if default_desktop_environment is not None:
os.system(
"echo \"XSession={!s}\" >> {!s}/var/lib/AccountsService/users/{!s}".format(default_desktop_environment.desktop_file,root_mount_point,username))
"echo \"XSession={!s}\" >> {!s}/var/lib/AccountsService/users/{!s}".format(
default_desktop_environment.desktop_file, root_mount_point, username))
os.system(
"echo \"Icon=\" >> {!s}/var/lib/AccountsService/users/{!s}".format(root_mount_point,username))
"echo \"Icon=\" >> {!s}/var/lib/AccountsService/users/{!s}".format(
root_mount_point, username))
if "kdm" in displaymanagers:
# Systems with KDM as Desktop Manager
@ -191,7 +202,7 @@ def set_autologin(username, displaymanagers, default_desktop_environment, root_m
if default_desktop_environment is not None:
line = 'Session={}.desktop\n'.format(default_desktop_environment.desktop_file)
sddm_conf.write(line)
return None
@ -209,15 +220,16 @@ def run():
displaymanagers = libcalamares.globalstorage.value("displaymanagers")
if displaymanagers is None:
return "No display managers selected for the displaymanager module.",\
return "No display managers selected for the displaymanager module.", \
"The displaymanagers list is empty or undefined in both globalstorage and displaymanager.conf."
username = libcalamares.globalstorage.value("autologinUser")
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
if "default_desktop_environment" in libcalamares.job.configuration:
entry = libcalamares.job.configuration["defaultDesktopEnvironment"]
default_desktop_environment = DesktopEnvironment(entry["executable"], entry["desktopFile"])
default_desktop_environment = DesktopEnvironment(entry["executable"],
entry["desktopFile"])
else:
default_desktop_environment = find_desktop_environment(root_mount_point)
@ -247,9 +259,10 @@ def run():
libcalamares.utils.chroot_call(
['groupadd', '-g', '620', 'lightdm'])
if libcalamares.utils.chroot_call(['getent', 'passwd', 'lightdm']) != 0:
libcalamares.utils.chroot_call(['useradd', '-c', '"LightDM Display Manager"',
'-u', '620', '-g', 'lightdm', '-d', '/var/run/lightdm',
'-s', '/usr/bin/nologin', 'lightdm'])
libcalamares.utils.chroot_call(
['useradd', '-c', '"LightDM Display Manager"',
'-u', '620', '-g', 'lightdm', '-d', '/var/run/lightdm',
'-s', '/usr/bin/nologin', 'lightdm'])
libcalamares.utils.chroot_call(['passwd', '-l', 'lightdm'])
libcalamares.utils.chroot_call(
['chown', '-R', 'lightdm:lightdm', '/run/lightdm'])
@ -257,7 +270,8 @@ def run():
['chmod', '+r' '/etc/lightdm/lightdm.conf'])
if default_desktop_environment is not None:
os.system(
"sed -i -e \"s/^.*user-session=.*/user-session={!s}/\" {!s}/etc/lightdm/lightdm.conf".format(default_desktop_environment.desktop_file,root_mount_point))
"sed -i -e \"s/^.*user-session=.*/user-session={!s}/\" {!s}/etc/lightdm/lightdm.conf".format(
default_desktop_environment.desktop_file, root_mount_point))
else:
libcalamares.utils.debug("lightdm selected but not installed")
displaymanagers.remove("lightdm")
@ -269,9 +283,10 @@ def run():
if libcalamares.utils.chroot_call(['getent', 'group', 'gdm']) != 0:
libcalamares.utils.chroot_call(['groupadd', '-g', '120', 'gdm'])
if libcalamares.utils.chroot_call(['getent', 'passwd', 'gdm']) != 0:
libcalamares.utils.chroot_call(['useradd', '-c', '"Gnome Display Manager"',
'-u', '120', '-g', 'gdm', '-d', '/var/lib/gdm',
'-s', '/usr/bin/nologin', 'gdm'])
libcalamares.utils.chroot_call(
['useradd', '-c', '"Gnome Display Manager"',
'-u', '120', '-g', 'gdm', '-d', '/var/lib/gdm',
'-s', '/usr/bin/nologin', 'gdm'])
libcalamares.utils.chroot_call(['passwd', '-l', 'gdm'])
libcalamares.utils.chroot_call(
['chown', '-R', 'gdm:gdm', '/var/lib/gdm'])
@ -286,16 +301,18 @@ def run():
if libcalamares.utils.chroot_call(['getent', 'group', 'mdm']) != 0:
libcalamares.utils.chroot_call(['groupadd', '-g', '128', 'mdm'])
if libcalamares.utils.chroot_call(['getent', 'passwd', 'mdm']) != 0:
libcalamares.utils.chroot_call(['useradd', '-c', '"Linux Mint Display Manager"',
'-u', '128', '-g', 'mdm', '-d', '/var/lib/mdm',
'-s', '/usr/bin/nologin', 'mdm'])
libcalamares.utils.chroot_call(
['useradd', '-c', '"Linux Mint Display Manager"',
'-u', '128', '-g', 'mdm', '-d', '/var/lib/mdm',
'-s', '/usr/bin/nologin', 'mdm'])
libcalamares.utils.chroot_call(['passwd', '-l', 'mdm'])
libcalamares.utils.chroot_call(
['chown', 'root:mdm', '/var/lib/mdm'])
libcalamares.utils.chroot_call(['chmod', '1770', '/var/lib/mdm'])
if default_desktop_environment is not None:
os.system(
"sed -i \"s|default.desktop|{!s}.desktop|g\" {!s}/etc/mdm/custom.conf".format(default_desktop_environment.desktop_file,root_mount_point))
"sed -i \"s|default.desktop|{!s}.desktop|g\" {!s}/etc/mdm/custom.conf".format(
default_desktop_environment.desktop_file, root_mount_point))
else:
libcalamares.utils.debug("mdm selected but not installed")
displaymanagers.remove("mdm")
@ -314,7 +331,8 @@ def run():
['chmod', '+r', '/etc/lxdm/lxdm.conf'])
if default_desktop_environment is not None:
os.system(
"sed -i -e \"s|^.*session=.*|session={!s}|\" {!s}/etc/lxdm/lxdm.conf".format(default_desktop_environment.executable,root_mount_point))
"sed -i -e \"s|^.*session=.*|session={!s}|\" {!s}/etc/lxdm/lxdm.conf".format(
default_desktop_environment.executable, root_mount_point))
else:
libcalamares.utils.debug("lxdm selected but not installed")
displaymanagers.remove("lxdm")
@ -326,8 +344,9 @@ def run():
if libcalamares.utils.chroot_call(['getent', 'group', 'kdm']) != 0:
libcalamares.utils.chroot_call(['groupadd', '-g', '135', 'kdm'])
if libcalamares.utils.chroot_call(['getent', 'passwd', 'kdm']) != 0:
libcalamares.utils.chroot_call(['useradd', '-u', '135', '-g', 'kdm', '-d',
'/var/lib/kdm', '-s', '/bin/false', '-r', '-M', 'kdm'])
libcalamares.utils.chroot_call(
['useradd', '-u', '135', '-g', 'kdm', '-d',
'/var/lib/kdm', '-s', '/bin/false', '-r', '-M', 'kdm'])
libcalamares.utils.chroot_call(
['chown', '-R', '135:135', 'var/lib/kdm'])
else:

@ -32,16 +32,13 @@ def run():
accumulator += "This job's path: " + libcalamares.job.working_path + "\n"
accumulator += str(libcalamares.job.configuration)
accumulator += " *** globalstorage test ***\n"
accumulator += "lala: " + \
str(libcalamares.globalstorage.contains("lala")) + "\n"
accumulator += "foo: " + \
str(libcalamares.globalstorage.contains("foo")) + "\n"
accumulator += "lala: " + str(libcalamares.globalstorage.contains("lala")) + "\n"
accumulator += "foo: " + str(libcalamares.globalstorage.contains("foo")) + "\n"
accumulator += "count: " + str(libcalamares.globalstorage.count()) + "\n"
libcalamares.globalstorage.insert("item2", "value2")
libcalamares.globalstorage.insert("item3", 3)
accumulator += "keys: {}\n".format(str(libcalamares.globalstorage.keys()))
accumulator += "remove: {}\n".format(
str(libcalamares.globalstorage.remove("item2")))
accumulator += "remove: {}\n".format(str(libcalamares.globalstorage.remove("item2")))
accumulator += "values: {} {} {}\n".format(
str(libcalamares.globalstorage.value("foo")),
str(libcalamares.globalstorage.value("item2")),

@ -26,16 +26,17 @@ import shutil
from collections import OrderedDict
from libcalamares.utils import check_chroot_call
def cpuinfo():
''' Return the information in /proc/cpuinfo
as a dictionary in the following format:
"""
Return the information in /proc/cpuinfo as a dictionary in the following format:
cpu_info['proc0']={...}
cpu_info['proc1']={...}
'''
"""
cpuinfo=OrderedDict()
procinfo=OrderedDict()
cpuinfo = OrderedDict()
procinfo = OrderedDict()
nprocs = 0
with open('/proc/cpuinfo') as f:
@ -45,7 +46,7 @@ def cpuinfo():
cpuinfo["proc{!s}".format(nprocs)] = procinfo
nprocs += 1
# Reset
procinfo=OrderedDict()
procinfo = OrderedDict()
else:
if len(line.split(':')) == 2:
procinfo[line.split(':')[0].strip()] = line.split(':')[1].strip()
@ -54,6 +55,7 @@ def cpuinfo():
return cpuinfo
def set_mkinitcpio_hooks_and_modules(hooks, modules, root_mount_point):
""" Set up mkinitcpio.conf """
@ -72,6 +74,7 @@ def set_mkinitcpio_hooks_and_modules(hooks, modules, root_mount_point):
with open(path, "w") as mkinitcpio_file:
mkinitcpio_file.write("\n".join(mklins) + "\n")
def modify_mkinitcpio_conf(partitions, root_mount_point):
""" Modifies mkinitcpio.conf """

@ -3,20 +3,20 @@
#
# === This file is part of Calamares - <http://github.com/calamares> ===
#
# Copyright 2014, Kevin Kofler <kevin.kofler@chello.at>
# Copyright 2014, Kevin Kofler <kevin.kofler@chello.at>
#
# Calamares is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Calamares is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Calamares is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# Calamares is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
# You should have received a copy of the GNU General Public License
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
import libcalamares
import os

@ -35,7 +35,6 @@ except ImportError:
class Job:
def __init__(self, working_path, doc, cfg_doc):
self.module_name = doc["name"]
self.pretty_name = "Testing job " + doc["name"]

Loading…
Cancel
Save