Merge branch 'master' of https://github.com/calamares/calamares into development

This commit is contained in:
Philip 2017-09-06 18:13:08 +01:00
commit c61f662c86
11 changed files with 131 additions and 34 deletions

View File

@ -179,7 +179,7 @@ Branding::Branding( const QString& brandingFilePath,
} }
catch ( YAML::Exception& e ) catch ( YAML::Exception& e )
{ {
cDebug() << "WARNING: YAML parser error " << e.what(); cDebug() << "WARNING: YAML parser error " << e.what() << "in" << file.fileName();
} }
QDir translationsDir( componentDir.filePath( "lang" ) ); QDir translationsDir( componentDir.filePath( "lang" ) );

View File

@ -156,7 +156,7 @@ Settings::Settings( const QString& settingsFilePath,
} }
catch ( YAML::Exception& e ) catch ( YAML::Exception& e )
{ {
cDebug() << "WARNING: YAML parser error " << e.what(); cDebug() << "WARNING: YAML parser error " << e.what() << "in" << file.fileName();
} }
} }
else else

View File

@ -18,8 +18,11 @@
*/ */
#include "YamlUtils.h" #include "YamlUtils.h"
#include "utils/Logger.h"
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
#include <QByteArray>
#include <QRegExp> #include <QRegExp>
void void
@ -105,4 +108,42 @@ yamlMapToVariant( const YAML::Node& mapNode )
} }
void
explainYamlException( const YAML::Exception& e, const QByteArray& yamlData, const char *label )
{
cDebug() << "WARNING: YAML error " << e.what() << "in" << label << '.';
if ( ( e.mark.line >= 0 ) && ( e.mark.column >= 0 ) )
{
// Try to show the line where it happened.
int linestart = 0;
for ( int linecount = 0; linecount < e.mark.line; ++linecount )
{
linestart = yamlData.indexOf( '\n', linestart );
// No more \ns found, weird
if ( linestart < 0 )
break;
linestart += 1; // Skip that \n
}
int lineend = linestart;
if ( linestart >= 0 )
{
lineend = yamlData.indexOf( '\n', linestart );
if ( lineend < 0 )
lineend = yamlData.length();
}
int rangestart = linestart;
int rangeend = lineend;
// Adjust range (linestart..lineend) so it's not too long
if ( ( linestart >= 0 ) && ( e.mark.column > 30 ) )
rangestart += ( e.mark.column - 30 );
if ( ( linestart >= 0 ) && ( rangeend - rangestart > 40 ) )
rangeend = rangestart + 40;
if ( linestart >= 0 )
cDebug() << "WARNING: offending YAML data:" << yamlData.mid( rangestart, rangeend-rangestart ).constData();
}
} }
} // namespace

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014, Teo Mrnjavac <teo@kde.org> * Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -22,9 +23,12 @@
#include <QStringList> #include <QStringList>
#include <QVariant> #include <QVariant>
class QByteArray;
namespace YAML namespace YAML
{ {
class Node; class Node;
class Exception;
} }
void operator>>( const YAML::Node& node, QStringList& v ); void operator>>( const YAML::Node& node, QStringList& v );
@ -37,6 +41,13 @@ QVariant yamlScalarToVariant( const YAML::Node& scalarNode );
QVariant yamlSequenceToVariant( const YAML::Node& sequenceNode ); QVariant yamlSequenceToVariant( const YAML::Node& sequenceNode );
QVariant yamlMapToVariant( const YAML::Node& mapNode ); QVariant yamlMapToVariant( const YAML::Node& mapNode );
/**
* Given an exception from the YAML parser library, explain
* what is going on in terms of the data passed to the parser.
* Uses @p label when labeling the data source (e.g. "netinstall data")
*/
void explainYamlException( const YAML::Exception& e, const QByteArray& data, const char *label );
} //ns } //ns
#endif // YAMLUTILS_H #endif // YAMLUTILS_H

View File

