From 05588a1ffd6419778d8ccb4a55a9d6b49406a476 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 27 Nov 2018 12:39:19 +0100 Subject: [PATCH 1/3] [packages] Improvide conf documentation - about LOCALE packages - about pre- and post-scripts CC: #1057 --- src/modules/packages/packages.conf | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/modules/packages/packages.conf b/src/modules/packages/packages.conf index 974ba07a7..40701841e 100644 --- a/src/modules/packages/packages.conf +++ b/src/modules/packages/packages.conf @@ -89,20 +89,25 @@ update_system: false # "package: vi" with neither script option will trick Calamares into # trying to install a package named "package: vi", which is unlikely to work. # +# Pre- and post-scripts are supported only in the install and try_install +# operations. +# # Any package name may be localized; this is used to install localization # packages for software based on the selected system locale. By including -# the string LOCALE in the package name, the following happens: +# the string `LOCALE` in the package name, the following happens: # # - if the system locale is English (any variety), then the package is not # installed at all, -# - otherwise $LOCALE or ${LOCALE} is replaced by the 'lower-cased' BCP47 +# - otherwise `$LOCALE` or `${LOCALE}` is replaced by the 'lower-cased' BCP47 # name of the 'language' part of the selected system locale (not the # country/region/dialect part), e.g. selecting "nl_BE" will use "nl" # here. # -# Take care that just plain LOCALE will not be replaced, so foo-LOCALE will -# be left unchanged, while foo-$LOCALE will be changed. However, foo-LOCALE -# 'will' be removed from the list of packages, if English is selected. +# Take care that just plain `LOCALE` will not be replaced, so `foo-LOCALE` will +# be left unchanged, while `foo-$LOCALE` will be changed. However, `foo-LOCALE` +# **will** be removed from the list of packages (i.e. not installed), if +# English is selected. If a non-English locale is selected, then `foo-LOCALE` +# will be installed, unchanged (no language-name-substitution occurs). # # The following installs localizations for vi, if they are relevant; if # there is no localization, installation continues normally. From 34255b4cf51f8e38910f6eab03385a26887c0b1d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 27 Nov 2018 12:48:31 +0100 Subject: [PATCH 2/3] [packages] Document *localInstall* operation. --- src/modules/packages/packages.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/packages/packages.conf b/src/modules/packages/packages.conf index 40701841e..a71a7df15 100644 --- a/src/modules/packages/packages.conf +++ b/src/modules/packages/packages.conf @@ -64,6 +64,8 @@ update_system: false # - localInstall: this is used to call the package manager # to install a package from a path-to-a-package. This is # useful if you have a static package archive on the install media. +# The *pacman* package manager is the only one to specially support +# this operation (all others treat this the same as *install*). # - remove, try_remove: will call the package manager to # remove one or more packages. The remove target will # abort the whole installation if package-removal fails, From 0a73d57808d3f9cc14b0d06a9b9784c79db47d53 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 27 Nov 2018 12:52:24 +0100 Subject: [PATCH 3/3] [packages] Add support for pre- and post- scripts everywhere - for remove and localInstall, add support for pre- and post- scripts like there already was for install. This feels like there's code duplication going on, but I haven't thought of an elegant way to distinguish the available operations so that I can pass around functions instead. --- src/modules/packages/main.py | 35 +++++++++++++++++++++++++----- src/modules/packages/packages.conf | 3 --- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index bffd6a945..9116cf2ef 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -126,7 +126,8 @@ class PackageManager(metaclass=abc.ABCMeta): """ 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. + with pre- and post-scripts. If @p packagedata is a dict, + it is assumed to follow the documented structure. @param packagedata: str|dict @param from_local: bool @@ -139,6 +140,22 @@ class PackageManager(metaclass=abc.ABCMeta): self.install([packagedata["package"]], from_local=from_local) self.run(packagedata["post-script"]) + def remove_package(self, packagedata): + """ + Remove a package from a single entry in the remove list. + This can be either a single package name, or an object + with pre- and post-scripts. If @p packagedata is a dict, + it is assumed to follow the documented structure. + + @param packagedata: str|dict + """ + if isinstance(packagedata, str): + self.remove([packagedata], from_local=from_local) + else: + self.run(packagedata["pre-script"]) + self.remove([packagedata["package"]], from_local=from_local) + self.run(packagedata["post-script"]) + class PMPackageKit(PackageManager): backend = "packagekit" @@ -440,19 +457,27 @@ def run_operations(pkgman, entry): libcalamares.utils.warning(warn_text) elif key == "remove": _change_mode(REMOVE) - pkgman.remove(package_list) + if all([isinstance(x, str) for x in package_list]): + pkgman.remove(package_list) + else: + for package in package_list: + pkgman.remove_package(package) elif key == "try_remove": _change_mode(REMOVE) for package in package_list: try: - pkgman.remove([package]) + pkgman.remove_package(package) except subprocess.CalledProcessError: warn_text = "Could not remove package " - warn_text += package + warn_text += str(package) libcalamares.utils.warning(warn_text) elif key == "localInstall": _change_mode(INSTALL) - pkgman.install(package_list, from_local=True) + if all([isinstance(x, str) for x in package_list]): + pkgman.install(package_list, from_local=True) + else: + for package in package_list: + pkgman.install_package(package, from_local=True) completed_packages += len(package_list) libcalamares.job.setprogress(completed_packages * 1.0 / total_packages) diff --git a/src/modules/packages/packages.conf b/src/modules/packages/packages.conf index a71a7df15..94f3cfdb6 100644 --- a/src/modules/packages/packages.conf +++ b/src/modules/packages/packages.conf @@ -91,9 +91,6 @@ update_system: false # "package: vi" with neither script option will trick Calamares into # trying to install a package named "package: vi", which is unlikely to work. # -# Pre- and post-scripts are supported only in the install and try_install -# operations. -# # Any package name may be localized; this is used to install localization # packages for software based on the selected system locale. By including # the string `LOCALE` in the package name, the following happens: