diff --git a/CHANGES b/CHANGES index 70e7ec8c9..b0a823883 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,19 @@ contributors are listed. Note that Calamares does not have a historical changelog -- this log starts with version 3.2.0. The release notes on the website will have to do for older versions. +# 3.2.5 (unreleased) # + +This release contains contributions from (alphabetically by first name): + +## Core ## + +## Modules ## + + * Python modules: several modules have had translations added. This is + usually only visible when the module runs as part of the *exec* step, + when the module's *pretty name* is displayed. In addition, error + messages are now translated. + # 3.2.4 (2019-02-12) # This release contains contributions from (alphabetically by first name): @@ -66,6 +79,7 @@ This release contains contributions from (alphabetically by first name): the installation media to the target stystem. This can be used, for instance, for block-level-identical installations. + # 3.2.3 (2019-01-09) # This release contains contributions from (alphabetically by first name): diff --git a/CMakeLists.txt b/CMakeLists.txt index cc7d91d43..0aeb8a584 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,8 +75,8 @@ set( CALAMARES_DESCRIPTION_SUMMARY set( CALAMARES_VERSION_MAJOR 3 ) set( CALAMARES_VERSION_MINOR 2 ) -set( CALAMARES_VERSION_PATCH 4 ) -set( CALAMARES_VERSION_RC 0 ) +set( CALAMARES_VERSION_PATCH 5 ) +set( CALAMARES_VERSION_RC 1 ) ### Transifex (languages) info @@ -240,7 +240,7 @@ include( CMakeColors ) ### DEPENDENCIES # -find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED Core Gui Widgets LinguistTools Svg Quick QuickWidgets ) +find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED Concurrent Core Gui Widgets LinguistTools Svg Quick QuickWidgets ) find_package( YAMLCPP ${YAMLCPP_VERSION} REQUIRED ) if( INSTALL_POLKIT ) find_package( PolkitQt5-1 REQUIRED ) diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index 98aa2121f..b75fb6495 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -2,7 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2014, Teo Mrnjavac - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,9 +68,9 @@ logLevel() } static void -log( const char* msg, unsigned int debugLevel, bool toDisk = true ) +log( const char* msg, unsigned int debugLevel ) { - if ( toDisk || debugLevel < s_threshold ) + if ( true ) { QMutexLocker lock( &s_mutex ); diff --git a/src/libcalamares/utils/NamedEnum.h b/src/libcalamares/utils/NamedEnum.h index 69abf4bd1..047ae6f19 100644 --- a/src/libcalamares/utils/NamedEnum.h +++ b/src/libcalamares/utils/NamedEnum.h @@ -51,7 +51,7 @@ struct NamedEnumTable * * static const NamedEnumTable c{ {"red", Colors::Red } }; */ - NamedEnumTable( const std::initializer_list< pair_t >& v ) : table( v ) { /* static_assert( v.size() > 0 ); */ }; + NamedEnumTable( const std::initializer_list< pair_t >& v ) : table( v ) { /* static_assert( v.size() > 0 ); */ } /** @brief Find a name @p s in the table. * diff --git a/src/modules/displaymanager/main.py b/src/modules/displaymanager/main.py index 08eeb6fdb..4413aefbb 100644 --- a/src/modules/displaymanager/main.py +++ b/src/modules/displaymanager/main.py @@ -768,11 +768,11 @@ def run(): displaymanagers.remove(dm) if not dm_impl: - return ( - _("No display managers selected for the displaymanager module."), - _("The list is empty after checking for installed display managers.") + libcalamares.utils.warning( + "No display managers selected for the displaymanager module. " + "The list is empty after checking for installed display managers." ) - + return None # Pick up remaining settings if "defaultDesktopEnvironment" in libcalamares.job.configuration: diff --git a/src/modules/locale/LocaleConfiguration.h b/src/modules/locale/LocaleConfiguration.h index abe90ffcb..5e99b1f37 100644 --- a/src/modules/locale/LocaleConfiguration.h +++ b/src/modules/locale/LocaleConfiguration.h @@ -31,7 +31,7 @@ public: explicit LocaleConfiguration(); /// @brief Create a locale with everything set to the given @p localeName explicit LocaleConfiguration( const QString& localeName /* "en_US.UTF-8" */ ) - : LocaleConfiguration( localeName, localeName ) { }; + : LocaleConfiguration( localeName, localeName ) { } /// @brief Create a locale with language and formats separate explicit LocaleConfiguration( const QString& localeName, const QString& formatsName ); diff --git a/src/modules/machineid/main.py b/src/modules/machineid/main.py index c4c473246..092fc7196 100644 --- a/src/modules/machineid/main.py +++ b/src/modules/machineid/main.py @@ -6,6 +6,7 @@ # Copyright 2014, Kevin Kofler # Copyright 2016, Philip Müller # Copyright 2017, Alf Gaida +# Copyright 2019, Adriaan de Groot # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index d61064041..d09bcd149 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -408,6 +408,56 @@ isEfiBootable( const Partition* candidate ) flags.testFlag( PartitionTable::FlagBoot ); } +QString +findFS( QString fsName, FileSystem::Type* fsType ) +{ + QStringList fsLanguage { QLatin1Literal( "C" ) }; // Required language list to turn off localization + if ( fsName.isEmpty() ) + fsName = QStringLiteral( "ext4" ); + + FileSystem::Type tmpType = FileSystem::typeForName( fsName, fsLanguage ); + if ( tmpType != FileSystem::Unknown ) + { + cDebug() << "Found filesystem" << fsName; + if ( fsType ) + *fsType = tmpType; + return fsName; + } + + // Second pass: try case-insensitive + const auto fstypes = FileSystem::types(); + for ( FileSystem::Type t : fstypes ) + { + if ( 0 == QString::compare( fsName, FileSystem::nameForType( t, fsLanguage ), Qt::CaseInsensitive ) ) + { + QString fsRealName = FileSystem::nameForType( t, fsLanguage ); + cDebug() << "Filesystem name" << fsName << "translated to" << fsRealName; + if ( fsType ) + *fsType = t; + return fsRealName; + } + } + + cDebug() << "Filesystem" << fsName << "not found, using ext4"; + fsName = QStringLiteral( "ext4" ); + // fsType can be used to check whether fsName was a valid filesystem. + if (fsType) + *fsType = FileSystem::Unknown; +#ifdef DEBUG_FILESYSTEMS + // This bit is for distro's debugging their settings, and shows + // all the strings that KPMCore is matching against for FS type. + { + Logger::CDebug d; + using TR = Logger::DebugRow< int, QString >; + const auto fstypes = FileSystem::types(); + d << "Available types (" << fstypes.count() << ')'; + for ( FileSystem::Type t : fstypes ) + d << TR( static_cast( t ), FileSystem::nameForType( t, fsLanguage ) ); + } +#endif + return fsName; +} + } // nmamespace PartUtils /* Implementation of methods for FstabEntry, from OsproberEntry.h */ diff --git a/src/modules/partition/core/PartUtils.h b/src/modules/partition/core/PartUtils.h index b94e20567..c7da86c06 100644 --- a/src/modules/partition/core/PartUtils.h +++ b/src/modules/partition/core/PartUtils.h @@ -22,6 +22,10 @@ #include "OsproberEntry.h" +// KPMcore +#include + +// Qt #include class PartitionCoreModule; @@ -73,6 +77,15 @@ bool isEfiSystem(); * the partition table layout, this may mean different flags. */ bool isEfiBootable( const Partition* candidate ); + +/** @brief translate @p fsName into a recognized name and type + * + * Makes several attempts to translate the string into a + * name that KPMCore will recognize. + * The corresponding filesystem type is stored in @p fsType, and + * its value is FileSystem::Unknown if @p fsName is not recognized. + */ +QString findFS( QString fsName, FileSystem::Type* fsType ); } #endif // PARTUTILS_H diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index c2489620f..39341fddd 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -18,27 +18,50 @@ * along with Calamares. If not, see . */ +#include "GlobalStorage.h" +#include "JobQueue.h" + #include "core/PartitionLayout.h" #include "core/KPMHelpers.h" #include "core/PartitionActions.h" #include "core/PartitionInfo.h" +#include "core/PartUtils.h" #include #include #include +static FileSystem::Type +getDefaultFileSystemType() +{ + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + FileSystem::Type defaultFS = FileSystem::Ext4; + + if ( gs->contains( "defaultFileSystemType" ) ) + { + PartUtils::findFS( gs->value( "defaultFileSystemType" ).toString(), &defaultFS); + if ( defaultFS == FileSystem::Unknown ) + defaultFS = FileSystem::Ext4; + } + + return defaultFS; +} + PartitionLayout::PartitionLayout() { + m_defaultFsType = getDefaultFileSystemType(); } PartitionLayout::PartitionLayout( PartitionLayout::PartitionEntry entry ) { - partLayout.append( entry ); + m_defaultFsType = getDefaultFileSystemType(); + m_partLayout.append( entry ); } PartitionLayout::PartitionLayout( const PartitionLayout& layout ) - : partLayout( layout.partLayout ) + : m_partLayout( layout.m_partLayout ) + , m_defaultFsType( layout.m_defaultFsType ) { } @@ -49,7 +72,7 @@ PartitionLayout::~PartitionLayout() void PartitionLayout::addEntry( PartitionLayout::PartitionEntry entry ) { - partLayout.append( entry ); + m_partLayout.append( entry ); } static double @@ -115,9 +138,9 @@ PartitionLayout::addEntry( const QString& mountPoint, const QString& size, const PartitionLayout::PartitionEntry entry( size, min ); entry.partMountPoint = mountPoint; - entry.partFileSystem = FileSystem::Ext4; + entry.partFileSystem = m_defaultFsType; - partLayout.append( entry ); + m_partLayout.append( entry ); } void @@ -127,9 +150,11 @@ PartitionLayout::addEntry( const QString& label, const QString& mountPoint, cons entry.partLabel = label; entry.partMountPoint = mountPoint; - entry.partFileSystem = FileSystem::typeForName( fs ); + PartUtils::findFS( fs, &entry.partFileSystem ); + if ( entry.partFileSystem == FileSystem::Unknown ) + entry.partFileSystem = m_defaultFsType; - partLayout.append( entry ); + m_partLayout.append( entry ); } static qint64 @@ -175,7 +200,7 @@ PartitionLayout::execute( Device *dev, qint64 firstSector, // TODO: Refine partition sizes to make sure there is room for every partition // Use a default (200-500M ?) minimum size for partition without minSize - foreach( const PartitionLayout::PartitionEntry& part, partLayout ) + foreach( const PartitionLayout::PartitionEntry& part, m_partLayout ) { Partition *currentPartition = nullptr; @@ -194,7 +219,7 @@ PartitionLayout::execute( Device *dev, qint64 firstSector, parent, *dev, role, - static_cast(part.partFileSystem), + part.partFileSystem, firstSector, end, PartitionTable::FlagNone @@ -206,7 +231,7 @@ PartitionLayout::execute( Device *dev, qint64 firstSector, parent, *dev, role, - static_cast(part.partFileSystem), + part.partFileSystem, firstSector, end, luksPassphrase, diff --git a/src/modules/partition/core/PartitionLayout.h b/src/modules/partition/core/PartitionLayout.h index 5e216122c..999e10425 100644 --- a/src/modules/partition/core/PartitionLayout.h +++ b/src/modules/partition/core/PartitionLayout.h @@ -24,6 +24,7 @@ // KPMcore #include +#include // Qt #include @@ -48,7 +49,7 @@ public: { QString partLabel; QString partMountPoint; - int partFileSystem = 0; + FileSystem::Type partFileSystem = FileSystem::Unknown; double partSize = 0.0L; SizeUnit partSizeUnit = Percent; double partMinSize = 0.0L; @@ -76,7 +77,8 @@ public: QList< Partition* > execute( Device *dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase, PartitionNode* parent, const PartitionRole& role ); private: - QList< PartitionEntry > partLayout; + FileSystem::Type m_defaultFsType; + QList< PartitionEntry > m_partLayout; }; #endif /* PARTITIONLAYOUT_H */ diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 7c980cf49..21783c251 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -1248,7 +1248,7 @@ ChoicePage::setupActions() } if ( PartUtils::canBeReplaced( *it ) ) { - cDebug() << ".. contains replacable" << it; + cDebug() << ".. contains replaceable" << it; atLeastOneCanBeReplaced = true; } if ( (*it)->isMounted() ) diff --git a/src/modules/partition/gui/CreateVolumeGroupDialog.cpp b/src/modules/partition/gui/CreateVolumeGroupDialog.cpp index fe5c40be8..a255e9902 100644 --- a/src/modules/partition/gui/CreateVolumeGroupDialog.cpp +++ b/src/modules/partition/gui/CreateVolumeGroupDialog.cpp @@ -34,7 +34,7 @@ CreateVolumeGroupDialog::CreateVolumeGroupDialog( QString& vgName, , m_selectedPVs( selectedPVs ) , m_peSize( pSize ) { - setWindowTitle( "Create Volume Group" ); + setWindowTitle( tr( "Create Volume Group" ) ); peSize()->setValue( pSize ); diff --git a/src/modules/partition/gui/PartitionDialogHelpers.cpp b/src/modules/partition/gui/PartitionDialogHelpers.cpp index 3dcf41f58..02d91ca4b 100644 --- a/src/modules/partition/gui/PartitionDialogHelpers.cpp +++ b/src/modules/partition/gui/PartitionDialogHelpers.cpp @@ -44,7 +44,7 @@ void standardMountPoints(QComboBox& combo) { combo.clear(); - combo.addItem( combo.tr( "(no mount point)" ) ); + combo.addItem( QObject::tr( "(no mount point)" ) ); combo.addItems( standardMountPoints() ); } diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index a152db14b..3c71302e0 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -493,55 +493,6 @@ nameToChoice( QString name, bool& ok ) return names.find( name, ok ); } -/** @brief translate @p defaultFS into a recognized name - * - * Makes several attempts to translate the string into a - * name that KPMCore will recognize. - */ -static QString -findFS( QString defaultFS ) -{ - QStringList fsLanguage { QLatin1Literal( "C" ) }; // Required language list to turn off localization - if ( defaultFS.isEmpty() ) - { - cWarning() << "Partition-module setting *defaultFileSystemType* is missing, using ext4"; - defaultFS = QStringLiteral( "ext4" ); - } - if ( FileSystem::typeForName( defaultFS, fsLanguage ) != FileSystem::Unknown ) - { - cDebug() << "Partition-module setting *defaultFileSystemType*" << defaultFS; - return defaultFS; - } - - // Second pass: try case-insensitive - const auto fstypes = FileSystem::types(); - for ( FileSystem::Type t : fstypes ) - { - if ( 0 == QString::compare( defaultFS, FileSystem::nameForType( t, fsLanguage ), Qt::CaseInsensitive ) ) - { - defaultFS = FileSystem::nameForType( t, fsLanguage ); - cWarning() << "Partition-module setting *defaultFileSystemType* changed" << defaultFS; - return defaultFS; - } - } - - cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << defaultFS << ") using ext4."; - defaultFS = QStringLiteral( "ext4" ); -#ifdef DEBUG_FILESYSTEMS - // This bit is for distro's debugging their settings, and shows - // all the strings that KPMCore is matching against for FS type. - { - Logger::CDebug d; - using TR = Logger::DebugRow< int, QString >; - const auto fstypes = FileSystem::types(); - d << "Available types (" << fstypes.count() << ')'; - for ( FileSystem::Type t : fstypes ) - d << TR( static_cast( t ), FileSystem::nameForType( t, fsLanguage ) ); - } -#endif - return defaultFS; -} - void PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { @@ -630,7 +581,21 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) gs->insert( "alwaysShowPartitionLabels", CalamaresUtils::getBool( configurationMap, "alwaysShowPartitionLabels", true ) ); gs->insert( "enableLuksAutomatedPartitioning", CalamaresUtils::getBool( configurationMap, "enableLuksAutomatedPartitioning", true ) ); gs->insert( "allowManualPartitioning", CalamaresUtils::getBool( configurationMap, "allowManualPartitioning", true ) ); - gs->insert( "defaultFileSystemType", findFS( CalamaresUtils::getString( configurationMap, "defaultFileSystemType" ) ) ); + + // The defaultFileSystemType setting needs a bit more processing, + // as we want to cover various cases (such as different cases) + QString fsName = CalamaresUtils::getString( configurationMap, "defaultFileSystemType" ); + FileSystem::Type fsType; + if ( fsName.isEmpty() ) + cWarning() << "Partition-module setting *defaultFileSystemType* is missing, will use ext4"; + QString fsRealName = PartUtils::findFS( fsName, &fsType ); + if ( fsRealName == fsName ) + cDebug() << "Partition-module setting *defaultFileSystemType*" << fsRealName; + else if ( fsType != FileSystem::Unknown ) + cWarning() << "Partition-module setting *defaultFileSystemType* changed" << fsRealName; + else + cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << fsRealName << ") using ext4."; + gs->insert( "defaultFileSystemType", fsRealName ); // Now that we have the config, we load the PartitionCoreModule in the background diff --git a/src/modules/partition/gui/ResizeVolumeGroupDialog.cpp b/src/modules/partition/gui/ResizeVolumeGroupDialog.cpp index b3173096d..35b6bbdf1 100644 --- a/src/modules/partition/gui/ResizeVolumeGroupDialog.cpp +++ b/src/modules/partition/gui/ResizeVolumeGroupDialog.cpp @@ -35,7 +35,7 @@ ResizeVolumeGroupDialog::ResizeVolumeGroupDialog( LvmDevice *device, : VolumeGroupBaseDialog( device->name(), device->physicalVolumes(), parent ) , m_selectedPVs( selectedPVs ) { - setWindowTitle( "Resize Volume Group" ); + setWindowTitle( tr( "Resize Volume Group" ) ); for ( int i = 0; i < pvList()->count(); i++ ) pvList()->item(i)->setCheckState( Qt::Checked ); diff --git a/src/modules/partition/gui/VolumeGroupBaseDialog.ui b/src/modules/partition/gui/VolumeGroupBaseDialog.ui index b45d204e2..f84cf22d0 100644 --- a/src/modules/partition/gui/VolumeGroupBaseDialog.ui +++ b/src/modules/partition/gui/VolumeGroupBaseDialog.ui @@ -11,7 +11,7 @@ - VolumeGroupDialog + Create Volume Group diff --git a/src/modules/partition/jobs/CreateVolumeGroupJob.h b/src/modules/partition/jobs/CreateVolumeGroupJob.h index 9e84fba73..6f85eaab8 100644 --- a/src/modules/partition/jobs/CreateVolumeGroupJob.h +++ b/src/modules/partition/jobs/CreateVolumeGroupJob.h @@ -27,6 +27,7 @@ class CreateVolumeGroupJob : public Calamares::Job { + Q_OBJECT public: CreateVolumeGroupJob( QString& vgName, QVector< const Partition* > pvList, const qint32 peSize ); diff --git a/src/modules/partition/jobs/DeactivateVolumeGroupJob.h b/src/modules/partition/jobs/DeactivateVolumeGroupJob.h index 5b59c2c4f..17be7cdef 100644 --- a/src/modules/partition/jobs/DeactivateVolumeGroupJob.h +++ b/src/modules/partition/jobs/DeactivateVolumeGroupJob.h @@ -25,6 +25,7 @@ class LvmDevice; class DeactivateVolumeGroupJob : public Calamares::Job { + Q_OBJECT public: DeactivateVolumeGroupJob( LvmDevice* device ); diff --git a/src/modules/partition/jobs/RemoveVolumeGroupJob.h b/src/modules/partition/jobs/RemoveVolumeGroupJob.h index 426dde7fb..009e6f44d 100644 --- a/src/modules/partition/jobs/RemoveVolumeGroupJob.h +++ b/src/modules/partition/jobs/RemoveVolumeGroupJob.h @@ -25,6 +25,7 @@ class LvmDevice; class RemoveVolumeGroupJob : public Calamares::Job { + Q_OBJECT public: RemoveVolumeGroupJob( LvmDevice* device ); diff --git a/src/modules/partition/jobs/ResizeVolumeGroupJob.h b/src/modules/partition/jobs/ResizeVolumeGroupJob.h index 380bee416..fb0ff715b 100644 --- a/src/modules/partition/jobs/ResizeVolumeGroupJob.h +++ b/src/modules/partition/jobs/ResizeVolumeGroupJob.h @@ -28,6 +28,7 @@ class Partition; class ResizeVolumeGroupJob : public Calamares::Job { + Q_OBJECT public: ResizeVolumeGroupJob( LvmDevice* device, QVector< const Partition* >& partitionList ); diff --git a/src/modules/plymouthcfg/main.py b/src/modules/plymouthcfg/main.py index 6f1128b7e..e224f5df0 100644 --- a/src/modules/plymouthcfg/main.py +++ b/src/modules/plymouthcfg/main.py @@ -6,6 +6,7 @@ # Copyright 2016, Artoo # Copyright 2017, Alf Gaida # Copyright 2018, Gabriel Craciunescu +# Copyright 2019, Adriaan de Groot # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,6 +25,16 @@ import libcalamares from libcalamares.utils import debug, target_env_call +import gettext +_ = gettext.translation("calamares-python", + localedir=libcalamares.utils.gettext_path(), + languages=libcalamares.utils.gettext_languages(), + fallback=True).gettext + + +def pretty_name(): + return _("Configure Plymouth theme") + class PlymouthController: diff --git a/src/modules/removeuser/main.py b/src/modules/removeuser/main.py index 9acc20b54..bd876edcd 100644 --- a/src/modules/removeuser/main.py +++ b/src/modules/removeuser/main.py @@ -5,6 +5,7 @@ # # Copyright 2015, Teo Mrnjavac # Copyright 2017. Alf Gaida +# Copyright 2019, Adriaan de Groot # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,6 +23,16 @@ import subprocess import libcalamares +import gettext +_ = gettext.translation("calamares-python", + localedir=libcalamares.utils.gettext_path(), + languages=libcalamares.utils.gettext_languages(), + fallback=True).gettext + + +def pretty_name(): + return _("Remove live user from target system") + def run(): """ diff --git a/src/modules/services-openrc/main.py b/src/modules/services-openrc/main.py index c3e14b481..23591fb84 100644 --- a/src/modules/services-openrc/main.py +++ b/src/modules/services-openrc/main.py @@ -6,7 +6,7 @@ # Copyright 2016, Artoo # Copyright 2017, Philip Müller # Copyright 2018, Artoo -# Copyright 2018, Adriaan de Groot +# Copyright 2018-2019, Adriaan de Groot # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,6 +27,17 @@ from libcalamares.utils import target_env_call, warning from os.path import exists, join +import gettext +_ = gettext.translation("calamares-python", + localedir=libcalamares.utils.gettext_path(), + languages=libcalamares.utils.gettext_languages(), + fallback=True).gettext + + +def pretty_name(): + return _("Configure OpenRC services") + + class OpenrcController: """ This is the openrc service controller. @@ -45,6 +56,22 @@ class OpenrcController: self.initdDir = libcalamares.job.configuration['initdDir'] self.runlevelsDir = libcalamares.job.configuration['runlevelsDir'] + + def make_failure_description(self, state, name, runlevel): + """ + Returns a generic "could not " failure message, specialized + for the action @p state and the specific service @p name in @p runlevel. + """ + if state == "add": + description = _("Cannot add service {name!s} to run-level {level!s}.") + elif state == "del": + description = _("Cannot remove service {name!s} from run-level {level!s}.") + else: + description = _("Unknown service-action {arg!s} for service {name!s} in run-level {level!s}.") + + return description.format(arg=state, name=name, level=runlevel) + + def update(self, state): """ Call rc-update for each service listed @@ -69,24 +96,31 @@ class OpenrcController: if exists(runlevel_path): ec = target_env_call(["rc-update", state, name, runlevel]) if ec != 0: + warning("Cannot {} service {} to {}".format(state, name, runlevel)) + warning("rc-update returned error code {!s}".format(ec)) if mandatory: - return ("Cannot {} service {} to {}".format(state, name, runlevel), - "rc-update {} call in chroot returned error code {}".format(state, ec) + title = _("Cannot modify service") + diagnostic = _("rc-update {arg!s} call in chroot returned error code {num!s}.").format(arg=state, num=ec) + return (title, + self.make_failure_description(state, name, runlevel) + " " + diagnostic ) - else: - warning("Could not {} service {} in {}, error {!s}".format(state, name, runlevel, ec)) else: + warning("Target runlevel {} does not exist for {}.".format(runlevel, name)) if mandatory: - return ("Target runlevel {} does not exist for {}.".format(runlevel, name), - "No {} found.".format(runlevel_path)) - else: - warning("Target runlevel {} does not exist for {}.".format(runlevel, name)) + title = _("Target runlevel does not exist") + diagnostic = _("The path for runlevel {level!s} is {path!s}, which does not exist.").format(level=runlevel, path=runlevel_path) + + return (title, + self.make_failure_description(state, name, runlevel) + " " + diagnostic + ) else: + warning("Target service {} does not exist in {}.".format(name, self.initdDir)) if mandatory: - return ("Target service {} does not exist.".format(name), - "No {} found.".format(service_path)) - else: - warning("Target service {} does not exist in {}.".format(name, self.initdDir)) + title = _("Target service does not exist") + diagnostic = _("The path for service {name!s} is {path!s}, which does not exist.").format(name=name, path=service_path) + return (title, + self.make_failure_description(state, name, runlevel) + " " + diagnostic + ) def run(self): diff --git a/src/modules/services-systemd/main.py b/src/modules/services-systemd/main.py index 09263b9f0..cd13d9ce9 100644 --- a/src/modules/services-systemd/main.py +++ b/src/modules/services-systemd/main.py @@ -6,7 +6,7 @@ # Copyright 2014, Philip Müller # Copyright 2014, Teo Mrnjavac # Copyright 2017, Alf Gaida -# Copyright 2018, Adriaan de Groot +# Copyright 2018-2019, Adriaan de Groot # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,6 +24,17 @@ import libcalamares +import gettext +_ = gettext.translation("calamares-python", + localedir=libcalamares.utils.gettext_path(), + languages=libcalamares.utils.gettext_languages(), + fallback=True).gettext + + +def pretty_name(): + return _("Configure systemd services") + + def systemctl(targets, command, suffix): """ For each entry in @p targets, run "systemctl ", @@ -47,17 +58,32 @@ def systemctl(targets, command, suffix): ) if ec != 0: + libcalamares.utils.warning( + "Cannot {} systemd {} {}".format(command, suffix, name) + ) + libcalamares.utils.warning( + "systemctl {} call in chroot returned error code {}".format(command, ec) + ) if mandatory: - return ("Cannot {} systemd {} {}".format(command, suffix, name), - "systemctl {} call in chroot returned error code {}".format(command, ec) + title = _("Cannot modify service") + diagnostic = _("systemctl {arg!s} call in chroot returned error code {num!s}.").format(arg=command, num=ec) + + if command == "enable" and suffix == ".service": + description = _("Cannot enable systemd service {name!s}.") + elif command == "enable" and suffix == ".target": + description = _("Cannot enable systemd target {name!s}.") + elif command == "disable" and suffix == ".service": + description = _("Cannot enable systemd service {name!s}.") + elif command == "disable" and suffix == ".target": + description = _("Cannot disable systemd target {name!s}.") + elif command == "mask": + description = _("Cannot mask systemd unit {name!s}.") + else: + description = _("Unknown systemd commands {command!s} and {suffix!s} for unit {name!s}.") + + return (title, + description.format(name=name, command=command, suffix=suffix) + " " + diagnostic ) - else: - libcalamares.utils.warning( - "Cannot {} systemd {} {}".format(command, suffix, name) - ) - libcalamares.utils.warning( - "systemctl {} call in chroot returned error code {}".format(command, ec) - ) return None @@ -92,6 +118,4 @@ def run(): if r is not None: return r - - # This could have just been return r return None diff --git a/src/modules/users/CreateUserJob.cpp b/src/modules/users/CreateUserJob.cpp index 052af87c6..d7e356231 100644 --- a/src/modules/users/CreateUserJob.cpp +++ b/src/modules/users/CreateUserJob.cpp @@ -154,29 +154,29 @@ CreateUserJob::exec() useradd << "-c" << m_fullName; useradd << m_userName; - auto pres = CalamaresUtils::System::instance()->targetEnvCommand( useradd ); - if ( pres.getExitCode() ) + auto commandResult = CalamaresUtils::System::instance()->targetEnvCommand( useradd ); + if ( commandResult.getExitCode() ) { - cError() << "useradd failed" << pres.getExitCode(); - return pres.explainProcess( useradd, 10 /* bogus timeout */ ); + cError() << "useradd failed" << commandResult.getExitCode(); + return commandResult.explainProcess( useradd, 10 /* bogus timeout */ ); } - pres = CalamaresUtils::System::instance()->targetEnvCommand( + commandResult = CalamaresUtils::System::instance()->targetEnvCommand( { "usermod", "-aG", defaultGroups, m_userName } ); - if ( pres.getExitCode() ) + if ( commandResult.getExitCode() ) { - cError() << "usermod failed" << pres.getExitCode(); - return pres.explainProcess( "usermod", 10 ); + cError() << "usermod failed" << commandResult.getExitCode(); + return commandResult.explainProcess( "usermod", 10 ); } QString userGroup = QString( "%1:%2" ).arg( m_userName ).arg( m_userName ); QString homeDir = QString( "/home/%1" ).arg( m_userName ); - pres = CalamaresUtils::System::instance()->targetEnvCommand( + commandResult = CalamaresUtils::System::instance()->targetEnvCommand( { "chown", "-R", userGroup, homeDir } ); - if ( pres.getExitCode() ) + if ( commandResult.getExitCode() ) { - cError() << "chown failed" << pres.getExitCode(); - return pres.explainProcess( "chown", 10 ); + cError() << "chown failed" << commandResult.getExitCode(); + return commandResult.explainProcess( "chown", 10 ); } return Calamares::JobResult::ok();