@ -35,8 +35,6 @@ FinishedViewStep::FinishedViewStep( QObject* parent )
, m_widget( new FinishedPage() ) , m_widget( new FinishedPage() )
, installFailed( false ) , installFailed( false )
{ {
cDebug() << "FinishedViewStep()";
auto jq = Calamares::JobQueue::instance(); auto jq = Calamares::JobQueue::instance();
connect( jq, &Calamares::JobQueue::failed, connect( jq, &Calamares::JobQueue::failed,
m_widget, &FinishedPage::onInstallationFailed ); m_widget, &FinishedPage::onInstallationFailed );
@ -64,7 +62,6 @@ FinishedViewStep::prettyName() const
QWidget* QWidget*
FinishedViewStep::widget() FinishedViewStep::widget()
{ {
cDebug() << "FinishedViewStep::widget()";
return m_widget; return m_widget;
} }
@ -140,7 +137,6 @@ FinishedViewStep::sendNotification()
void void
FinishedViewStep::onActivate() FinishedViewStep::onActivate()
{ {
cDebug() << "FinishedViewStep::onActivate()";
m_widget->setUpRestart(); m_widget->setUpRestart();
sendNotification(); sendNotification();
@ -150,7 +146,6 @@ FinishedViewStep::onActivate()
QList< Calamares::job_ptr > QList< Calamares::job_ptr >
FinishedViewStep::jobs() const FinishedViewStep::jobs() const
{ {
cDebug() << "FinishedViewStep::jobs";
return QList< Calamares::job_ptr >(); return QList< Calamares::job_ptr >();
} }

View File

@ -116,28 +116,37 @@ LocaleViewStep::fetchGeoIpTimezone()
{ {
if ( reply->error() == QNetworkReply::NoError ) if ( reply->error() == QNetworkReply::NoError )
{ {
YAML::Node doc = YAML::Load( reply->readAll() ); QByteArray data = reply->readAll();
QVariant var = CalamaresUtils::yamlToVariant( doc ); try
if ( !var.isNull() &&
var.isValid() &&
var.type() == QVariant::Map )
{ {
QVariantMap map = var.toMap(); YAML::Node doc = YAML::Load( reply->readAll() );
if ( map.contains( "time_zone" ) &&
!map.value( "time_zone" ).toString().isEmpty() ) QVariant var = CalamaresUtils::yamlToVariant( doc );
if ( !var.isNull() &&
var.isValid() &&
var.type() == QVariant::Map )
{ {
QString timezoneString = map.value( "time_zone" ).toString(); QVariantMap map = var.toMap();
QStringList timezone = timezoneString.split( '/', QString::SkipEmptyParts ); if ( map.contains( "time_zone" ) &&
if ( timezone.size() >= 2 ) !map.value( "time_zone" ).toString().isEmpty() )
{ {
cDebug() << "GeoIP reporting" << timezoneString; QString timezoneString = map.value( "time_zone" ).toString();
QString region = timezone.takeFirst(); QStringList timezone = timezoneString.split( '/', QString::SkipEmptyParts );
QString zone = timezone.join( '/' ); if ( timezone.size() >= 2 )
m_startingTimezone = qMakePair( region, zone ); {
cDebug() << "GeoIP reporting" << timezoneString;
QString region = timezone.takeFirst();
QString zone = timezone.join( '/' );
m_startingTimezone = qMakePair( region, zone );
}
} }
} }
} }
catch ( YAML::Exception& e )
{
CalamaresUtils::explainYamlException( e, data, "GeoIP data");
}
} }
reply->deleteLater(); reply->deleteLater();

View File

@ -64,14 +64,28 @@ NetInstallPage::isReady()
return true; return true;
} }
void NetInstallPage::readGroups( const QByteArray& yamlData ) bool
NetInstallPage::readGroups( const QByteArray& yamlData )
{ {
YAML::Node groups = YAML::Load( yamlData.constData() ); try
Q_ASSERT( groups.IsSequence() ); {
m_groups = new PackageModel( groups ); YAML::Node groups = YAML::Load( yamlData.constData() );
CALAMARES_RETRANSLATE(
m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) ); if ( !groups.IsSequence() )
m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Description" ) ); ) cDebug() << "WARNING: netinstall groups data does not form a sequence.";
Q_ASSERT( groups.IsSequence() );
m_groups = new PackageModel( groups );
CALAMARES_RETRANSLATE(
m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) );
m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Description" ) ); )
return true;
}
catch ( YAML::Exception& e )
{
CalamaresUtils::explainYamlException( e, yamlData, "netinstall groups data" );
return false;
}
} }
void void
@ -84,7 +98,13 @@ NetInstallPage::dataIsHere( QNetworkReply* reply )
return; return;
} }
readGroups( reply->readAll() ); if ( !readGroups( reply->readAll() ) )
{
cDebug() << "Netinstall groups data was received, but invalid.";
ui->netinst_status->setText( tr( "Network Installation. (Disabled: Unable to fetch package lists, check your network connection)" ) );
reply->deleteLater();
return;
}
ui->groupswidget->setModel( m_groups ); ui->groupswidget->setModel( m_groups );
ui->groupswidget->header()->setSectionResizeMode( 0, QHeaderView::ResizeToContents ); ui->groupswidget->header()->setSectionResizeMode( 0, QHeaderView::ResizeToContents );

View File

