Merge pull request #719 from siduction/pep8-packages
Fixed pep8 whining in module packages
This commit is contained in:
commit
f93a7fbd28
@ -6,6 +6,7 @@
|
|||||||
# Copyright 2014, Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
|
# Copyright 2014, Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
|
||||||
# Copyright 2015-2017, Teo Mrnjavac <teo@kde.org>
|
# Copyright 2015-2017, Teo Mrnjavac <teo@kde.org>
|
||||||
# Copyright 2016-2017, Kyle Robbertze <kyle@aims.ac.za>
|
# Copyright 2016-2017, Kyle Robbertze <kyle@aims.ac.za>
|
||||||
|
# Copyright 2017, Alf Gaida <agaida@siduction.org>
|
||||||
#
|
#
|
||||||
# Calamares is free software: you can redistribute it and/or modify
|
# Calamares is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -25,8 +26,10 @@ import libcalamares
|
|||||||
from libcalamares.utils import check_target_env_call, target_env_call
|
from libcalamares.utils import check_target_env_call, target_env_call
|
||||||
from string import Template
|
from string import Template
|
||||||
|
|
||||||
|
|
||||||
class PackageManager:
|
class PackageManager:
|
||||||
""" Package manager class.
|
"""
|
||||||
|
Package manager class.
|
||||||
|
|
||||||
:param backend:
|
:param backend:
|
||||||
"""
|
"""
|
||||||
@ -43,15 +46,19 @@ class PackageManager:
|
|||||||
for pkg in pkgs:
|
for pkg in pkgs:
|
||||||
check_target_env_call(["pkcon", "-py", "install", pkg])
|
check_target_env_call(["pkcon", "-py", "install", pkg])
|
||||||
elif self.backend == "zypp":
|
elif self.backend == "zypp":
|
||||||
check_target_env_call(["zypper", "--non-interactive", "--quiet-install", "install",
|
check_target_env_call(["zypper", "--non-interactive",
|
||||||
"--auto-agree-with-licenses", "install"] + pkgs)
|
"--quiet-install", "install",
|
||||||
|
"--auto-agree-with-licenses",
|
||||||
|
"install"] + pkgs)
|
||||||
elif self.backend == "yum":
|
elif self.backend == "yum":
|
||||||
check_target_env_call(["yum", "install", "-y"] + pkgs)
|
check_target_env_call(["yum", "install", "-y"] + pkgs)
|
||||||
elif self.backend == "dnf":
|
elif self.backend == "dnf":
|
||||||
check_target_env_call(["dnf", "install", "-y"] + pkgs)
|
check_target_env_call(["dnf", "install", "-y"] + pkgs)
|
||||||
elif self.backend == "urpmi":
|
elif self.backend == "urpmi":
|
||||||
check_target_env_call(["urpmi", "--download-all", "--no-suggests", "--no-verify-rpm",
|
check_target_env_call(["urpmi", "--download-all", "--no-suggests",
|
||||||
"--fastunsafe", "--ignoresize", "--nolock", "--auto"] + pkgs)
|
"--no-verify-rpm", "--fastunsafe",
|
||||||
|
"--ignoresize", "--nolock",
|
||||||
|
"--auto"] + pkgs)
|
||||||
elif self.backend == "apt":
|
elif self.backend == "apt":
|
||||||
check_target_env_call(["apt-get", "-q", "-y", "install"] + pkgs)
|
check_target_env_call(["apt-get", "-q", "-y", "install"] + pkgs)
|
||||||
elif self.backend == "pacman":
|
elif self.backend == "pacman":
|
||||||
@ -60,7 +67,8 @@ class PackageManager:
|
|||||||
else:
|
else:
|
||||||
pacman_flags = "-Sy"
|
pacman_flags = "-Sy"
|
||||||
|
|
||||||
check_target_env_call(["pacman", pacman_flags, "--noconfirm"] + pkgs)
|
check_target_env_call(["pacman", pacman_flags,
|
||||||
|
"--noconfirm"] + pkgs)
|
||||||
elif self.backend == "portage":
|
elif self.backend == "portage":
|
||||||
check_target_env_call(["emerge", "-v"] + pkgs)
|
check_target_env_call(["emerge", "-v"] + pkgs)
|
||||||
elif self.backend == "entropy":
|
elif self.backend == "entropy":
|
||||||
@ -75,17 +83,23 @@ class PackageManager:
|
|||||||
for pkg in pkgs:
|
for pkg in pkgs:
|
||||||
check_target_env_call(["pkcon", "-py", "remove", pkg])
|
check_target_env_call(["pkcon", "-py", "remove", pkg])
|
||||||
elif self.backend == "zypp":
|
elif self.backend == "zypp":
|
||||||
check_target_env_call(["zypper", "--non-interactive", "remove"] + pkgs)
|
check_target_env_call(["zypper", "--non-interactive",
|
||||||
|
"remove"] + pkgs)
|
||||||
elif self.backend == "yum":
|
elif self.backend == "yum":
|
||||||
check_target_env_call(["yum", "--disablerepo=*", "-C", "-y", "remove"] + pkgs)
|
check_target_env_call(["yum", "--disablerepo=*", "-C", "-y",
|
||||||
|
"remove"] + pkgs)
|
||||||
elif self.backend == "dnf":
|
elif self.backend == "dnf":
|
||||||
# ignore the error code for now because dnf thinks removing a nonexistent package is an error
|
# ignore the error code for now because dnf thinks removing a
|
||||||
target_env_call(["dnf", "--disablerepo=*", "-C", "-y", "remove"] + pkgs)
|
# nonexistent package is an error
|
||||||
|
target_env_call(["dnf", "--disablerepo=*", "-C", "-y",
|
||||||
|
"remove"] + pkgs)
|
||||||
elif self.backend == "urpmi":
|
elif self.backend == "urpmi":
|
||||||
check_target_env_call(["urpme", "--auto"] + pkgs)
|
check_target_env_call(["urpme", "--auto"] + pkgs)
|
||||||
elif self.backend == "apt":
|
elif self.backend == "apt":
|
||||||
check_target_env_call(["apt-get", "--purge", "-q", "-y", "remove"] + pkgs)
|
check_target_env_call(["apt-get", "--purge", "-q", "-y",
|
||||||
check_target_env_call(["apt-get", "--purge", "-q", "-y", "autoremove"])
|
"remove"] + pkgs)
|
||||||
|
check_target_env_call(["apt-get", "--purge", "-q", "-y",
|
||||||
|
"autoremove"])
|
||||||
elif self.backend == "pacman":
|
elif self.backend == "pacman":
|
||||||
check_target_env_call(["pacman", "-Rs", "--noconfirm"] + pkgs)
|
check_target_env_call(["pacman", "-Rs", "--noconfirm"] + pkgs)
|
||||||
elif self.backend == "portage":
|
elif self.backend == "portage":
|
||||||
@ -120,7 +134,7 @@ def subst_locale(list):
|
|||||||
locale = libcalamares.globalstorage.value("locale")
|
locale = libcalamares.globalstorage.value("locale")
|
||||||
if locale:
|
if locale:
|
||||||
for e in list:
|
for e in list:
|
||||||
if locale != "en":
|
if locale != "en":
|
||||||
entry = Template(e)
|
entry = Template(e)
|
||||||
ret.append(entry.safe_substitute(LOCALE=locale))
|
ret.append(entry.safe_substitute(LOCALE=locale))
|
||||||
elif 'LOCALE' not in e:
|
elif 'LOCALE' not in e:
|
||||||
@ -129,8 +143,10 @@ def subst_locale(list):
|
|||||||
ret = list
|
ret = list
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def run_operations(pkgman, entry):
|
def run_operations(pkgman, entry):
|
||||||
""" Call package manager with given parameters.
|
"""
|
||||||
|
Call package manager with given parameters.
|
||||||
|
|
||||||
:param pkgman:
|
:param pkgman:
|
||||||
:param entry:
|
:param entry:
|
||||||
@ -146,21 +162,25 @@ def run_operations(pkgman, entry):
|
|||||||
else:
|
else:
|
||||||
pkgman.install(entry[key])
|
pkgman.install(entry[key])
|
||||||
elif key == "try_install":
|
elif key == "try_install":
|
||||||
# we make a separate package manager call for each package so a single
|
# we make a separate package manager call for each package so a
|
||||||
# failing package won't stop all of them
|
# single failing package won't stop all of them
|
||||||
for package in entry[key]:
|
for package in entry[key]:
|
||||||
if isinstance(package, str):
|
if isinstance(package, str):
|
||||||
try:
|
try:
|
||||||
pkgman.install([package])
|
pkgman.install([package])
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
libcalamares.utils.debug("WARNING: could not install package {}".format(package))
|
warn_text = "WARNING: could not install package "
|
||||||
|
warn_text += package
|
||||||
|
libcalamares.utils.debug(warn_text)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
pkgman.run(package["pre-script"])
|
pkgman.run(package["pre-script"])
|
||||||
pkgman.install([package["package"]])
|
pkgman.install([package["package"]])
|
||||||
pkgman.run(package["post-script"])
|
pkgman.run(package["post-script"])
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
libcalamares.utils.debug("WARNING: could not install packages {}".format(package["package"]))
|
warn_text = "WARNING: could not install packages "
|
||||||
|
warn_text += package["package"]
|
||||||
|
libcalamares.utils.debug(warn_text)
|
||||||
elif key == "remove":
|
elif key == "remove":
|
||||||
pkgman.remove(entry[key])
|
pkgman.remove(entry[key])
|
||||||
elif key == "try_remove":
|
elif key == "try_remove":
|
||||||
@ -168,20 +188,24 @@ def run_operations(pkgman, entry):
|
|||||||
try:
|
try:
|
||||||
pkgman.remove([package])
|
pkgman.remove([package])
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
libcalamares.utils.debug("WARNING: could not remove package {}".format(package))
|
warn_text = "WARNING: could not remove package "
|
||||||
|
warn_text += package
|
||||||
|
libcalamares.utils.debug(warn_text)
|
||||||
elif key == "localInstall":
|
elif key == "localInstall":
|
||||||
pkgman.install(entry[key], from_local=True)
|
pkgman.install(entry[key], from_local=True)
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
""" Calls routine with detected package manager to install locale packages
|
"""
|
||||||
|
Calls routine with detected package manager to install locale packages
|
||||||
or remove drivers not needed on the installed system.
|
or remove drivers not needed on the installed system.
|
||||||
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
backend = libcalamares.job.configuration.get("backend")
|
backend = libcalamares.job.configuration.get("backend")
|
||||||
|
|
||||||
if backend not in ("packagekit", "zypp", "yum", "dnf", "urpmi", "apt", "pacman", "portage", "entropy"):
|
if backend not in ("packagekit", "zypp", "yum", "dnf", "urpmi", "apt",
|
||||||
|
"pacman", "portage", "entropy"):
|
||||||
return "Bad backend", "backend=\"{}\"".format(backend)
|
return "Bad backend", "backend=\"{}\"".format(backend)
|
||||||
|
|
||||||
pkgman = PackageManager(backend)
|
pkgman = PackageManager(backend)
|
||||||
@ -195,6 +219,7 @@ def run():
|
|||||||
run_operations(pkgman, entry)
|
run_operations(pkgman, entry)
|
||||||
|
|
||||||
if libcalamares.globalstorage.contains("packageOperations"):
|
if libcalamares.globalstorage.contains("packageOperations"):
|
||||||
run_operations(pkgman, libcalamares.globalstorage.value("packageOperations"))
|
run_operations(pkgman,
|
||||||
|
libcalamares.globalstorage.value("packageOperations"))
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user