From b32bbf2b9a74dcd0561356efa78f2fe57bfb0bfd Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 22 Aug 2014 15:16:45 +0200 Subject: [PATCH] Add check for enough RAM to prepare viewmodule. --- settings.conf | 1 + src/modules/prepare/PrepareViewStep.cpp | 62 +++++++++++++++++++------ src/modules/prepare/PrepareViewStep.h | 6 ++- src/modules/prepare/prepare.conf | 3 +- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/settings.conf b/settings.conf index 5f306b3f3..fc857f702 100644 --- a/settings.conf +++ b/settings.conf @@ -18,6 +18,7 @@ prepare: - greeting - locale - keyboard +- prepare - partition - users - summary diff --git a/src/modules/prepare/PrepareViewStep.cpp b/src/modules/prepare/PrepareViewStep.cpp index 4a1774a6e..fe4941f63 100644 --- a/src/modules/prepare/PrepareViewStep.cpp +++ b/src/modules/prepare/PrepareViewStep.cpp @@ -27,13 +27,14 @@ #include #include +#include PrepareViewStep::PrepareViewStep( QObject* parent ) : Calamares::ViewStep( parent ) , m_widget( new QWidget() ) , m_actualWidget( new PreparePage() ) , m_nextEnabled( false ) - , m_requiredSpaceGB( -1 ) + , m_requiredStorageGB( -1 ) { QBoxLayout* mainLayout = new QHBoxLayout; m_widget->setLayout( mainLayout ); @@ -77,14 +78,20 @@ PrepareViewStep::PrepareViewStep( QObject* parent ) connect( timer, &QTimer::timeout, [=]() { - bool bigEnough, hasPower, hasInternet; - qint64 requiredSpaceB = m_requiredSpaceGB * 1073741824L; /*powers of 2*/ - cDebug() << "Need at least bytes:" << requiredSpaceB; - bigEnough = checkBigEnough( requiredSpaceB ); + bool enoughStorage, enoughRam, hasPower, hasInternet; + + qint64 requiredStorageB = m_requiredStorageGB * 1073741824L; /*powers of 2*/ + cDebug() << "Need at least storage bytes:" << requiredStorageB; + enoughStorage = checkEnoughStorage( requiredStorageB ); + + qint64 requiredRamB = m_requiredRamGB * 1073741824L; /*powers of 2*/ + cDebug() << "Need at least ram bytes:" << requiredRamB; + enoughRam = checkEnoughRam( requiredRamB ); + hasPower = checkHasPower(); hasInternet = checkHasInternet(); - cDebug() << "bigEnough, hasPower, hasInternet: " - << bigEnough << hasPower << hasInternet; + cDebug() << "enoughStorage, enoughRam, hasPower, hasInternet: " + << enoughStorage << enoughRam << hasPower << hasInternet; m_actualWidget->init(); m_widget->layout()->removeWidget( waitingWidget ); @@ -170,28 +177,57 @@ PrepareViewStep::onLeave() void PrepareViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { - if ( configurationMap.contains( "requiredSpace" ) && - configurationMap.value( "requiredSpace" ).type() == QVariant::Double ) + if ( configurationMap.contains( "requiredStorage" ) && + configurationMap.value( "requiredStorage" ).type() == QVariant::Double ) { bool ok = false; - m_requiredSpaceGB = configurationMap.value( "requiredSpace" ).toDouble( &ok ); + m_requiredStorageGB = configurationMap.value( "requiredStorage" ).toDouble( &ok ); if ( !ok ) - m_requiredSpaceGB = 3.; + m_requiredStorageGB = 3.; } else { - m_requiredSpaceGB = 3.; + m_requiredStorageGB = 3.; + } + + if ( configurationMap.contains( "requiredRam" ) && + configurationMap.value( "requiredRam" ).type() == QVariant::Double ) + { + bool ok = false; + m_requiredRamGB = configurationMap.value( "requiredRam" ).toDouble( &ok ); + if ( !ok ) + m_requiredRamGB = 1.; + } + else + { + m_requiredRamGB = 1.; } } bool -PrepareViewStep::checkBigEnough( qint64 requiredSpace ) +PrepareViewStep::checkEnoughStorage( qint64 requiredSpace ) { return check_big_enough( requiredSpace ); } +bool +PrepareViewStep::checkEnoughRam( qint64 requiredRam ) +{ + // A line in meminfo looks like this, with {print $2} we grab the second column. + // MemTotal: 8133432 kB + + QProcess p; + p.start( "awk", { "/MemTotal/ {print $2}", "/proc/meminfo" } ); + p.waitForFinished(); + QString memoryLine = p.readAllStandardOutput().simplified(); + qint64 availableRam = memoryLine.toLongLong() * 1024; + + return availableRam >= requiredRam; +} + + bool PrepareViewStep::checkHasPower() { diff --git a/src/modules/prepare/PrepareViewStep.h b/src/modules/prepare/PrepareViewStep.h index 7d30f0ec4..a29fc82de 100644 --- a/src/modules/prepare/PrepareViewStep.h +++ b/src/modules/prepare/PrepareViewStep.h @@ -56,12 +56,14 @@ public: void setConfigurationMap( const QVariantMap& configurationMap ) override; private: - bool checkBigEnough( qint64 requiredSpace ); + bool checkEnoughStorage( qint64 requiredSpace ); + bool checkEnoughRam( qint64 requiredRam ); bool checkHasPower(); bool checkHasInternet(); QWidget* m_widget; - qreal m_requiredSpaceGB; + qreal m_requiredStorageGB; + qreal m_requiredRamGB; PreparePage* m_actualWidget; bool m_nextEnabled; diff --git a/src/modules/prepare/prepare.conf b/src/modules/prepare/prepare.conf index 8f959a95c..39baed9e7 100644 --- a/src/modules/prepare/prepare.conf +++ b/src/modules/prepare/prepare.conf @@ -1,2 +1,3 @@ --- -requiredSpace: 5.5 +requiredStorage: 5.5 +requiredRam: 2.0