@ -2,6 +2,7 @@
* Copyright 2016, Luca Giambonini <almack@chakraos.org> * Copyright 2016, Luca Giambonini <almack@chakraos.org>
* Copyright 2016, Lisa Vitolo <shainer@chakraos.org> * Copyright 2016, Lisa Vitolo <shainer@chakraos.org>
* Copyright 2017, Kyle Robbertze <krobbertze@gmail.com> * Copyright 2017, Kyle Robbertze <krobbertze@gmail.com>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -67,7 +68,7 @@ private:
// Takes the YAML data representing the groups and reads them into the // Takes the YAML data representing the groups and reads them into the
// m_groups and m_groupOrder internal structures. See the README.md // m_groups and m_groupOrder internal structures. See the README.md
// of this module to know the format expected of the YAML files. // of this module to know the format expected of the YAML files.
void readGroups( const QByteArray& yamlData ); bool readGroups( const QByteArray& yamlData );
Ui::Page_NetInst* ui; Ui::Page_NetInst* ui;

View File

@ -8,6 +8,10 @@ find_package( KF5 REQUIRED CoreAddons )
# These are needed because KPMcore links publicly against ConfigCore, I18n, IconThemes, KIOCore and Service # These are needed because KPMcore links publicly against ConfigCore, I18n, IconThemes, KIOCore and Service
find_package( KF5 REQUIRED Config I18n IconThemes KIO Service ) find_package( KF5 REQUIRED Config I18n IconThemes KIO Service )
find_package( KPMcore 3.1.50 )
if ( ${KPMcore_FOUND} )
add_definitions(-DWITH_KPMCORE22)
endif()
find_package( KPMcore 3.0.3 REQUIRED ) find_package( KPMcore 3.0.3 REQUIRED )
find_library( atasmart_LIB atasmart ) find_library( atasmart_LIB atasmart )
find_library( blkid_LIB blkid ) find_library( blkid_LIB blkid )

View File

@ -23,6 +23,7 @@
#include "core/PartitionIterator.h" #include "core/PartitionIterator.h"
// KPMcore // KPMcore
#include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h> #include <kpmcore/core/partition.h>
#include <kpmcore/fs/filesystemfactory.h> #include <kpmcore/fs/filesystemfactory.h>
#include <kpmcore/backend/corebackendmanager.h> #include <kpmcore/backend/corebackendmanager.h>
@ -114,7 +115,11 @@ createNewPartition( PartitionNode* parent,
qint64 lastSector, qint64 lastSector,
PartitionTable::Flags flags ) PartitionTable::Flags flags )
{ {
FileSystem* fs = FileSystemFactory::create( fsType, firstSector, lastSector ); FileSystem* fs = FileSystemFactory::create( fsType, firstSector, lastSector
#ifdef WITH_KPMCORE22
,device.logicalSize()
#endif
);
return new Partition( return new Partition(
parent, parent,
device, device,
@ -147,7 +152,11 @@ createNewEncryptedPartition( PartitionNode* parent,
FS::luks* fs = dynamic_cast< FS::luks* >( FS::luks* fs = dynamic_cast< FS::luks* >(
FileSystemFactory::create( FileSystem::Luks, FileSystemFactory::create( FileSystem::Luks,
firstSector, firstSector,
lastSector ) ); lastSector
#ifdef WITH_KPMCORE22
,device.logicalSize()
#endif
) );
if ( !fs ) if ( !fs )
{ {
qDebug() << "ERROR: cannot create LUKS filesystem. Giving up."; qDebug() << "ERROR: cannot create LUKS filesystem. Giving up.";
@ -177,6 +186,9 @@ clonePartition( Device* device, Partition* partition )
partition->fileSystem().type(), partition->fileSystem().type(),
partition->firstSector(), partition->firstSector(),
partition->lastSector() partition->lastSector()
#ifdef WITH_KPMCORE22
,device->logicalSize()
#endif
); );
return new Partition( partition->parent(), return new Partition( partition->parent(),
*device, *device,

View File

@ -217,7 +217,11 @@ PartitionJobTests::newCreatePartitionJob( Partition* freeSpacePartition, Partiti
lastSector = firstSector + size / m_device->logicalSize(); lastSector = firstSector + size / m_device->logicalSize();
else else
lastSector = freeSpacePartition->lastSector(); lastSector = freeSpacePartition->lastSector();
FileSystem* fs = FileSystemFactory::create( type, firstSector, lastSector ); FileSystem* fs = FileSystemFactory::create( type, firstSector, lastSector
#ifdef WITH_KPMCORE22
,m_device->logicalSize()
#endif
);
Partition* partition = new Partition( Partition* partition = new Partition(
freeSpacePartition->parent(), freeSpacePartition->parent(),