Package module: optimize & fix
- Expand example configurations - Optimize commoon case of just listing package names - Do locale substitution in both kinds of cases
This commit is contained in:
parent
6c36534206
commit
3799a26b3c
@ -249,24 +249,53 @@ class PMDummy(PackageManager):
|
|||||||
libcalamares.utils.debug("Running script '" + str(script) + "'")
|
libcalamares.utils.debug("Running script '" + str(script) + "'")
|
||||||
|
|
||||||
|
|
||||||
|
# Collect all the subclasses of PackageManager defined above,
|
||||||
|
# and index them based on the backend property of each class.
|
||||||
backend_managers = [
|
backend_managers = [
|
||||||
(c.backend, c)
|
(c.backend, c)
|
||||||
for c in globals().values()
|
for c in globals().values()
|
||||||
if type(c) is abc.ABCMeta and issubclass(c, PackageManager) and c.backend]
|
if type(c) is abc.ABCMeta and issubclass(c, PackageManager) and c.backend]
|
||||||
|
|
||||||
|
|
||||||
def subst_locale(list):
|
def subst_locale(plist):
|
||||||
ret = []
|
"""
|
||||||
|
Returns a locale-aware list of packages, based on @p plist.
|
||||||
|
Package names that contain LOCALE are localized with the
|
||||||
|
BCP47 name of the chosen system locale; if the system
|
||||||
|
locale is 'en' (e.g. English, US) then these localized
|
||||||
|
packages are dropped from the list.
|
||||||
|
|
||||||
|
@param plist: list[str|dict]
|
||||||
|
Candidate packages to install.
|
||||||
|
@return: list[str|dict]
|
||||||
|
"""
|
||||||
locale = libcalamares.globalstorage.value("locale")
|
locale = libcalamares.globalstorage.value("locale")
|
||||||
if locale:
|
if not locale:
|
||||||
for e in list:
|
return plist
|
||||||
if locale != "en":
|
|
||||||
entry = Template(e)
|
ret = []
|
||||||
ret.append(entry.safe_substitute(LOCALE=locale))
|
for packagedata in plist:
|
||||||
elif 'LOCALE' not in e:
|
if isinstance(packagedata, str):
|
||||||
ret.append(e)
|
packagename = packagedata
|
||||||
else:
|
else:
|
||||||
ret = list
|
packagename = packagedata["package"]
|
||||||
|
|
||||||
|
# Update packagename: substitute LOCALE, and drop packages
|
||||||
|
# if locale is en and LOCALE is in the package name.
|
||||||
|
if locale != "en":
|
||||||
|
packagename = Template(packagename).safe_substitute(LOCALE=locale)
|
||||||
|
elif 'LOCALE' in packagename:
|
||||||
|
packagename = None
|
||||||
|
|
||||||
|
if packagename is not None:
|
||||||
|
# Put it back in packagedata
|
||||||
|
if isinstance(packagedata, str):
|
||||||
|
packagedata = packagename
|
||||||
|
else:
|
||||||
|
packagedata["package"] = packagename
|
||||||
|
|
||||||
|
ret.append(packagedata)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
@ -280,8 +309,11 @@ def run_operations(pkgman, entry):
|
|||||||
for key in entry.keys():
|
for key in entry.keys():
|
||||||
entry[key] = subst_locale(entry[key])
|
entry[key] = subst_locale(entry[key])
|
||||||
if key == "install":
|
if key == "install":
|
||||||
for package in entry[key]:
|
if all([isinstance(x, str) for x in entry[key]]):
|
||||||
pkgman.install_package(package)
|
pkgman.install(entry[key])
|
||||||
|
else:
|
||||||
|
for package in entry[key]:
|
||||||
|
pkgman.install_package(package)
|
||||||
elif key == "try_install":
|
elif key == "try_install":
|
||||||
# we make a separate package manager call for each package so a
|
# we make a separate package manager call for each package so a
|
||||||
# single failing package won't stop all of them
|
# single failing package won't stop all of them
|
||||||
|
@ -50,3 +50,12 @@ update_db: true
|
|||||||
# - pkg7
|
# - pkg7
|
||||||
# - localInstall:
|
# - localInstall:
|
||||||
# - /path/to/pkg8
|
# - /path/to/pkg8
|
||||||
|
operations:
|
||||||
|
- install:
|
||||||
|
- vi
|
||||||
|
- wget
|
||||||
|
- binutils
|
||||||
|
- remove:
|
||||||
|
- vi
|
||||||
|
- wget
|
||||||
|
- binutils
|
||||||
|
@ -6,6 +6,7 @@ operations:
|
|||||||
package: vi
|
package: vi
|
||||||
post-script: rm /tmp/foo
|
post-script: rm /tmp/foo
|
||||||
- wget
|
- wget
|
||||||
|
- binutils
|
||||||
- remove:
|
- remove:
|
||||||
- vi
|
- vi
|
||||||
- wget
|
- wget
|
||||||
|
Loading…
Reference in New Issue
Block a user