From 3799a26b3ca97c83214ebb282363b05e88e3e289 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 29 Aug 2017 06:33:07 -0400 Subject: [PATCH] Package module: optimize & fix - Expand example configurations - Optimize commoon case of just listing package names - Do locale substitution in both kinds of cases --- src/modules/packages/main.py | 58 +++++++++++++++++++++++------- src/modules/packages/packages.conf | 9 +++++ src/modules/packages/test.yaml | 1 + 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index dcd999727..9eb0a8ea0 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -249,24 +249,53 @@ class PMDummy(PackageManager): 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 = [ (c.backend, c) for c in globals().values() if type(c) is abc.ABCMeta and issubclass(c, PackageManager) and c.backend] -def subst_locale(list): - ret = [] +def subst_locale(plist): + """ + 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") - if locale: - for e in list: - if locale != "en": - entry = Template(e) - ret.append(entry.safe_substitute(LOCALE=locale)) - elif 'LOCALE' not in e: - ret.append(e) - else: - ret = list + if not locale: + return plist + + ret = [] + for packagedata in plist: + if isinstance(packagedata, str): + packagename = packagedata + else: + 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 @@ -280,8 +309,11 @@ def run_operations(pkgman, entry): for key in entry.keys(): entry[key] = subst_locale(entry[key]) if key == "install": - for package in entry[key]: - pkgman.install_package(package) + if all([isinstance(x, str) for x in entry[key]]): + pkgman.install(entry[key]) + else: + for package in 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 diff --git a/src/modules/packages/packages.conf b/src/modules/packages/packages.conf index da47cec25..7bf589243 100644 --- a/src/modules/packages/packages.conf +++ b/src/modules/packages/packages.conf @@ -50,3 +50,12 @@ update_db: true # - pkg7 # - localInstall: # - /path/to/pkg8 +operations: + - install: + - vi + - wget + - binutils + - remove: + - vi + - wget + - binutils diff --git a/src/modules/packages/test.yaml b/src/modules/packages/test.yaml index 49c1a5197..8902b657a 100644 --- a/src/modules/packages/test.yaml +++ b/src/modules/packages/test.yaml @@ -6,6 +6,7 @@ operations: package: vi post-script: rm /tmp/foo - wget + - binutils - remove: - vi - wget