From 9cdb6734bfa83fe3476b096f8bbe851567330240 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Apr 2018 08:02:16 -0400 Subject: [PATCH 1/5] [packages] If locale is empty, pretend it is 'en'. - Otherwise packages like vi-$LOCALE will be retained in the package list, which will cause install problems. --- src/modules/packages/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index 60ede34fa..3105474f8 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -318,7 +318,10 @@ def subst_locale(plist): """ locale = libcalamares.globalstorage.value("locale") if not locale: - return plist + # It is possible to skip the locale-setting entirely. + # Then pretend it is "en", so that {LOCALE}-decorated + # package names are removed from the list. + locale = "en" ret = [] for packagedata in plist: From fd1279dbe36aef6665d04eb78b413434dfc8b3f2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Apr 2018 08:19:45 -0400 Subject: [PATCH 2/5] [welcome] Make the example configuration less strict --- src/modules/welcome/welcome.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index 18e71b1ef..b7ce5cfcd 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -25,6 +25,6 @@ requirements: # If any of these conditions are not met, the user cannot # continue past the welcome page. required: - - storage + # - storage - ram - - root + # - root From 36aede52ef6c0d4ddb3b8cf5f752f798446ba769 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Apr 2018 08:20:01 -0400 Subject: [PATCH 3/5] [packages] Example configuration installs a localization package --- src/modules/packages/packages.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/packages/packages.conf b/src/modules/packages/packages.conf index 2d6ca116f..38497c2f5 100644 --- a/src/modules/packages/packages.conf +++ b/src/modules/packages/packages.conf @@ -127,6 +127,7 @@ update_db: true operations: - install: - vi + - vi-${LOCALE} - wget - binutils - remove: From 4c04260b9783d3c14c6187fced640292d41725e8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Apr 2018 08:28:29 -0400 Subject: [PATCH 4/5] [packages] Don't change the global package list. - Count only the packages that will be changed, given the current locale settings. - Preserve global storage unchanged (don't remove any locale-packages). --- src/modules/packages/main.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index 3105474f8..f252bc15f 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -367,20 +367,20 @@ def run_operations(pkgman, entry): global group_packages, completed_packages, mode_packages for key in entry.keys(): - entry[key] = subst_locale(entry[key]) - group_packages = len(entry[key]) + package_list = subst_locale(entry[key]) + group_packages = len(package_list) if key == "install": _change_mode(INSTALL) - if all([isinstance(x, str) for x in entry[key]]): - pkgman.install(entry[key]) + if all([isinstance(x, str) for x in package_list]): + pkgman.install(package_list) else: - for package in entry[key]: + for package in package_list: pkgman.install_package(package) elif key == "try_install": _change_mode(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]: + for package in package_list: try: pkgman.install_package(package) except subprocess.CalledProcessError: @@ -389,10 +389,10 @@ def run_operations(pkgman, entry): libcalamares.utils.debug(warn_text) elif key == "remove": _change_mode(REMOVE) - pkgman.remove(entry[key]) + pkgman.remove(package_list) elif key == "try_remove": _change_mode(REMOVE) - for package in entry[key]: + for package in package_list: try: pkgman.remove([package]) except subprocess.CalledProcessError: @@ -401,9 +401,9 @@ def run_operations(pkgman, entry): libcalamares.utils.debug(warn_text) elif key == "localInstall": _change_mode(INSTALL) - pkgman.install(entry[key], from_local=True) + pkgman.install(package_list, from_local=True) - completed_packages += len(entry[key]) + completed_packages += len(package_list) libcalamares.job.setprogress(completed_packages * 1.0 / total_packages) libcalamares.utils.debug(pretty_name()) @@ -447,7 +447,7 @@ def run(): completed_packages = 0 for op in operations: for packagelist in op.values(): - total_packages += len(packagelist) + total_packages += len(subst_locale(packagelist)) if not total_packages: # Avoids potential divide-by-zero in progress reporting From b8e61445531f2ec1a56d3720a16755df6c69aafa Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Apr 2018 12:10:05 -0400 Subject: [PATCH 5/5] [locale] Document how the locale entry in Global Storage works. - Make the BCP47 value explicitly lower-case. - Add some constness and encapsulation. - Fix up documentation in the packages module explaining the format of the ${LOCALE} replacement (now forced to lower-case, but it is also only the language part, not e.g. en-UK). FIXES #922 --- src/modules/locale/LocaleConfiguration.cpp | 14 +++++++++++--- src/modules/locale/LocaleConfiguration.h | 9 +++++++-- src/modules/locale/LocalePage.cpp | 6 ++++-- src/modules/packages/packages.conf | 17 +++++++++++------ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/modules/locale/LocaleConfiguration.cpp b/src/modules/locale/LocaleConfiguration.cpp index b8f5f6a9e..c612c50c4 100644 --- a/src/modules/locale/LocaleConfiguration.cpp +++ b/src/modules/locale/LocaleConfiguration.cpp @@ -43,9 +43,11 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale, const QStringList& availableLocales, const QString& countryCode ) { - LocaleConfiguration lc = LocaleConfiguration(); + LocaleConfiguration lc; + + // Note that the documentation how this works is in packages.conf QString language = languageLocale.split( '_' ).first(); - lc.myLanguageLocaleBcp47 = QLocale(language).bcp47Name(); + lc.myLanguageLocaleBcp47 = QLocale(language).bcp47Name().toLower(); QStringList linesForLanguage; for ( const QString &line : availableLocales ) @@ -288,7 +290,7 @@ LocaleConfiguration::isEmpty() const QMap< QString, QString > -LocaleConfiguration::toMap() +LocaleConfiguration::toMap() const { QMap< QString, QString > map; @@ -324,3 +326,9 @@ LocaleConfiguration::toMap() return map; } + +QString +LocaleConfiguration::toBcp47() const +{ + return myLanguageLocaleBcp47; +} diff --git a/src/modules/locale/LocaleConfiguration.h b/src/modules/locale/LocaleConfiguration.h index 073d19a5b..04d1db456 100644 --- a/src/modules/locale/LocaleConfiguration.h +++ b/src/modules/locale/LocaleConfiguration.h @@ -35,16 +35,21 @@ public: bool isEmpty() const; + QMap< QString, QString > toMap() const; + // Note that the documentation how this works is in packages.conf + QString toBcp47() const; + // These become all uppercase in locale.conf, but we keep them lowercase here to // avoid confusion with locale.h. QString lang, lc_numeric, lc_time, lc_monetary, lc_paper, lc_name, lc_address, lc_telephone, lc_measurement, lc_identification; - QString myLanguageLocaleBcp47; - QMap< QString, QString > toMap(); // If the user has explicitly selected language (from the dialog) // or numbers format, set these to avoid implicit changes to them. bool explicit_lang, explicit_lc; + +private: + QString myLanguageLocaleBcp47; }; #endif // LOCALECONFIGURATION_H diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 2172586ff..8b05ccfba 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -489,8 +489,10 @@ LocalePage::updateGlobalStorage() ->insert( "locationRegion", location.region ); Calamares::JobQueue::instance()->globalStorage() ->insert( "locationZone", location.zone ); - Calamares::JobQueue::instance()->globalStorage() - ->insert( "locale", m_selectedLocaleConfiguration.myLanguageLocaleBcp47); + + const QString bcp47 = m_selectedLocaleConfiguration.toBcp47(); + Calamares::JobQueue::instance()->globalStorage()->insert( "locale", bcp47 ); + cDebug() << "Updated locale globals, BCP47=" << bcp47; // If we're in chroot mode (normal install mode), then we immediately set the // timezone on the live system. diff --git a/src/modules/packages/packages.conf b/src/modules/packages/packages.conf index 38497c2f5..7e5717b7c 100644 --- a/src/modules/packages/packages.conf +++ b/src/modules/packages/packages.conf @@ -76,7 +76,7 @@ update_db: true # pre-script: touch /tmp/installing-vi # post-script: rm -f /tmp/installing-vi # -# The pre- and post-scripts are optional, but not both optional: using +# The pre- and post-scripts are optional, but you cannot leave both out: using # "package: vi" with neither script option will trick Calamares into # trying to install a package named "package: vi", which is unlikely to work. # @@ -84,11 +84,16 @@ update_db: true # packages for software based on the selected system locale. By including # the string LOCALE in the package name, the following happens: # -# - if the system locale is English (generally US English; en_GB is a valid -# localization), then the package is not installed at all, -# - otherwise $LOCALE or ${LOCALE} is replaced by the Bcp47 name of the selected -# system locale, e.g. nl_BE. Note that just plain LOCALE will not be replaced, -# so foo-LOCALE will be unchanged, while foo-$LOCALE will be changed. +# - 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 +# 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. # # The following installs localizations for vi, if they are relevant; if # there is no localization, installation continues normally.