mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-30 10:55:37 -04:00
[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.
This commit is contained in:
parent
34255b4cf5
commit
0a73d57808
2 changed files with 30 additions and 8 deletions
|
@ -126,7 +126,8 @@ class PackageManager(metaclass=abc.ABCMeta):
|
||||||
"""
|
"""
|
||||||
Install a package from a single entry in the install list.
|
Install a package from a single entry in the install list.
|
||||||
This can be either a single package name, or an object
|
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 packagedata: str|dict
|
||||||
@param from_local: bool
|
@param from_local: bool
|
||||||
|
@ -139,6 +140,22 @@ class PackageManager(metaclass=abc.ABCMeta):
|
||||||
self.install([packagedata["package"]], from_local=from_local)
|
self.install([packagedata["package"]], from_local=from_local)
|
||||||
self.run(packagedata["post-script"])
|
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):
|
class PMPackageKit(PackageManager):
|
||||||
backend = "packagekit"
|
backend = "packagekit"
|
||||||
|
@ -440,19 +457,27 @@ def run_operations(pkgman, entry):
|
||||||
libcalamares.utils.warning(warn_text)
|
libcalamares.utils.warning(warn_text)
|
||||||
elif key == "remove":
|
elif key == "remove":
|
||||||
_change_mode(REMOVE)
|
_change_mode(REMOVE)
|
||||||
|
if all([isinstance(x, str) for x in package_list]):
|
||||||
pkgman.remove(package_list)
|
pkgman.remove(package_list)
|
||||||
|
else:
|
||||||
|
for package in package_list:
|
||||||
|
pkgman.remove_package(package)
|
||||||
elif key == "try_remove":
|
elif key == "try_remove":
|
||||||
_change_mode(REMOVE)
|
_change_mode(REMOVE)
|
||||||
for package in package_list:
|
for package in package_list:
|
||||||
try:
|
try:
|
||||||
pkgman.remove([package])
|
pkgman.remove_package(package)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
warn_text = "Could not remove package "
|
warn_text = "Could not remove package "
|
||||||
warn_text += package
|
warn_text += str(package)
|
||||||
libcalamares.utils.warning(warn_text)
|
libcalamares.utils.warning(warn_text)
|
||||||
elif key == "localInstall":
|
elif key == "localInstall":
|
||||||
_change_mode(INSTALL)
|
_change_mode(INSTALL)
|
||||||
|
if all([isinstance(x, str) for x in package_list]):
|
||||||
pkgman.install(package_list, from_local=True)
|
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)
|
completed_packages += len(package_list)
|
||||||
libcalamares.job.setprogress(completed_packages * 1.0 / total_packages)
|
libcalamares.job.setprogress(completed_packages * 1.0 / total_packages)
|
||||||
|
|
|
@ -91,9 +91,6 @@ update_system: false
|
||||||
# "package: vi" with neither script option will trick Calamares into
|
# "package: vi" with neither script option will trick Calamares into
|
||||||
# trying to install a package named "package: vi", which is unlikely to work.
|
# 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
|
# Any package name may be localized; this is used to install localization
|
||||||
# packages for software based on the selected system locale. By including
|
# 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:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue