Add check for enough RAM to prepare viewmodule.
This commit is contained in:
parent
03800e2966
commit
b32bbf2b9a
@ -18,6 +18,7 @@ prepare:
|
|||||||
- greeting
|
- greeting
|
||||||
- locale
|
- locale
|
||||||
- keyboard
|
- keyboard
|
||||||
|
- prepare
|
||||||
- partition
|
- partition
|
||||||
- users
|
- users
|
||||||
- summary
|
- summary
|
||||||
|
@ -27,13 +27,14 @@
|
|||||||
|
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
PrepareViewStep::PrepareViewStep( QObject* parent )
|
PrepareViewStep::PrepareViewStep( QObject* parent )
|
||||||
: Calamares::ViewStep( parent )
|
: Calamares::ViewStep( parent )
|
||||||
, m_widget( new QWidget() )
|
, m_widget( new QWidget() )
|
||||||
, m_actualWidget( new PreparePage() )
|
, m_actualWidget( new PreparePage() )
|
||||||
, m_nextEnabled( false )
|
, m_nextEnabled( false )
|
||||||
, m_requiredSpaceGB( -1 )
|
, m_requiredStorageGB( -1 )
|
||||||
{
|
{
|
||||||
QBoxLayout* mainLayout = new QHBoxLayout;
|
QBoxLayout* mainLayout = new QHBoxLayout;
|
||||||
m_widget->setLayout( mainLayout );
|
m_widget->setLayout( mainLayout );
|
||||||
@ -77,14 +78,20 @@ PrepareViewStep::PrepareViewStep( QObject* parent )
|
|||||||
connect( timer, &QTimer::timeout,
|
connect( timer, &QTimer::timeout,
|
||||||
[=]()
|
[=]()
|
||||||
{
|
{
|
||||||
bool bigEnough, hasPower, hasInternet;
|
bool enoughStorage, enoughRam, hasPower, hasInternet;
|
||||||
qint64 requiredSpaceB = m_requiredSpaceGB * 1073741824L; /*powers of 2*/
|
|
||||||
cDebug() << "Need at least bytes:" << requiredSpaceB;
|
qint64 requiredStorageB = m_requiredStorageGB * 1073741824L; /*powers of 2*/
|
||||||
bigEnough = checkBigEnough( requiredSpaceB );
|
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();
|
hasPower = checkHasPower();
|
||||||
hasInternet = checkHasInternet();
|
hasInternet = checkHasInternet();
|
||||||
cDebug() << "bigEnough, hasPower, hasInternet: "
|
cDebug() << "enoughStorage, enoughRam, hasPower, hasInternet: "
|
||||||
<< bigEnough << hasPower << hasInternet;
|
<< enoughStorage << enoughRam << hasPower << hasInternet;
|
||||||
|
|
||||||
m_actualWidget->init();
|
m_actualWidget->init();
|
||||||
m_widget->layout()->removeWidget( waitingWidget );
|
m_widget->layout()->removeWidget( waitingWidget );
|
||||||
@ -170,28 +177,57 @@ PrepareViewStep::onLeave()
|
|||||||
void
|
void
|
||||||
PrepareViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
PrepareViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
{
|
{
|
||||||
if ( configurationMap.contains( "requiredSpace" ) &&
|
if ( configurationMap.contains( "requiredStorage" ) &&
|
||||||
configurationMap.value( "requiredSpace" ).type() == QVariant::Double )
|
configurationMap.value( "requiredStorage" ).type() == QVariant::Double )
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
m_requiredSpaceGB = configurationMap.value( "requiredSpace" ).toDouble( &ok );
|
m_requiredStorageGB = configurationMap.value( "requiredStorage" ).toDouble( &ok );
|
||||||
if ( !ok )
|
if ( !ok )
|
||||||
m_requiredSpaceGB = 3.;
|
m_requiredStorageGB = 3.;
|
||||||
}
|
}
|
||||||
else
|
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
|
bool
|
||||||
PrepareViewStep::checkBigEnough( qint64 requiredSpace )
|
PrepareViewStep::checkEnoughStorage( qint64 requiredSpace )
|
||||||
{
|
{
|
||||||
return check_big_enough( 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
|
bool
|
||||||
PrepareViewStep::checkHasPower()
|
PrepareViewStep::checkHasPower()
|
||||||
{
|
{
|
||||||
|
@ -56,12 +56,14 @@ public:
|
|||||||
void setConfigurationMap( const QVariantMap& configurationMap ) override;
|
void setConfigurationMap( const QVariantMap& configurationMap ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool checkBigEnough( qint64 requiredSpace );
|
bool checkEnoughStorage( qint64 requiredSpace );
|
||||||
|
bool checkEnoughRam( qint64 requiredRam );
|
||||||
bool checkHasPower();
|
bool checkHasPower();
|
||||||
bool checkHasInternet();
|
bool checkHasInternet();
|
||||||
|
|
||||||
QWidget* m_widget;
|
QWidget* m_widget;
|
||||||
qreal m_requiredSpaceGB;
|
qreal m_requiredStorageGB;
|
||||||
|
qreal m_requiredRamGB;
|
||||||
|
|
||||||
PreparePage* m_actualWidget;
|
PreparePage* m_actualWidget;
|
||||||
bool m_nextEnabled;
|
bool m_nextEnabled;
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
---
|
---
|
||||||
requiredSpace: 5.5
|
requiredStorage: 5.5
|
||||||
|
requiredRam: 2.0
|
||||||
|
Loading…
Reference in New Issue
Block a user