Package module: fix packages-could-be-objects code
- Check for 'list' when it's actually a 'dict' is strange. Reverse logic to consider 'str' a package name and everything else is special. - Refactor to handle the difference between package names and packages-with-script-data in one place. - Add code and config documentation. - Switch sample configurations to dummy-backend.
This commit is contained in:
parent
d66434985e
commit
6c36534206
@ -42,13 +42,26 @@ class PackageManager(metaclass=abc.ABCMeta):
|
||||
|
||||
@abc.abstractmethod
|
||||
def install(self, pkgs, from_local=False):
|
||||
"""
|
||||
Install a list of packages (named) into the system.
|
||||
Although this handles lists, in practice it is called
|
||||
with one package at a time.
|
||||
|
||||
@param pkgs: list[str]
|
||||
list of package names
|
||||
@param from_local: bool
|
||||
if True, then these are local packages (on disk) and the
|
||||
pkgs names are paths.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def remove(self, pkgs):
|
||||
""" Removes packages.
|
||||
"""
|
||||
Removes packages.
|
||||
|
||||
:param pkgs:
|
||||
@param pkgs: list[str]
|
||||
list of package names
|
||||
"""
|
||||
pass
|
||||
|
||||
@ -60,6 +73,23 @@ class PackageManager(metaclass=abc.ABCMeta):
|
||||
if script != "":
|
||||
check_target_env_call(script.split(" "))
|
||||
|
||||
def install_package(self, packagedata, from_local=False):
|
||||
"""
|
||||
Install a package from a single entry in the install list.
|
||||
This can be either a single package name, or an object
|
||||
with pre- and post-scripts.
|
||||
|
||||
@param packagedata: str|dict
|
||||
@param from_local: bool
|
||||
see install.from_local
|
||||
"""
|
||||
if isinstance(packagedata, str):
|
||||
self.install([packagedata], from_local=from_local)
|
||||
else:
|
||||
self.run(packagedata["pre-script"])
|
||||
self.install([packagedata["package"]], from_local=from_local)
|
||||
self.run(packagedata["post-script"])
|
||||
|
||||
|
||||
class PMPackageKit(PackageManager):
|
||||
backend = "packagekit"
|
||||
@ -126,7 +156,7 @@ class PMDnf(PackageManager):
|
||||
|
||||
|
||||
class PMUrpmi(PackageManager):
|
||||
backend = "urpmi";
|
||||
backend = "urpmi"
|
||||
|
||||
def install(self, pkgs, from_local=False):
|
||||
check_target_env_call(["urpmi", "--download-all", "--no-suggests",
|
||||
@ -215,6 +245,9 @@ class PMDummy(PackageManager):
|
||||
def update_db(self):
|
||||
libcalamares.utils.debug("Updating DB")
|
||||
|
||||
def run(self, script):
|
||||
libcalamares.utils.debug("Running script '" + str(script) + "'")
|
||||
|
||||
|
||||
backend_managers = [
|
||||
(c.backend, c)
|
||||
@ -247,32 +280,17 @@ def run_operations(pkgman, entry):
|
||||
for key in entry.keys():
|
||||
entry[key] = subst_locale(entry[key])
|
||||
if key == "install":
|
||||
if isinstance(entry[key], list):
|
||||
for package in entry[key]:
|
||||
pkgman.run(package["pre-script"])
|
||||
pkgman.install([package["package"]])
|
||||
pkgman.run(package["post-script"])
|
||||
else:
|
||||
pkgman.install(entry[key])
|
||||
pkgman.install_package(package)
|
||||
elif key == "try_install":
|
||||
# we make a separate package manager call for each package so a
|
||||
# single failing package won't stop all of them
|
||||
for package in entry[key]:
|
||||
if isinstance(package, str):
|
||||
try:
|
||||
pkgman.install([package])
|
||||
pkgman.install_package(package)
|
||||
except subprocess.CalledProcessError:
|
||||
warn_text = "WARNING: could not install package "
|
||||
warn_text += package
|
||||
libcalamares.utils.debug(warn_text)
|
||||
else:
|
||||
try:
|
||||
pkgman.run(package["pre-script"])
|
||||
pkgman.install([package["package"]])
|
||||
pkgman.run(package["post-script"])
|
||||
except subprocess.CalledProcessError:
|
||||
warn_text = "WARNING: could not install packages "
|
||||
warn_text += package["package"]
|
||||
warn_text += str(package)
|
||||
libcalamares.utils.debug(warn_text)
|
||||
elif key == "remove":
|
||||
pkgman.remove(entry[key])
|
||||
|
@ -10,9 +10,13 @@
|
||||
# - pacman - Pacman
|
||||
# - portage - Gentoo package manager
|
||||
# - entropy - Sabayon package manager
|
||||
# - dummy - Dummy manager, only logs
|
||||
#
|
||||
backend: packagekit
|
||||
backend: dummy
|
||||
|
||||
# If set to true, a package-manager specific update procedure
|
||||
# is run first (only if there is internet) to update the list
|
||||
# of packages and dependencies.
|
||||
update_db: true
|
||||
|
||||
#
|
||||
|
@ -1,5 +1,6 @@
|
||||
backend: dummy
|
||||
rootMountPoint: /tmp/mount
|
||||
packageOperations:
|
||||
operations:
|
||||
- install:
|
||||
- pre-script: touch /tmp/foo
|
||||
package: vi
|
||||
|
Loading…
Reference in New Issue
Block a user