From 98f99fa5bf0f9b7dcf026f24543cd38adc7f0d17 Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Sun, 16 Nov 2014 04:19:53 +0100 Subject: [PATCH 01/10] Introduce and use a Calamares::Branding::setGlobals method. The method creates a map called "branding" in the global storage, and inserts an entry for each of the branding strings. This makes the branding information accessible to the Python modules. The method is called by CalamaresApplication::initJobQueue. This is necessary because the Branding class is in libcalamaresui, so Python modules cannot access it directly. --- src/calamares/CalamaresApplication.cpp | 3 ++- src/libcalamaresui/Branding.cpp | 15 +++++++++++++++ src/libcalamaresui/Branding.h | 9 +++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index c7851d6b7..78b16e3bb 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -316,5 +316,6 @@ CalamaresApplication::onPluginsReady() void CalamaresApplication::initJobQueue() { - new Calamares::JobQueue( this ); + Calamares::JobQueue *jobQueue = new Calamares::JobQueue( this ); + Calamares::Branding::instance()->setGlobals( jobQueue->globalStorage() ); } diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index b1672f899..8943f9ea9 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -18,6 +18,7 @@ #include "Branding.h" +#include "GlobalStorage.h" #include "utils/CalamaresUtils.h" #include "utils/Logger.h" #include "utils/YamlUtils.h" @@ -26,6 +27,7 @@ #include #include #include +#include #include @@ -200,6 +202,19 @@ Branding::slideshowPaths() const } +void +Branding::setGlobals( GlobalStorage* globalStorage ) const +{ + QVariantMap brandingMap; + brandingMap.insert( "productName", string( ProductName ) ); + brandingMap.insert( "version", string( Version ) ); + brandingMap.insert( "shortVersion", string( ShortVersion ) ); + brandingMap.insert( "versionedName", string( VersionedName ) ); + brandingMap.insert( "shortVersionedName", string( ShortVersionedName ) ); + globalStorage->insert( "branding", brandingMap ); +} + + void Branding::bail( const QString& message ) { diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index d86c92878..991aafa39 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -30,6 +30,8 @@ namespace Calamares { +class GlobalStorage; + class UIDLLEXPORT Branding : public QObject { Q_OBJECT @@ -63,6 +65,13 @@ public: QPixmap image( Branding::ImageEntry imageEntry, const QSize& size ) const; QStringList slideshowPaths() const; + /** + * Creates a map called "branding" in the global storage, and inserts an + * entry for each of the branding strings. This makes the branding + * information accessible to the Python modules. + */ + void setGlobals( GlobalStorage* globalStorage ) const; + private: static Branding* s_instance; From 3cf5baadc1ab732ccfdeafbfd39ebf994874a97d Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Sun, 16 Nov 2014 04:26:51 +0100 Subject: [PATCH 02/10] bootloader: Get the distribution name from the branding. Remove the redundant "distribution" setting from bootloader.conf. --- src/modules/bootloader/bootloader.conf | 5 ++--- src/modules/bootloader/main.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/modules/bootloader/bootloader.conf b/src/modules/bootloader/bootloader.conf index 34ea11ddd..af79d1bb9 100644 --- a/src/modules/bootloader/bootloader.conf +++ b/src/modules/bootloader/bootloader.conf @@ -1,7 +1,6 @@ --- -# Gummiboot configuration files settings, set preferred distribution name and amount of time before -# default selection boots -distribution: KaOS-kf5 +# Gummiboot configuration files settings, set kernel and initramfs file names +# and amount of time before default selection boots kernel: /vmlinuz-linux img: /initramfs-linux.img fallback: /initramfs-linux-fallback.img diff --git a/src/modules/bootloader/main.py b/src/modules/bootloader/main.py index e868fd948..50ae9d773 100644 --- a/src/modules/bootloader/main.py +++ b/src/modules/bootloader/main.py @@ -53,7 +53,8 @@ def get_uuid(): def create_conf(uuid, conf_path): - distribution = libcalamares.job.configuration["distribution"] + branding = libcalamares.globalstorage.value("branding") + distribution = branding["productName"] kernel = libcalamares.job.configuration["kernel"] img = libcalamares.job.configuration["img"] partitions = libcalamares.globalstorage.value("partitions") @@ -79,7 +80,8 @@ def create_conf(uuid, conf_path): def create_fallback(uuid, fallback_path): - distribution = libcalamares.job.configuration["distribution"] + branding = libcalamares.globalstorage.value("branding") + distribution = branding["productName"] kernel = libcalamares.job.configuration["kernel"] fb_img = libcalamares.job.configuration["fallback"] partitions = libcalamares.globalstorage.value("partitions") @@ -105,7 +107,8 @@ def create_fallback(uuid, fallback_path): def create_loader(loader_path): - distribution = libcalamares.job.configuration["distribution"] + branding = libcalamares.globalstorage.value("branding") + distribution = branding["productName"] timeout = libcalamares.job.configuration["timeout"] lines = [ 'timeout %s\n' % timeout, @@ -122,7 +125,8 @@ def install_bootloader(boot_loader, fw_type): if fw_type == 'efi': install_path = libcalamares.globalstorage.value("rootMountPoint") uuid = get_uuid() - distribution = libcalamares.job.configuration["distribution"] + branding = libcalamares.globalstorage.value("branding") + distribution = branding["productName"] conf_path = os.path.join( install_path, "boot", "loader", "entries", "%s.conf" % distribution) fallback_path = os.path.join( From 8f5b0585cbc83c049e033d40e2386c78563a0494 Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Sun, 16 Nov 2014 04:33:27 +0100 Subject: [PATCH 03/10] grubcfg: Get the distribution name from the branding. Remove the redundant "distributor" setting from grubcfg.conf (and the entire grubcfg.conf file that has no settings left for now). --- src/modules/grubcfg/grubcfg.conf | 3 --- src/modules/grubcfg/main.py | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) delete mode 100644 src/modules/grubcfg/grubcfg.conf diff --git a/src/modules/grubcfg/grubcfg.conf b/src/modules/grubcfg/grubcfg.conf deleted file mode 100644 index bdbe2dbcd..000000000 --- a/src/modules/grubcfg/grubcfg.conf +++ /dev/null @@ -1,3 +0,0 @@ ---- -# Replace 'LinuxDistribution' with your distribution name - for example with 'Manjaro' -distributor: LinuxDistribution diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index 26d26a14c..c80348346 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -66,5 +66,6 @@ def modify_grub_default(partitions, root_mount_point, distributor): def run(): partitions = libcalamares.globalstorage.value("partitions") root_mount_point = libcalamares.globalstorage.value("rootMountPoint") - distributor = libcalamares.job.configuration["distributor"] + branding = libcalamares.globalstorage.value("branding") + distributor = branding["productName"] return modify_grub_default(partitions, root_mount_point, distributor) From 76450b44a3786a50a2878d7bc3ca64ab5eb0420c Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Sun, 16 Nov 2014 04:56:11 +0100 Subject: [PATCH 04/10] bootloader: Ensure that the file names are valid. Change any '/' slashes to '-' dashes. Also change spaces to underscores while we are at it. --- src/modules/bootloader/main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/modules/bootloader/main.py b/src/modules/bootloader/main.py index 50ae9d773..e27473ba3 100644 --- a/src/modules/bootloader/main.py +++ b/src/modules/bootloader/main.py @@ -110,9 +110,10 @@ def create_loader(loader_path): branding = libcalamares.globalstorage.value("branding") distribution = branding["productName"] timeout = libcalamares.job.configuration["timeout"] + file_name_sanitizer = str.maketrans(" /", "_-") lines = [ 'timeout %s\n' % timeout, - 'default %s\n' % distribution, + 'default %s\n' % distribution.translate(file_name_sanitizer), ] with open(loader_path, 'w') as f: @@ -127,10 +128,11 @@ def install_bootloader(boot_loader, fw_type): uuid = get_uuid() branding = libcalamares.globalstorage.value("branding") distribution = branding["productName"] + file_name_sanitizer = str.maketrans(" /", "_-") conf_path = os.path.join( - install_path, "boot", "loader", "entries", "%s.conf" % distribution) + install_path, "boot", "loader", "entries", "%s.conf" % distribution.translate(file_name_sanitizer)) fallback_path = os.path.join( - install_path, "boot", "loader", "entries", "%s-fallback.conf" % distribution) + install_path, "boot", "loader", "entries", "%s-fallback.conf" % distribution.translate(file_name_sanitizer)) loader_path = os.path.join( install_path, "boot", "loader", "loader.conf") partitions = libcalamares.globalstorage.value("partitions") From cde7356f0d3211f0ae95be316408bebe0173c285 Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Sun, 16 Nov 2014 04:58:00 +0100 Subject: [PATCH 05/10] grubcfg: Quote the GRUB_DISTRIBUTOR value. --- src/modules/grubcfg/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index c80348346..01a15fe61 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -56,7 +56,7 @@ def modify_grub_default(partitions, root_mount_point, distributor): elif lines[i].startswith("GRUB_CMDLINE_LINUX_DEFAULT"): lines[i] = kernel_cmd elif lines[i].startswith("#GRUB_DISTRIBUTOR") or lines[i].startswith("GRUB_DISTRIBUTOR"): - lines[i] = "GRUB_DISTRIBUTOR=%s" % distributor + lines[i] = "GRUB_DISTRIBUTOR='%s'" % distributor.replace("'", "'\\''") with open(default_grub, 'w') as grub_file: grub_file.write("\n".join(lines) + "\n") From 538b457ea89879ef18750ed87c1d687525851716 Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Sun, 16 Nov 2014 05:14:57 +0100 Subject: [PATCH 06/10] branding: Add a shortProductName entry. This is what the bootloader modules really want, and it was also missing for consistency with the other branding entries. --- src/branding/default/branding.desc | 1 + src/libcalamaresui/Branding.cpp | 10 ++++------ src/libcalamaresui/Branding.h | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 93ca927cf..06ffe4747 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -3,6 +3,7 @@ componentName: default strings: productName: Generic GNU/Linux + shortProductName: Generic version: 1.0 LTS shortVersion: 1.0 versionedName: Generic GNU/Linux 1.0 LTS "Rusty Trombone" diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 8943f9ea9..43a7714fc 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -50,7 +50,8 @@ QStringList Branding::s_stringEntryStrings = "version", "shortVersion", "versionedName", - "shortVersionedName" + "shortVersionedName", + "shortProductName" }; @@ -206,11 +207,8 @@ void Branding::setGlobals( GlobalStorage* globalStorage ) const { QVariantMap brandingMap; - brandingMap.insert( "productName", string( ProductName ) ); - brandingMap.insert( "version", string( Version ) ); - brandingMap.insert( "shortVersion", string( ShortVersion ) ); - brandingMap.insert( "versionedName", string( VersionedName ) ); - brandingMap.insert( "shortVersionedName", string( ShortVersionedName ) ); + foreach ( const QString& key, s_stringEntryStrings ) + brandingMap.insert( key, m_strings.value( key ) ); globalStorage->insert( "branding", brandingMap ); } diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 991aafa39..6a4446ecd 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -42,7 +42,8 @@ public: Version, ShortVersion, VersionedName, - ShortVersionedName + ShortVersionedName, + ShortProductName }; enum ImageEntry : short From e420341ba6b84810ff7aa540982d20fb71304dfe Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Sun, 16 Nov 2014 05:17:06 +0100 Subject: [PATCH 07/10] bootloader: Use shortProductName. This is particularly useful if the full product name contains "GNU/Linux" or "Linux", because e.g. "Generic GNU/Linux GNU/Linux" does not make sense. --- src/modules/bootloader/main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/bootloader/main.py b/src/modules/bootloader/main.py index e27473ba3..efca4a1b8 100644 --- a/src/modules/bootloader/main.py +++ b/src/modules/bootloader/main.py @@ -54,7 +54,7 @@ def get_uuid(): def create_conf(uuid, conf_path): branding = libcalamares.globalstorage.value("branding") - distribution = branding["productName"] + distribution = branding["shortProductName"] kernel = libcalamares.job.configuration["kernel"] img = libcalamares.job.configuration["img"] partitions = libcalamares.globalstorage.value("partitions") @@ -81,7 +81,7 @@ def create_conf(uuid, conf_path): def create_fallback(uuid, fallback_path): branding = libcalamares.globalstorage.value("branding") - distribution = branding["productName"] + distribution = branding["shortProductName"] kernel = libcalamares.job.configuration["kernel"] fb_img = libcalamares.job.configuration["fallback"] partitions = libcalamares.globalstorage.value("partitions") @@ -108,7 +108,7 @@ def create_fallback(uuid, fallback_path): def create_loader(loader_path): branding = libcalamares.globalstorage.value("branding") - distribution = branding["productName"] + distribution = branding["shortProductName"] timeout = libcalamares.job.configuration["timeout"] file_name_sanitizer = str.maketrans(" /", "_-") lines = [ @@ -127,7 +127,7 @@ def install_bootloader(boot_loader, fw_type): install_path = libcalamares.globalstorage.value("rootMountPoint") uuid = get_uuid() branding = libcalamares.globalstorage.value("branding") - distribution = branding["productName"] + distribution = branding["shortProductName"] file_name_sanitizer = str.maketrans(" /", "_-") conf_path = os.path.join( install_path, "boot", "loader", "entries", "%s.conf" % distribution.translate(file_name_sanitizer)) From 48eca95a2655443d0350fa5869ceaf54695abc0a Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Sun, 16 Nov 2014 05:18:11 +0100 Subject: [PATCH 08/10] grubcfg: Use shortProductName. This is particularly useful if the full product name contains "GNU/Linux" or "Linux", because e.g. "Generic GNU/Linux GNU/Linux" does not make sense. --- src/modules/grubcfg/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index 01a15fe61..3e3ad81f0 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -67,5 +67,5 @@ def run(): partitions = libcalamares.globalstorage.value("partitions") root_mount_point = libcalamares.globalstorage.value("rootMountPoint") branding = libcalamares.globalstorage.value("branding") - distributor = branding["productName"] + distributor = branding["shortProductName"] return modify_grub_default(partitions, root_mount_point, distributor) From c27c053482718ecc4881c8e8af91e6bda5a3fa9c Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Sun, 16 Nov 2014 15:02:32 +0100 Subject: [PATCH 09/10] hacking/GlobalStorage.md: Document the "branding" dictionary. --- hacking/GlobalStorage.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hacking/GlobalStorage.md b/hacking/GlobalStorage.md index 0e024b16c..000282662 100644 --- a/hacking/GlobalStorage.md +++ b/hacking/GlobalStorage.md @@ -10,6 +10,17 @@ A dictionary with the following keys: - `installPath`: device where the boot loader should be installed ("/dev/sda", "/dev/sdb1"...) +## branding + +A dictionary with the following keys (loaded from branding.desc): + +- `productName`: distribution unversioned product name (long version) +- `shortProductName`: distribution unversioned product name (short version) +- `version`: distribution version number (long version) +- `shortVersion`: distribution version number (short version) +- `versionedName`: distribution product name and version (long version) +- `shortVersionedName`: distribution product name and version (short version) + ## partitions A list of dictionaries, one per partition. The dictionary contains the following keys: From 75921ec1251e1f4d1bb4a17545a7ef73cef0d30e Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Sun, 16 Nov 2014 15:05:00 +0100 Subject: [PATCH 10/10] bootloader/test.yaml: Define the shortProductName. --- src/modules/bootloader/test.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/bootloader/test.yaml b/src/modules/bootloader/test.yaml index 3b9852e63..1cd6c418f 100644 --- a/src/modules/bootloader/test.yaml +++ b/src/modules/bootloader/test.yaml @@ -1,3 +1,5 @@ rootMountPoint: /tmp/mount bootLoader: installPath: /dev/sdb +branding: + shortProductName: "Generic Distro"