Merge pull request #152 from calamares/python-branding
Give Python modules access to the branding information.
This commit is contained in:
commit
df47842fc7
@ -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:
|
||||
|
@ -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"
|
||||
|
@ -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() );
|
||||
}
|
||||
|
@ -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 <QDir>
|
||||
#include <QFile>
|
||||
#include <QPixmap>
|
||||
#include <QVariantMap>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
@ -48,7 +50,8 @@ QStringList Branding::s_stringEntryStrings =
|
||||
"version",
|
||||
"shortVersion",
|
||||
"versionedName",
|
||||
"shortVersionedName"
|
||||
"shortVersionedName",
|
||||
"shortProductName"
|
||||
};
|
||||
|
||||
|
||||
@ -200,6 +203,16 @@ Branding::slideshowPaths() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Branding::setGlobals( GlobalStorage* globalStorage ) const
|
||||
{
|
||||
QVariantMap brandingMap;
|
||||
foreach ( const QString& key, s_stringEntryStrings )
|
||||
brandingMap.insert( key, m_strings.value( key ) );
|
||||
globalStorage->insert( "branding", brandingMap );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Branding::bail( const QString& message )
|
||||
{
|
||||
|
@ -30,6 +30,8 @@
|
||||
namespace Calamares
|
||||
{
|
||||
|
||||
class GlobalStorage;
|
||||
|
||||
class UIDLLEXPORT Branding : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -40,7 +42,8 @@ public:
|
||||
Version,
|
||||
ShortVersion,
|
||||
VersionedName,
|
||||
ShortVersionedName
|
||||
ShortVersionedName,
|
||||
ShortProductName
|
||||
};
|
||||
|
||||
enum ImageEntry : short
|
||||
@ -63,6 +66,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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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["shortProductName"]
|
||||
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["shortProductName"]
|
||||
kernel = libcalamares.job.configuration["kernel"]
|
||||
fb_img = libcalamares.job.configuration["fallback"]
|
||||
partitions = libcalamares.globalstorage.value("partitions")
|
||||
@ -105,11 +107,13 @@ def create_fallback(uuid, fallback_path):
|
||||
|
||||
|
||||
def create_loader(loader_path):
|
||||
distribution = libcalamares.job.configuration["distribution"]
|
||||
branding = libcalamares.globalstorage.value("branding")
|
||||
distribution = branding["shortProductName"]
|
||||
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:
|
||||
@ -122,11 +126,13 @@ 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["shortProductName"]
|
||||
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")
|
||||
|
@ -1,3 +1,5 @@
|
||||
rootMountPoint: /tmp/mount
|
||||
bootLoader:
|
||||
installPath: /dev/sdb
|
||||
branding:
|
||||
shortProductName: "Generic Distro"
|
||||
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
# Replace 'LinuxDistribution' with your distribution name - for example with 'Manjaro'
|
||||
distributor: LinuxDistribution
|
@ -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")
|
||||
@ -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["shortProductName"]
|
||||
return modify_grub_default(partitions, root_mount_point, distributor)
|
||||
|
Loading…
Reference in New Issue
Block a user