[libcalamares] Apply current coding style to all of libcalamares/
This commit is contained in:
parent
fa676c573e
commit
1afa9c4d08
@ -24,11 +24,11 @@ namespace Calamares
|
|||||||
|
|
||||||
CppJob::CppJob( QObject* parent )
|
CppJob::CppJob( QObject* parent )
|
||||||
: Job( parent )
|
: Job( parent )
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CppJob::~CppJob()
|
CppJob::~CppJob() {}
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -44,4 +44,4 @@ CppJob::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
Q_UNUSED( configurationMap )
|
Q_UNUSED( configurationMap )
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace Calamares
|
||||||
|
@ -45,6 +45,6 @@ protected:
|
|||||||
QString m_instanceKey;
|
QString m_instanceKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace Calamares
|
||||||
|
|
||||||
#endif // CALAMARES_CPPJOB_H
|
#endif // CALAMARES_CPPJOB_H
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Yaml.h"
|
|
||||||
#include "utils/Units.h"
|
#include "utils/Units.h"
|
||||||
|
#include "utils/Yaml.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
@ -40,7 +40,8 @@ namespace bp = boost::python;
|
|||||||
|
|
||||||
using CalamaresUtils::operator""_MiB;
|
using CalamaresUtils::operator""_MiB;
|
||||||
|
|
||||||
namespace Calamares {
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
GlobalStorage::GlobalStorage()
|
GlobalStorage::GlobalStorage()
|
||||||
: QObject( nullptr )
|
: QObject( nullptr )
|
||||||
@ -106,7 +107,9 @@ GlobalStorage::save(const QString& filename)
|
|||||||
{
|
{
|
||||||
QFile f( filename );
|
QFile f( filename );
|
||||||
if ( !f.open( QFile::WriteOnly ) )
|
if ( !f.open( QFile::WriteOnly ) )
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
f.write( QJsonDocument::fromVariant( m ).toJson() );
|
f.write( QJsonDocument::fromVariant( m ).toJson() );
|
||||||
f.close();
|
f.close();
|
||||||
@ -118,14 +121,20 @@ GlobalStorage::load( const QString& filename )
|
|||||||
{
|
{
|
||||||
QFile f( filename );
|
QFile f( filename );
|
||||||
if ( !f.open( QFile::ReadOnly ) )
|
if ( !f.open( QFile::ReadOnly ) )
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonParseError e;
|
QJsonParseError e;
|
||||||
QJsonDocument d = QJsonDocument::fromJson( f.read( 1_MiB ), &e );
|
QJsonDocument d = QJsonDocument::fromJson( f.read( 1_MiB ), &e );
|
||||||
if ( d.isNull() )
|
if ( d.isNull() )
|
||||||
|
{
|
||||||
cWarning() << filename << e.errorString();
|
cWarning() << filename << e.errorString();
|
||||||
|
}
|
||||||
else if ( !d.isObject() )
|
else if ( !d.isObject() )
|
||||||
|
{
|
||||||
cWarning() << filename << "Not suitable JSON.";
|
cWarning() << filename << "Not suitable JSON.";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto map = d.toVariant().toMap();
|
auto map = d.toVariant().toMap();
|
||||||
@ -150,7 +159,9 @@ GlobalStorage::loadYaml( const QString& filename )
|
|||||||
bool ok = false;
|
bool ok = false;
|
||||||
auto gs = CalamaresUtils::loadYaml( filename, &ok );
|
auto gs = CalamaresUtils::loadYaml( filename, &ok );
|
||||||
if ( ok )
|
if ( ok )
|
||||||
|
{
|
||||||
m = gs;
|
m = gs;
|
||||||
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,11 +205,9 @@ GlobalStoragePythonWrapper::count() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalStoragePythonWrapper::insert( const std::string& key,
|
GlobalStoragePythonWrapper::insert( const std::string& key, const bp::object& value )
|
||||||
const bp::object& value )
|
|
||||||
{
|
{
|
||||||
m_gs->insert( QString::fromStdString( key ),
|
m_gs->insert( QString::fromStdString( key ), CalamaresPython::variantFromPyObject( value ) );
|
||||||
CalamaresPython::variantFromPyObject( value ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bp::list
|
bp::list
|
||||||
@ -207,7 +216,9 @@ GlobalStoragePythonWrapper::keys() const
|
|||||||
bp::list pyList;
|
bp::list pyList;
|
||||||
const auto keys = m_gs->keys();
|
const auto keys = m_gs->keys();
|
||||||
for ( const QString& key : keys )
|
for ( const QString& key : keys )
|
||||||
|
{
|
||||||
pyList.append( key.toStdString() );
|
pyList.append( key.toStdString() );
|
||||||
|
}
|
||||||
return pyList;
|
return pyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ namespace api
|
|||||||
class object;
|
class object;
|
||||||
}
|
}
|
||||||
class list;
|
class list;
|
||||||
}
|
} // namespace python
|
||||||
}
|
} // namespace boost
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Calamares
|
namespace Calamares
|
||||||
|
@ -84,7 +84,8 @@ JobResult::JobResult( const QString& message, const QString& details, int number
|
|||||||
: m_message( message )
|
: m_message( message )
|
||||||
, m_details( details )
|
, m_details( details )
|
||||||
, m_number( number )
|
, m_number( number )
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Job::Job( QObject* parent )
|
Job::Job( QObject* parent )
|
||||||
@ -93,8 +94,7 @@ Job::Job( QObject* parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Job::~Job()
|
Job::~Job() {}
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
qreal
|
qreal
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
namespace Calamares {
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
class DLLEXPORT JobResult
|
class DLLEXPORT JobResult
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,8 @@ GoodJob::exec()
|
|||||||
JobResult
|
JobResult
|
||||||
FailJob::exec()
|
FailJob::exec()
|
||||||
{
|
{
|
||||||
return JobResult::error( tr( "Job failed (%1)" ).arg( m_name ), tr( "Programmed job failure was explicitly requested." ) );
|
return JobResult::error( tr( "Job failed (%1)" ).arg( m_name ),
|
||||||
|
tr( "Programmed job failure was explicitly requested." ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace Calamares
|
||||||
|
@ -21,7 +21,8 @@
|
|||||||
|
|
||||||
#include "Job.h"
|
#include "Job.h"
|
||||||
|
|
||||||
namespace Calamares {
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
/** @brief A Job with a name
|
/** @brief A Job with a name
|
||||||
*
|
*
|
||||||
@ -39,6 +40,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual QString prettyName() const override;
|
virtual QString prettyName() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const QString m_name;
|
const QString m_name;
|
||||||
};
|
};
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
|
||||||
#include "Job.h"
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
|
#include "Job.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "CalamaresConfig.h"
|
#include "CalamaresConfig.h"
|
||||||
@ -87,12 +87,18 @@ public:
|
|||||||
details = result.details();
|
details = result.details();
|
||||||
}
|
}
|
||||||
if ( !anyFailed )
|
if ( !anyFailed )
|
||||||
|
{
|
||||||
++m_jobIndex;
|
++m_jobIndex;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ( anyFailed )
|
if ( anyFailed )
|
||||||
|
{
|
||||||
emitFailed( message, details );
|
emitFailed( message, details );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
emitProgress();
|
emitProgress();
|
||||||
|
}
|
||||||
emitFinished();
|
emitFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,49 +115,39 @@ private:
|
|||||||
jobPercent = qBound( qreal( 0 ), jobPercent, qreal( 1 ) );
|
jobPercent = qBound( qreal( 0 ), jobPercent, qreal( 1 ) );
|
||||||
|
|
||||||
int jobCount = m_jobs.size();
|
int jobCount = m_jobs.size();
|
||||||
QString message = m_jobIndex < jobCount
|
QString message = m_jobIndex < jobCount ? m_jobs.at( m_jobIndex )->prettyStatusMessage() : tr( "Done" );
|
||||||
? m_jobs.at( m_jobIndex )->prettyStatusMessage()
|
|
||||||
: tr( "Done" );
|
|
||||||
|
|
||||||
qreal cumulativeProgress = 0.0;
|
qreal cumulativeProgress = 0.0;
|
||||||
for ( auto jobWeight : m_jobWeights.mid( 0, m_jobIndex ) )
|
for ( auto jobWeight : m_jobWeights.mid( 0, m_jobIndex ) )
|
||||||
{
|
{
|
||||||
cumulativeProgress += jobWeight;
|
cumulativeProgress += jobWeight;
|
||||||
}
|
}
|
||||||
qreal percent = m_jobIndex < jobCount
|
qreal percent
|
||||||
? cumulativeProgress + ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent )
|
= m_jobIndex < jobCount ? cumulativeProgress + ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent ) : 1.0;
|
||||||
: 1.0;
|
|
||||||
|
|
||||||
if ( m_jobIndex < jobCount )
|
if ( m_jobIndex < jobCount )
|
||||||
{
|
{
|
||||||
cDebug(Logger::LOGVERBOSE) << "[JOBQUEUE]: Progress for Job[" << m_jobIndex << "]: " << ( jobPercent * 100 ) << "% completed";
|
cDebug( Logger::LOGVERBOSE ) << "[JOBQUEUE]: Progress for Job[" << m_jobIndex
|
||||||
cDebug(Logger::LOGVERBOSE) << "[JOBQUEUE]: Progress Overall: " << ( cumulativeProgress * 100 ) << "% (accumulated) + "
|
<< "]: " << ( jobPercent * 100 ) << "% completed";
|
||||||
<< ( ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent ) * 100 ) << "% (this job) = "
|
cDebug( Logger::LOGVERBOSE ) << "[JOBQUEUE]: Progress Overall: " << ( cumulativeProgress * 100 )
|
||||||
<< ( percent * 100 ) << "% (total)";
|
<< "% (accumulated) + "
|
||||||
|
<< ( ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent ) * 100 )
|
||||||
|
<< "% (this job) = " << ( percent * 100 ) << "% (total)";
|
||||||
}
|
}
|
||||||
QMetaObject::invokeMethod( m_queue, "progress", Qt::QueuedConnection,
|
QMetaObject::invokeMethod(
|
||||||
Q_ARG( qreal, percent ),
|
m_queue, "progress", Qt::QueuedConnection, Q_ARG( qreal, percent ), Q_ARG( QString, message ) );
|
||||||
Q_ARG( QString, message )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void emitFailed( const QString& message, const QString& details )
|
void emitFailed( const QString& message, const QString& details )
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod( m_queue, "failed", Qt::QueuedConnection,
|
QMetaObject::invokeMethod(
|
||||||
Q_ARG( QString, message ),
|
m_queue, "failed", Qt::QueuedConnection, Q_ARG( QString, message ), Q_ARG( QString, details ) );
|
||||||
Q_ARG( QString, details )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void emitFinished()
|
void emitFinished() { QMetaObject::invokeMethod( m_queue, "finished", Qt::QueuedConnection ); }
|
||||||
{
|
|
||||||
QMetaObject::invokeMethod( m_queue, "finished", Qt::QueuedConnection );
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
JobThread::~JobThread()
|
JobThread::~JobThread() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
JobQueue* JobQueue::s_instance = nullptr;
|
JobQueue* JobQueue::s_instance = nullptr;
|
||||||
@ -187,7 +183,9 @@ JobQueue::~JobQueue()
|
|||||||
{
|
{
|
||||||
m_thread->terminate();
|
m_thread->terminate();
|
||||||
if ( !m_thread->wait( 300 ) )
|
if ( !m_thread->wait( 300 ) )
|
||||||
|
{
|
||||||
cError() << "Could not terminate job thread (expect a crash now).";
|
cError() << "Could not terminate job thread (expect a crash now).";
|
||||||
|
}
|
||||||
delete m_thread;
|
delete m_thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,6 @@ private:
|
|||||||
GlobalStorage* m_storage;
|
GlobalStorage* m_storage;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace Calamares
|
||||||
|
|
||||||
#endif // CALAMARES_JOBQUEUE_H
|
#endif // CALAMARES_JOBQUEUE_H
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
namespace Calamares {
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
ProcessJob::ProcessJob( const QString& command,
|
ProcessJob::ProcessJob( const QString& command,
|
||||||
@ -38,27 +39,24 @@ ProcessJob::ProcessJob( const QString& command,
|
|||||||
, m_workingPath( workingPath )
|
, m_workingPath( workingPath )
|
||||||
, m_runInChroot( runInChroot )
|
, m_runInChroot( runInChroot )
|
||||||
, m_timeoutSec( secondsTimeout )
|
, m_timeoutSec( secondsTimeout )
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ProcessJob::~ProcessJob()
|
ProcessJob::~ProcessJob() {}
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
ProcessJob::prettyName() const
|
ProcessJob::prettyName() const
|
||||||
{
|
{
|
||||||
return ( m_runInChroot ? tr( "Run command '%1' in target system." ) : tr( " Run command '%1'." ) )
|
return ( m_runInChroot ? tr( "Run command '%1' in target system." ) : tr( " Run command '%1'." ) ).arg( m_command );
|
||||||
.arg( m_command );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
ProcessJob::prettyStatusMessage() const
|
ProcessJob::prettyStatusMessage() const
|
||||||
{
|
{
|
||||||
return tr( "Running command %1 %2" )
|
return tr( "Running command %1 %2" ).arg( m_command ).arg( m_runInChroot ? "in chroot." : " ." );
|
||||||
.arg( m_command )
|
|
||||||
.arg( m_runInChroot ? "in chroot." : " ." );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -68,15 +66,11 @@ ProcessJob::exec()
|
|||||||
using CalamaresUtils::System;
|
using CalamaresUtils::System;
|
||||||
|
|
||||||
if ( m_runInChroot )
|
if ( m_runInChroot )
|
||||||
return CalamaresUtils::System::instance()->
|
return CalamaresUtils::System::instance()
|
||||||
targetEnvCommand( { m_command },
|
->targetEnvCommand( { m_command }, m_workingPath, QString(), m_timeoutSec )
|
||||||
m_workingPath,
|
|
||||||
QString(),
|
|
||||||
m_timeoutSec )
|
|
||||||
.explainProcess( m_command, m_timeoutSec );
|
.explainProcess( m_command, m_timeoutSec );
|
||||||
else
|
else
|
||||||
return
|
return System::runCommand( System::RunLocation::RunInHost,
|
||||||
System::runCommand( System::RunLocation::RunInHost,
|
|
||||||
{ "/bin/sh", "-c", m_command },
|
{ "/bin/sh", "-c", m_command },
|
||||||
m_workingPath,
|
m_workingPath,
|
||||||
QString(),
|
QString(),
|
||||||
|
@ -24,7 +24,8 @@
|
|||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
namespace Calamares {
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
class ProcessJob : public Job
|
class ProcessJob : public Job
|
||||||
{
|
{
|
||||||
|
@ -72,26 +72,40 @@ variantFromPyObject( const boost::python::object& pyObject )
|
|||||||
{
|
{
|
||||||
std::string pyType = bp::extract< std::string >( pyObject.attr( "__class__" ).attr( "__name__" ) );
|
std::string pyType = bp::extract< std::string >( pyObject.attr( "__class__" ).attr( "__name__" ) );
|
||||||
if ( pyType == "dict" )
|
if ( pyType == "dict" )
|
||||||
|
{
|
||||||
return variantMapFromPyDict( bp::extract< bp::dict >( pyObject ) );
|
return variantMapFromPyDict( bp::extract< bp::dict >( pyObject ) );
|
||||||
|
}
|
||||||
|
|
||||||
else if ( pyType == "list" )
|
else if ( pyType == "list" )
|
||||||
|
{
|
||||||
return variantListFromPyList( bp::extract< bp::list >( pyObject ) );
|
return variantListFromPyList( bp::extract< bp::list >( pyObject ) );
|
||||||
|
}
|
||||||
|
|
||||||
else if ( pyType == "int" )
|
else if ( pyType == "int" )
|
||||||
|
{
|
||||||
return QVariant( bp::extract< int >( pyObject ) );
|
return QVariant( bp::extract< int >( pyObject ) );
|
||||||
|
}
|
||||||
|
|
||||||
else if ( pyType == "float" )
|
else if ( pyType == "float" )
|
||||||
|
{
|
||||||
return QVariant( bp::extract< double >( pyObject ) );
|
return QVariant( bp::extract< double >( pyObject ) );
|
||||||
|
}
|
||||||
|
|
||||||
else if ( pyType == "str" )
|
else if ( pyType == "str" )
|
||||||
|
{
|
||||||
return QVariant( QString::fromStdString( bp::extract< std::string >( pyObject ) ) );
|
return QVariant( QString::fromStdString( bp::extract< std::string >( pyObject ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
else if ( pyType == "bool" )
|
else if ( pyType == "bool" )
|
||||||
|
{
|
||||||
return QVariant( bp::extract< bool >( pyObject ) );
|
return QVariant( bp::extract< bool >( pyObject ) );
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
boost::python::list
|
boost::python::list
|
||||||
@ -99,7 +113,9 @@ variantListToPyList( const QVariantList& variantList )
|
|||||||
{
|
{
|
||||||
bp::list pyList;
|
bp::list pyList;
|
||||||
for ( const QVariant& variant : variantList )
|
for ( const QVariant& variant : variantList )
|
||||||
|
{
|
||||||
pyList.append( variantToPyObject( variant ) );
|
pyList.append( variantToPyObject( variant ) );
|
||||||
|
}
|
||||||
return pyList;
|
return pyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +125,9 @@ variantListFromPyList( const boost::python::list& pyList )
|
|||||||
{
|
{
|
||||||
QVariantList list;
|
QVariantList list;
|
||||||
for ( int i = 0; i < bp::len( pyList ); ++i )
|
for ( int i = 0; i < bp::len( pyList ); ++i )
|
||||||
|
{
|
||||||
list.append( variantFromPyObject( pyList[ i ] ) );
|
list.append( variantFromPyObject( pyList[ i ] ) );
|
||||||
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +137,9 @@ variantMapToPyDict( const QVariantMap& variantMap )
|
|||||||
{
|
{
|
||||||
bp::dict pyDict;
|
bp::dict pyDict;
|
||||||
for ( auto it = variantMap.constBegin(); it != variantMap.constEnd(); ++it )
|
for ( auto it = variantMap.constBegin(); it != variantMap.constEnd(); ++it )
|
||||||
|
{
|
||||||
pyDict[ it.key().toStdString() ] = variantToPyObject( it.value() );
|
pyDict[ it.key().toStdString() ] = variantToPyObject( it.value() );
|
||||||
|
}
|
||||||
return pyDict;
|
return pyDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +172,9 @@ variantHashToPyDict( const QVariantHash& variantHash )
|
|||||||
{
|
{
|
||||||
bp::dict pyDict;
|
bp::dict pyDict;
|
||||||
for ( auto it = variantHash.constBegin(); it != variantHash.constEnd(); ++it )
|
for ( auto it = variantHash.constBegin(); it != variantHash.constEnd(); ++it )
|
||||||
|
{
|
||||||
pyDict[ it.key().toStdString() ] = variantToPyObject( it.value() );
|
pyDict[ it.key().toStdString() ] = variantToPyObject( it.value() );
|
||||||
|
}
|
||||||
return pyDict;
|
return pyDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,18 +203,22 @@ variantHashFromPyDict( const boost::python::dict& pyDict )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Helper* Helper::s_instance = nullptr;
|
Helper* Helper::s_instance = nullptr;
|
||||||
|
|
||||||
static inline void add_if_lib_exists( const QDir& dir, const char* name, QStringList& list )
|
static inline void
|
||||||
|
add_if_lib_exists( const QDir& dir, const char* name, QStringList& list )
|
||||||
{
|
{
|
||||||
if ( !( dir.exists() && dir.isReadable() ) )
|
if ( !( dir.exists() && dir.isReadable() ) )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QFileInfo fi( dir.absoluteFilePath( name ) );
|
QFileInfo fi( dir.absoluteFilePath( name ) );
|
||||||
if ( fi.exists() && fi.isReadable() )
|
if ( fi.exists() && fi.isReadable() )
|
||||||
|
{
|
||||||
list.append( fi.dir().absolutePath() );
|
list.append( fi.dir().absolutePath() );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Helper::Helper( QObject* parent )
|
Helper::Helper( QObject* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
@ -201,7 +227,9 @@ Helper::Helper( QObject* parent )
|
|||||||
if ( !s_instance )
|
if ( !s_instance )
|
||||||
{
|
{
|
||||||
if ( !Py_IsInitialized() )
|
if ( !Py_IsInitialized() )
|
||||||
|
{
|
||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
m_mainModule = bp::import( "__main__" );
|
m_mainModule = bp::import( "__main__" );
|
||||||
m_mainNamespace = m_mainModule.attr( "__dict__" );
|
m_mainNamespace = m_mainModule.attr( "__dict__" );
|
||||||
@ -209,8 +237,7 @@ Helper::Helper( QObject* parent )
|
|||||||
// If we're running from the build dir
|
// If we're running from the build dir
|
||||||
add_if_lib_exists( QDir::current(), "libcalamares.so", m_pythonPaths );
|
add_if_lib_exists( QDir::current(), "libcalamares.so", m_pythonPaths );
|
||||||
|
|
||||||
QDir calaPythonPath( CalamaresUtils::systemLibDir().absolutePath() +
|
QDir calaPythonPath( CalamaresUtils::systemLibDir().absolutePath() + QDir::separator() + "calamares" );
|
||||||
QDir::separator() + "calamares" );
|
|
||||||
add_if_lib_exists( calaPythonPath, "libcalamares.so", m_pythonPaths );
|
add_if_lib_exists( calaPythonPath, "libcalamares.so", m_pythonPaths );
|
||||||
|
|
||||||
bp::object sys = bp::import( "sys" );
|
bp::object sys = bp::import( "sys" );
|
||||||
@ -264,10 +291,14 @@ Helper::handleLastError()
|
|||||||
bp::str pystr( h_type );
|
bp::str pystr( h_type );
|
||||||
bp::extract< std::string > extracted( pystr );
|
bp::extract< std::string > extracted( pystr );
|
||||||
if ( extracted.check() )
|
if ( extracted.check() )
|
||||||
|
{
|
||||||
typeMsg = QString::fromStdString( extracted() ).trimmed();
|
typeMsg = QString::fromStdString( extracted() ).trimmed();
|
||||||
|
}
|
||||||
|
|
||||||
if ( typeMsg.isEmpty() )
|
if ( typeMsg.isEmpty() )
|
||||||
|
{
|
||||||
typeMsg = tr( "Unknown exception type" );
|
typeMsg = tr( "Unknown exception type" );
|
||||||
|
}
|
||||||
debug << typeMsg << '\n';
|
debug << typeMsg << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,10 +309,14 @@ Helper::handleLastError()
|
|||||||
bp::str pystr( h_val );
|
bp::str pystr( h_val );
|
||||||
bp::extract< std::string > extracted( pystr );
|
bp::extract< std::string > extracted( pystr );
|
||||||
if ( extracted.check() )
|
if ( extracted.check() )
|
||||||
|
{
|
||||||
valMsg = QString::fromStdString( extracted() ).trimmed();
|
valMsg = QString::fromStdString( extracted() ).trimmed();
|
||||||
|
}
|
||||||
|
|
||||||
if ( valMsg.isEmpty() )
|
if ( valMsg.isEmpty() )
|
||||||
|
{
|
||||||
valMsg = tr( "unparseable Python error" );
|
valMsg = tr( "unparseable Python error" );
|
||||||
|
}
|
||||||
|
|
||||||
// Special-case: CalledProcessError has an attribute "output" with the command output,
|
// Special-case: CalledProcessError has an attribute "output" with the command output,
|
||||||
// add that to the printed message.
|
// add that to the printed message.
|
||||||
@ -318,22 +353,32 @@ Helper::handleLastError()
|
|||||||
bp::object pystr( bp::str( "\n" ).join( tb_list ) );
|
bp::object pystr( bp::str( "\n" ).join( tb_list ) );
|
||||||
bp::extract< std::string > extracted( pystr );
|
bp::extract< std::string > extracted( pystr );
|
||||||
if ( extracted.check() )
|
if ( extracted.check() )
|
||||||
|
{
|
||||||
tbMsg = QString::fromStdString( extracted() ).trimmed();
|
tbMsg = QString::fromStdString( extracted() ).trimmed();
|
||||||
|
}
|
||||||
|
|
||||||
if ( tbMsg.isEmpty() )
|
if ( tbMsg.isEmpty() )
|
||||||
|
{
|
||||||
tbMsg = tr( "unparseable Python traceback" );
|
tbMsg = tr( "unparseable Python traceback" );
|
||||||
|
}
|
||||||
debug << tbMsg << '\n';
|
debug << tbMsg << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( typeMsg.isEmpty() && valMsg.isEmpty() && tbMsg.isEmpty() )
|
if ( typeMsg.isEmpty() && valMsg.isEmpty() && tbMsg.isEmpty() )
|
||||||
|
{
|
||||||
return tr( "Unfetchable Python error." );
|
return tr( "Unfetchable Python error." );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList msgList;
|
QStringList msgList;
|
||||||
if ( !typeMsg.isEmpty() )
|
if ( !typeMsg.isEmpty() )
|
||||||
|
{
|
||||||
msgList.append( QString( "<strong>%1</strong>" ).arg( typeMsg.toHtmlEscaped() ) );
|
msgList.append( QString( "<strong>%1</strong>" ).arg( typeMsg.toHtmlEscaped() ) );
|
||||||
|
}
|
||||||
if ( !valMsg.isEmpty() )
|
if ( !valMsg.isEmpty() )
|
||||||
|
{
|
||||||
msgList.append( valMsg.toHtmlEscaped() );
|
msgList.append( valMsg.toHtmlEscaped() );
|
||||||
|
}
|
||||||
|
|
||||||
if ( !tbMsg.isEmpty() )
|
if ( !tbMsg.isEmpty() )
|
||||||
{
|
{
|
||||||
|
@ -66,6 +66,6 @@ private:
|
|||||||
QStringList m_pythonPaths;
|
QStringList m_pythonPaths;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace CalamaresPython
|
||||||
|
|
||||||
#endif // CALAMARES_PYTHONJOBHELPER_H
|
#endif // CALAMARES_PYTHONJOBHELPER_H
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
#include "PythonJob.h"
|
#include "PythonJob.h"
|
||||||
|
|
||||||
#include "PythonHelper.h"
|
|
||||||
#include "utils/Logger.h"
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
#include "PythonHelper.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
@ -35,27 +35,19 @@
|
|||||||
|
|
||||||
namespace bp = boost::python;
|
namespace bp = boost::python;
|
||||||
|
|
||||||
BOOST_PYTHON_FUNCTION_OVERLOADS( mount_overloads,
|
BOOST_PYTHON_FUNCTION_OVERLOADS( mount_overloads, CalamaresPython::mount, 2, 4 );
|
||||||
CalamaresPython::mount,
|
BOOST_PYTHON_FUNCTION_OVERLOADS( target_env_call_str_overloads, CalamaresPython::target_env_call, 1, 3 );
|
||||||
2, 4 );
|
BOOST_PYTHON_FUNCTION_OVERLOADS( target_env_call_list_overloads, CalamaresPython::target_env_call, 1, 3 );
|
||||||
BOOST_PYTHON_FUNCTION_OVERLOADS( target_env_call_str_overloads,
|
BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_call_str_overloads, CalamaresPython::check_target_env_call, 1, 3 );
|
||||||
CalamaresPython::target_env_call,
|
BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_call_list_overloads, CalamaresPython::check_target_env_call, 1, 3 );
|
||||||
1, 3 );
|
|
||||||
BOOST_PYTHON_FUNCTION_OVERLOADS( target_env_call_list_overloads,
|
|
||||||
CalamaresPython::target_env_call,
|
|
||||||
1, 3 );
|
|
||||||
BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_call_str_overloads,
|
|
||||||
CalamaresPython::check_target_env_call,
|
|
||||||
1, 3 );
|
|
||||||
BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_call_list_overloads,
|
|
||||||
CalamaresPython::check_target_env_call,
|
|
||||||
1, 3 );
|
|
||||||
BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_output_str_overloads,
|
BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_output_str_overloads,
|
||||||
CalamaresPython::check_target_env_output,
|
CalamaresPython::check_target_env_output,
|
||||||
1, 3 );
|
1,
|
||||||
|
3 );
|
||||||
BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_output_list_overloads,
|
BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_output_list_overloads,
|
||||||
CalamaresPython::check_target_env_output,
|
CalamaresPython::check_target_env_output,
|
||||||
1, 3 );
|
1,
|
||||||
|
3 );
|
||||||
BOOST_PYTHON_MODULE( libcalamares )
|
BOOST_PYTHON_MODULE( libcalamares )
|
||||||
{
|
{
|
||||||
bp::object package = bp::scope();
|
bp::object package = bp::scope();
|
||||||
@ -72,15 +64,14 @@ BOOST_PYTHON_MODULE( libcalamares )
|
|||||||
.def_readonly( "pretty_name", &CalamaresPython::PythonJobInterface::prettyName )
|
.def_readonly( "pretty_name", &CalamaresPython::PythonJobInterface::prettyName )
|
||||||
.def_readonly( "working_path", &CalamaresPython::PythonJobInterface::workingPath )
|
.def_readonly( "working_path", &CalamaresPython::PythonJobInterface::workingPath )
|
||||||
.def_readonly( "configuration", &CalamaresPython::PythonJobInterface::configuration )
|
.def_readonly( "configuration", &CalamaresPython::PythonJobInterface::configuration )
|
||||||
.def(
|
.def( "setprogress",
|
||||||
"setprogress",
|
|
||||||
&CalamaresPython::PythonJobInterface::setprogress,
|
&CalamaresPython::PythonJobInterface::setprogress,
|
||||||
bp::args( "progress" ),
|
bp::args( "progress" ),
|
||||||
"Reports the progress status of this job to Calamares, "
|
"Reports the progress status of this job to Calamares, "
|
||||||
"as a real number between 0 and 1."
|
"as a real number between 0 and 1." );
|
||||||
);
|
|
||||||
|
|
||||||
bp::class_< CalamaresPython::GlobalStoragePythonWrapper >( "GlobalStorage", bp::init< Calamares::GlobalStorage* >() )
|
bp::class_< CalamaresPython::GlobalStoragePythonWrapper >( "GlobalStorage",
|
||||||
|
bp::init< Calamares::GlobalStorage* >() )
|
||||||
.def( "contains", &CalamaresPython::GlobalStoragePythonWrapper::contains )
|
.def( "contains", &CalamaresPython::GlobalStoragePythonWrapper::contains )
|
||||||
.def( "count", &CalamaresPython::GlobalStoragePythonWrapper::count )
|
.def( "count", &CalamaresPython::GlobalStoragePythonWrapper::count )
|
||||||
.def( "insert", &CalamaresPython::GlobalStoragePythonWrapper::insert )
|
.def( "insert", &CalamaresPython::GlobalStoragePythonWrapper::insert )
|
||||||
@ -95,151 +86,88 @@ BOOST_PYTHON_MODULE( libcalamares )
|
|||||||
Q_UNUSED( utilsScope )
|
Q_UNUSED( utilsScope )
|
||||||
|
|
||||||
bp::def(
|
bp::def(
|
||||||
"debug",
|
"debug", &CalamaresPython::debug, bp::args( "s" ), "Writes the given string to the Calamares debug stream." );
|
||||||
&CalamaresPython::debug,
|
bp::def( "warning",
|
||||||
bp::args( "s" ),
|
|
||||||
"Writes the given string to the Calamares debug stream."
|
|
||||||
);
|
|
||||||
bp::def(
|
|
||||||
"warning",
|
|
||||||
&CalamaresPython::warning,
|
&CalamaresPython::warning,
|
||||||
bp::args( "s" ),
|
bp::args( "s" ),
|
||||||
"Writes the given string to the Calamares warning stream."
|
"Writes the given string to the Calamares warning stream." );
|
||||||
);
|
|
||||||
|
|
||||||
bp::def(
|
bp::def( "mount",
|
||||||
"mount",
|
|
||||||
&CalamaresPython::mount,
|
&CalamaresPython::mount,
|
||||||
mount_overloads(
|
mount_overloads( bp::args( "device_path", "mount_point", "filesystem_name", "options" ),
|
||||||
bp::args( "device_path",
|
|
||||||
"mount_point",
|
|
||||||
"filesystem_name",
|
|
||||||
"options" ),
|
|
||||||
"Runs the mount utility with the specified parameters.\n"
|
"Runs the mount utility with the specified parameters.\n"
|
||||||
"Returns the program's exit code, or:\n"
|
"Returns the program's exit code, or:\n"
|
||||||
"-1 = QProcess crash\n"
|
"-1 = QProcess crash\n"
|
||||||
"-2 = QProcess cannot start\n"
|
"-2 = QProcess cannot start\n"
|
||||||
"-3 = bad arguments"
|
"-3 = bad arguments" ) );
|
||||||
)
|
|
||||||
);
|
|
||||||
bp::def(
|
bp::def(
|
||||||
"target_env_call",
|
"target_env_call",
|
||||||
static_cast< int (*)( const std::string&,
|
static_cast< int ( * )( const std::string&, const std::string&, int ) >( &CalamaresPython::target_env_call ),
|
||||||
const std::string&,
|
target_env_call_str_overloads( bp::args( "command", "stdin", "timeout" ),
|
||||||
int ) >( &CalamaresPython::target_env_call ),
|
|
||||||
target_env_call_str_overloads(
|
|
||||||
bp::args( "command",
|
|
||||||
"stdin",
|
|
||||||
"timeout" ),
|
|
||||||
"Runs the specified command in the chroot of the target system.\n"
|
"Runs the specified command in the chroot of the target system.\n"
|
||||||
"Returns the program's exit code, or:\n"
|
"Returns the program's exit code, or:\n"
|
||||||
"-1 = QProcess crash\n"
|
"-1 = QProcess crash\n"
|
||||||
"-2 = QProcess cannot start\n"
|
"-2 = QProcess cannot start\n"
|
||||||
"-3 = bad arguments\n"
|
"-3 = bad arguments\n"
|
||||||
"-4 = QProcess timeout"
|
"-4 = QProcess timeout" ) );
|
||||||
)
|
bp::def( "target_env_call",
|
||||||
);
|
static_cast< int ( * )( const bp::list&, const std::string&, int ) >( &CalamaresPython::target_env_call ),
|
||||||
bp::def(
|
target_env_call_list_overloads( bp::args( "args", "stdin", "timeout" ),
|
||||||
"target_env_call",
|
|
||||||
static_cast< int (*)( const bp::list&,
|
|
||||||
const std::string&,
|
|
||||||
int ) >( &CalamaresPython::target_env_call ),
|
|
||||||
target_env_call_list_overloads(
|
|
||||||
bp::args( "args",
|
|
||||||
"stdin",
|
|
||||||
"timeout" ),
|
|
||||||
"Runs the specified command in the chroot of the target system.\n"
|
"Runs the specified command in the chroot of the target system.\n"
|
||||||
"Returns the program's exit code, or:\n"
|
"Returns the program's exit code, or:\n"
|
||||||
"-1 = QProcess crash\n"
|
"-1 = QProcess crash\n"
|
||||||
"-2 = QProcess cannot start\n"
|
"-2 = QProcess cannot start\n"
|
||||||
"-3 = bad arguments\n"
|
"-3 = bad arguments\n"
|
||||||
"-4 = QProcess timeout"
|
"-4 = QProcess timeout" ) );
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
bp::def(
|
bp::def( "check_target_env_call",
|
||||||
"check_target_env_call",
|
static_cast< int ( * )( const std::string&, const std::string&, int ) >(
|
||||||
static_cast< int (*)( const std::string&,
|
&CalamaresPython::check_target_env_call ),
|
||||||
const std::string&,
|
check_target_env_call_str_overloads( bp::args( "command", "stdin", "timeout" ),
|
||||||
int ) >( &CalamaresPython::check_target_env_call ),
|
|
||||||
check_target_env_call_str_overloads(
|
|
||||||
bp::args( "command",
|
|
||||||
"stdin",
|
|
||||||
"timeout" ),
|
|
||||||
"Runs the specified command in the chroot of the target system.\n"
|
"Runs the specified command in the chroot of the target system.\n"
|
||||||
"Returns 0, which is program's exit code if the program exited "
|
"Returns 0, which is program's exit code if the program exited "
|
||||||
"successfully, or raises a subprocess.CalledProcessError."
|
"successfully, or raises a subprocess.CalledProcessError." ) );
|
||||||
)
|
|
||||||
);
|
|
||||||
bp::def(
|
bp::def(
|
||||||
"check_target_env_call",
|
"check_target_env_call",
|
||||||
static_cast< int (*)( const bp::list&,
|
static_cast< int ( * )( const bp::list&, const std::string&, int ) >( &CalamaresPython::check_target_env_call ),
|
||||||
const std::string&,
|
check_target_env_call_list_overloads( bp::args( "args", "stdin", "timeout" ),
|
||||||
int ) >( &CalamaresPython::check_target_env_call ),
|
|
||||||
check_target_env_call_list_overloads(
|
|
||||||
bp::args( "args",
|
|
||||||
"stdin",
|
|
||||||
"timeout" ),
|
|
||||||
"Runs the specified command in the chroot of the target system.\n"
|
"Runs the specified command in the chroot of the target system.\n"
|
||||||
"Returns 0, which is program's exit code if the program exited "
|
"Returns 0, which is program's exit code if the program exited "
|
||||||
"successfully, or raises a subprocess.CalledProcessError."
|
"successfully, or raises a subprocess.CalledProcessError." ) );
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
bp::def(
|
bp::def( "check_target_env_output",
|
||||||
"check_target_env_output",
|
static_cast< std::string ( * )( const std::string&, const std::string&, int ) >(
|
||||||
static_cast< std::string (*)( const std::string&,
|
&CalamaresPython::check_target_env_output ),
|
||||||
const std::string&,
|
check_target_env_output_str_overloads( bp::args( "command", "stdin", "timeout" ),
|
||||||
int ) >( &CalamaresPython::check_target_env_output ),
|
|
||||||
check_target_env_output_str_overloads(
|
|
||||||
bp::args( "command",
|
|
||||||
"stdin",
|
|
||||||
"timeout" ),
|
|
||||||
"Runs the specified command in the chroot of the target system.\n"
|
"Runs the specified command in the chroot of the target system.\n"
|
||||||
"Returns the program's standard output, and raises a "
|
"Returns the program's standard output, and raises a "
|
||||||
"subprocess.CalledProcessError if something went wrong."
|
"subprocess.CalledProcessError if something went wrong." ) );
|
||||||
)
|
bp::def( "check_target_env_output",
|
||||||
);
|
static_cast< std::string ( * )( const bp::list&, const std::string&, int ) >(
|
||||||
bp::def(
|
&CalamaresPython::check_target_env_output ),
|
||||||
"check_target_env_output",
|
check_target_env_output_list_overloads( bp::args( "args", "stdin", "timeout" ),
|
||||||
static_cast< std::string (*)( const bp::list&,
|
|
||||||
const std::string&,
|
|
||||||
int ) >( &CalamaresPython::check_target_env_output ),
|
|
||||||
check_target_env_output_list_overloads(
|
|
||||||
bp::args( "args",
|
|
||||||
"stdin",
|
|
||||||
"timeout" ),
|
|
||||||
"Runs the specified command in the chroot of the target system.\n"
|
"Runs the specified command in the chroot of the target system.\n"
|
||||||
"Returns the program's standard output, and raises a "
|
"Returns the program's standard output, and raises a "
|
||||||
"subprocess.CalledProcessError if something went wrong."
|
"subprocess.CalledProcessError if something went wrong." ) );
|
||||||
)
|
bp::def( "obscure",
|
||||||
);
|
|
||||||
bp::def(
|
|
||||||
"obscure",
|
|
||||||
&CalamaresPython::obscure,
|
&CalamaresPython::obscure,
|
||||||
bp::args( "s" ),
|
bp::args( "s" ),
|
||||||
"Simple string obfuscation function based on KStringHandler::obscure.\n"
|
"Simple string obfuscation function based on KStringHandler::obscure.\n"
|
||||||
"Returns a string, generated using a simple symmetric encryption.\n"
|
"Returns a string, generated using a simple symmetric encryption.\n"
|
||||||
"Applying the function to a string obscured by this function will result "
|
"Applying the function to a string obscured by this function will result "
|
||||||
"in the original string."
|
"in the original string." );
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
bp::def(
|
bp::def( "gettext_languages",
|
||||||
"gettext_languages",
|
|
||||||
&CalamaresPython::gettext_languages,
|
&CalamaresPython::gettext_languages,
|
||||||
"Returns list of languages (most to least-specific) for gettext."
|
"Returns list of languages (most to least-specific) for gettext." );
|
||||||
);
|
|
||||||
|
|
||||||
bp::def(
|
bp::def( "gettext_path", &CalamaresPython::gettext_path, "Returns path for gettext search." );
|
||||||
"gettext_path",
|
|
||||||
&CalamaresPython::gettext_path,
|
|
||||||
"Returns path for gettext search."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace Calamares {
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
PythonJob::PythonJob( const QString& scriptFile,
|
PythonJob::PythonJob( const QString& scriptFile,
|
||||||
@ -255,8 +183,7 @@ PythonJob::PythonJob( const QString& scriptFile,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PythonJob::~PythonJob()
|
PythonJob::~PythonJob() {}
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
@ -270,11 +197,12 @@ QString
|
|||||||
PythonJob::prettyStatusMessage() const
|
PythonJob::prettyStatusMessage() const
|
||||||
{
|
{
|
||||||
if ( m_description.isEmpty() )
|
if ( m_description.isEmpty() )
|
||||||
return tr( "Running %1 operation." )
|
return tr( "Running %1 operation." ).arg( QDir( m_workingPath ).dirName() );
|
||||||
.arg( QDir( m_workingPath ).dirName() );
|
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return m_description;
|
return m_description;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
JobResult
|
JobResult
|
||||||
@ -282,19 +210,15 @@ PythonJob::exec()
|
|||||||
{
|
{
|
||||||
// We assume m_scriptFile to be relative to m_workingPath.
|
// We assume m_scriptFile to be relative to m_workingPath.
|
||||||
QDir workingDir( m_workingPath );
|
QDir workingDir( m_workingPath );
|
||||||
if ( !workingDir.exists() ||
|
if ( !workingDir.exists() || !workingDir.isReadable() )
|
||||||
!workingDir.isReadable() )
|
|
||||||
{
|
{
|
||||||
return JobResult::error( tr( "Bad working directory path" ),
|
return JobResult::error(
|
||||||
tr( "Working directory %1 for python job %2 is not readable." )
|
tr( "Bad working directory path" ),
|
||||||
.arg( m_workingPath )
|
tr( "Working directory %1 for python job %2 is not readable." ).arg( m_workingPath ).arg( prettyName() ) );
|
||||||
.arg( prettyName() ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo scriptFI( workingDir.absoluteFilePath( m_scriptFile ) );
|
QFileInfo scriptFI( workingDir.absoluteFilePath( m_scriptFile ) );
|
||||||
if ( !scriptFI.exists() ||
|
if ( !scriptFI.exists() || !scriptFI.isFile() || !scriptFI.isReadable() )
|
||||||
!scriptFI.isFile() ||
|
|
||||||
!scriptFI.isReadable() )
|
|
||||||
{
|
{
|
||||||
return JobResult::error( tr( "Bad main script file" ),
|
return JobResult::error( tr( "Bad main script file" ),
|
||||||
tr( "Main script file %1 for python job %2 is not readable." )
|
tr( "Main script file %1 for python job %2 is not readable." )
|
||||||
@ -310,12 +234,11 @@ PythonJob::exec()
|
|||||||
bp::dict calamaresNamespace = bp::extract< bp::dict >( calamaresModule.attr( "__dict__" ) );
|
bp::dict calamaresNamespace = bp::extract< bp::dict >( calamaresModule.attr( "__dict__" ) );
|
||||||
|
|
||||||
calamaresNamespace[ "job" ] = CalamaresPython::PythonJobInterface( this );
|
calamaresNamespace[ "job" ] = CalamaresPython::PythonJobInterface( this );
|
||||||
calamaresNamespace[ "globalstorage" ] = CalamaresPython::GlobalStoragePythonWrapper(
|
calamaresNamespace[ "globalstorage" ]
|
||||||
JobQueue::instance()->globalStorage() );
|
= CalamaresPython::GlobalStoragePythonWrapper( JobQueue::instance()->globalStorage() );
|
||||||
|
|
||||||
bp::object execResult = bp::exec_file( scriptFI.absoluteFilePath().toLocal8Bit().data(),
|
bp::object execResult
|
||||||
scriptNamespace,
|
= bp::exec_file( scriptFI.absoluteFilePath().toLocal8Bit().data(), scriptNamespace, scriptNamespace );
|
||||||
scriptNamespace );
|
|
||||||
|
|
||||||
bp::object entryPoint = scriptNamespace[ "run" ];
|
bp::object entryPoint = scriptNamespace[ "run" ];
|
||||||
bp::object prettyNameFunc = scriptNamespace.get( "pretty_name", bp::object() );
|
bp::object prettyNameFunc = scriptNamespace.get( "pretty_name", bp::object() );
|
||||||
@ -344,7 +267,9 @@ PythonJob::exec()
|
|||||||
m_description = QString::fromStdString( entryPoint_doc_attr() ).trimmed();
|
m_description = QString::fromStdString( entryPoint_doc_attr() ).trimmed();
|
||||||
auto i_newline = m_description.indexOf( '\n' );
|
auto i_newline = m_description.indexOf( '\n' );
|
||||||
if ( i_newline > 0 )
|
if ( i_newline > 0 )
|
||||||
|
{
|
||||||
m_description.truncate( i_newline );
|
m_description.truncate( i_newline );
|
||||||
|
}
|
||||||
cDebug() << "Job description from __doc__" << prettyName() << "=" << m_description;
|
cDebug() << "Job description from __doc__" << prettyName() << "=" << m_description;
|
||||||
emit progress( 0 );
|
emit progress( 0 );
|
||||||
}
|
}
|
||||||
@ -374,9 +299,7 @@ PythonJob::exec()
|
|||||||
bp::handle_exception();
|
bp::handle_exception();
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
return JobResult::internalError(
|
return JobResult::internalError(
|
||||||
tr( "Boost.Python error in job \"%1\"." ).arg( prettyName() ),
|
tr( "Boost.Python error in job \"%1\"." ).arg( prettyName() ), msg, JobResult::PythonUncaughtException );
|
||||||
msg,
|
|
||||||
JobResult::PythonUncaughtException );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,7 +316,9 @@ PythonJob::helper()
|
|||||||
{
|
{
|
||||||
auto ptr = CalamaresPython::Helper::s_instance;
|
auto ptr = CalamaresPython::Helper::s_instance;
|
||||||
if ( !ptr )
|
if ( !ptr )
|
||||||
|
{
|
||||||
ptr = new CalamaresPython::Helper;
|
ptr = new CalamaresPython::Helper;
|
||||||
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +27,10 @@ namespace CalamaresPython
|
|||||||
{
|
{
|
||||||
class PythonJobInterface;
|
class PythonJobInterface;
|
||||||
class Helper;
|
class Helper;
|
||||||
}
|
} // namespace CalamaresPython
|
||||||
|
|
||||||
namespace Calamares {
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
class PythonJob : public Job
|
class PythonJob : public Job
|
||||||
{
|
{
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
#include "PythonJobApi.h"
|
#include "PythonJobApi.h"
|
||||||
|
|
||||||
#include "PythonHelper.h"
|
#include "PythonHelper.h"
|
||||||
#include "utils/Logger.h"
|
|
||||||
#include "utils/CalamaresUtilsSystem.h"
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
#include "utils/String.h"
|
#include "utils/String.h"
|
||||||
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
@ -40,14 +40,18 @@ static int
|
|||||||
_handle_check_target_env_call_error( const CalamaresUtils::ProcessResult& ec, const QString& cmd )
|
_handle_check_target_env_call_error( const CalamaresUtils::ProcessResult& ec, const QString& cmd )
|
||||||
{
|
{
|
||||||
if ( !ec.first )
|
if ( !ec.first )
|
||||||
|
{
|
||||||
return ec.first;
|
return ec.first;
|
||||||
|
}
|
||||||
|
|
||||||
QString raise = QString( "import subprocess\n"
|
QString raise = QString( "import subprocess\n"
|
||||||
"e = subprocess.CalledProcessError(%1,\"%2\")\n" )
|
"e = subprocess.CalledProcessError(%1,\"%2\")\n" )
|
||||||
.arg( ec.first )
|
.arg( ec.first )
|
||||||
.arg( cmd );
|
.arg( cmd );
|
||||||
if ( !ec.second.isEmpty() )
|
if ( !ec.second.isEmpty() )
|
||||||
|
{
|
||||||
raise.append( QStringLiteral( "e.output = \"\"\"%1\"\"\"\n" ).arg( ec.second ) );
|
raise.append( QStringLiteral( "e.output = \"\"\"%1\"\"\"\n" ).arg( ec.second ) );
|
||||||
|
}
|
||||||
raise.append( "raise e" );
|
raise.append( "raise e" );
|
||||||
bp::exec( raise.toStdString().c_str() );
|
bp::exec( raise.toStdString().c_str() );
|
||||||
bp::throw_error_already_set();
|
bp::throw_error_already_set();
|
||||||
@ -63,8 +67,7 @@ mount( const std::string& device_path,
|
|||||||
const std::string& filesystem_name,
|
const std::string& filesystem_name,
|
||||||
const std::string& options )
|
const std::string& options )
|
||||||
{
|
{
|
||||||
return CalamaresUtils::System::instance()->
|
return CalamaresUtils::System::instance()->mount( QString::fromStdString( device_path ),
|
||||||
mount( QString::fromStdString( device_path ),
|
|
||||||
QString::fromStdString( mount_point ),
|
QString::fromStdString( mount_point ),
|
||||||
QString::fromStdString( filesystem_name ),
|
QString::fromStdString( filesystem_name ),
|
||||||
QString::fromStdString( options ) );
|
QString::fromStdString( options ) );
|
||||||
@ -77,66 +80,50 @@ _bp_list_to_qstringlist( const bp::list& args )
|
|||||||
QStringList list;
|
QStringList list;
|
||||||
for ( int i = 0; i < bp::len( args ); ++i )
|
for ( int i = 0; i < bp::len( args ); ++i )
|
||||||
{
|
{
|
||||||
list.append( QString::fromStdString(
|
list.append( QString::fromStdString( bp::extract< std::string >( args[ i ] ) ) );
|
||||||
bp::extract< std::string >( args[ i ] ) ) );
|
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline CalamaresUtils::ProcessResult
|
static inline CalamaresUtils::ProcessResult
|
||||||
_target_env_command(
|
_target_env_command( const QStringList& args, const std::string& stdin, int timeout )
|
||||||
const QStringList& args,
|
|
||||||
const std::string& stdin,
|
|
||||||
int timeout )
|
|
||||||
{
|
{
|
||||||
// Since Python doesn't give us the type system for distinguishing
|
// Since Python doesn't give us the type system for distinguishing
|
||||||
// seconds from other integral types, massage to seconds here.
|
// seconds from other integral types, massage to seconds here.
|
||||||
return CalamaresUtils::System::instance()->
|
return CalamaresUtils::System::instance()->targetEnvCommand(
|
||||||
targetEnvCommand( args,
|
args, QString(), QString::fromStdString( stdin ), std::chrono::seconds( timeout ) );
|
||||||
QString(),
|
|
||||||
QString::fromStdString( stdin ),
|
|
||||||
std::chrono::seconds( timeout ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
target_env_call( const std::string& command,
|
target_env_call( const std::string& command, const std::string& stdin, int timeout )
|
||||||
const std::string& stdin,
|
|
||||||
int timeout )
|
|
||||||
{
|
{
|
||||||
return _target_env_command(
|
return _target_env_command( QStringList { QString::fromStdString( command ) }, stdin, timeout ).first;
|
||||||
QStringList{ QString::fromStdString( command ) }, stdin, timeout ).first;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
target_env_call( const bp::list& args,
|
target_env_call( const bp::list& args, const std::string& stdin, int timeout )
|
||||||
const std::string& stdin,
|
|
||||||
int timeout )
|
|
||||||
{
|
{
|
||||||
return _target_env_command(
|
return _target_env_command( _bp_list_to_qstringlist( args ), stdin, timeout ).first;
|
||||||
_bp_list_to_qstringlist( args ), stdin, timeout ).first;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
check_target_env_call( const std::string& command,
|
check_target_env_call( const std::string& command, const std::string& stdin, int timeout )
|
||||||
const std::string& stdin,
|
|
||||||
int timeout )
|
|
||||||
{
|
{
|
||||||
auto ec = _target_env_command(
|
auto ec = _target_env_command( QStringList { QString::fromStdString( command ) }, stdin, timeout );
|
||||||
QStringList{ QString::fromStdString( command ) }, stdin, timeout );
|
|
||||||
return _handle_check_target_env_call_error( ec, QString::fromStdString( command ) );
|
return _handle_check_target_env_call_error( ec, QString::fromStdString( command ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
check_target_env_call( const bp::list& args,
|
check_target_env_call( const bp::list& args, const std::string& stdin, int timeout )
|
||||||
const std::string& stdin,
|
|
||||||
int timeout )
|
|
||||||
{
|
{
|
||||||
auto ec = _target_env_command( _bp_list_to_qstringlist( args ), stdin, timeout );
|
auto ec = _target_env_command( _bp_list_to_qstringlist( args ), stdin, timeout );
|
||||||
if ( !ec.first )
|
if ( !ec.first )
|
||||||
|
{
|
||||||
return ec.first;
|
return ec.first;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList failedCmdList = _bp_list_to_qstringlist( args );
|
QStringList failedCmdList = _bp_list_to_qstringlist( args );
|
||||||
return _handle_check_target_env_call_error( ec, failedCmdList.join( ' ' ) );
|
return _handle_check_target_env_call_error( ec, failedCmdList.join( ' ' ) );
|
||||||
@ -144,25 +131,19 @@ check_target_env_call( const bp::list& args,
|
|||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
check_target_env_output( const std::string& command,
|
check_target_env_output( const std::string& command, const std::string& stdin, int timeout )
|
||||||
const std::string& stdin,
|
|
||||||
int timeout )
|
|
||||||
{
|
{
|
||||||
auto ec = _target_env_command(
|
auto ec = _target_env_command( QStringList { QString::fromStdString( command ) }, stdin, timeout );
|
||||||
QStringList{ QString::fromStdString( command ) }, stdin, timeout );
|
|
||||||
_handle_check_target_env_call_error( ec, QString::fromStdString( command ) );
|
_handle_check_target_env_call_error( ec, QString::fromStdString( command ) );
|
||||||
return ec.second.toStdString();
|
return ec.second.toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
check_target_env_output( const bp::list& args,
|
check_target_env_output( const bp::list& args, const std::string& stdin, int timeout )
|
||||||
const std::string& stdin,
|
|
||||||
int timeout )
|
|
||||||
{
|
{
|
||||||
QStringList list = _bp_list_to_qstringlist( args );
|
QStringList list = _bp_list_to_qstringlist( args );
|
||||||
auto ec = _target_env_command(
|
auto ec = _target_env_command( list, stdin, timeout );
|
||||||
list, stdin, timeout );
|
|
||||||
_handle_check_target_env_call_error( ec, list.join( ' ' ) );
|
_handle_check_target_env_call_error( ec, list.join( ' ' ) );
|
||||||
return ec.second.toStdString();
|
return ec.second.toStdString();
|
||||||
}
|
}
|
||||||
@ -194,8 +175,10 @@ void
|
|||||||
PythonJobInterface::setprogress( qreal progress )
|
PythonJobInterface::setprogress( qreal progress )
|
||||||
{
|
{
|
||||||
if ( progress >= 0 && progress <= 1 )
|
if ( progress >= 0 && progress <= 1 )
|
||||||
|
{
|
||||||
m_parent->emitProgress( progress );
|
m_parent->emitProgress( progress );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
@ -216,7 +199,8 @@ _gettext_languages()
|
|||||||
// own GlobalStoragePythonWrapper, which then holds a
|
// own GlobalStoragePythonWrapper, which then holds a
|
||||||
// GlobalStorage object for all of Python.
|
// GlobalStorage object for all of Python.
|
||||||
Calamares::JobQueue* jq = Calamares::JobQueue::instance();
|
Calamares::JobQueue* jq = Calamares::JobQueue::instance();
|
||||||
Calamares::GlobalStorage* gs = jq ? jq->globalStorage() : CalamaresPython::GlobalStoragePythonWrapper::globalStorageInstance();
|
Calamares::GlobalStorage* gs
|
||||||
|
= jq ? jq->globalStorage() : CalamaresPython::GlobalStoragePythonWrapper::globalStorageInstance();
|
||||||
|
|
||||||
QVariant localeConf_ = gs->value( "localeConf" );
|
QVariant localeConf_ = gs->value( "localeConf" );
|
||||||
if ( localeConf_.canConvert< QVariantMap >() )
|
if ( localeConf_.canConvert< QVariantMap >() )
|
||||||
@ -246,7 +230,9 @@ gettext_languages()
|
|||||||
{
|
{
|
||||||
bp::list pyList;
|
bp::list pyList;
|
||||||
for ( auto lang : _gettext_languages() )
|
for ( auto lang : _gettext_languages() )
|
||||||
|
{
|
||||||
pyList.append( lang.toStdString() );
|
pyList.append( lang.toStdString() );
|
||||||
|
}
|
||||||
return pyList;
|
return pyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,24 +243,29 @@ _add_localedirs( QStringList& pathList, const QString& candidate )
|
|||||||
{
|
{
|
||||||
pathList.prepend( candidate );
|
pathList.prepend( candidate );
|
||||||
if ( QDir( candidate ).cd( "lang" ) )
|
if ( QDir( candidate ).cd( "lang" ) )
|
||||||
|
{
|
||||||
pathList.prepend( candidate + "/lang" );
|
pathList.prepend( candidate + "/lang" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bp::object
|
bp::object
|
||||||
gettext_path()
|
gettext_path()
|
||||||
{
|
{
|
||||||
// TODO: distinguish between -d runs and normal runs
|
// TODO: distinguish between -d runs and normal runs
|
||||||
// TODO: can we detect DESTDIR-installs?
|
// TODO: can we detect DESTDIR-installs?
|
||||||
QStringList candidatePaths = QStandardPaths::locateAll( QStandardPaths::GenericDataLocation, "locale", QStandardPaths::LocateDirectory );
|
QStringList candidatePaths
|
||||||
|
= QStandardPaths::locateAll( QStandardPaths::GenericDataLocation, "locale", QStandardPaths::LocateDirectory );
|
||||||
QString extra = QCoreApplication::applicationDirPath();
|
QString extra = QCoreApplication::applicationDirPath();
|
||||||
_add_localedirs( candidatePaths, extra ); // Often /usr/local/bin
|
_add_localedirs( candidatePaths, extra ); // Often /usr/local/bin
|
||||||
if ( !extra.isEmpty() )
|
if ( !extra.isEmpty() )
|
||||||
{
|
{
|
||||||
QDir d( extra );
|
QDir d( extra );
|
||||||
if ( d.cd( "../share/locale" ) ) // Often /usr/local/bin/../share/locale -> /usr/local/share/locale
|
if ( d.cd( "../share/locale" ) ) // Often /usr/local/bin/../share/locale -> /usr/local/share/locale
|
||||||
|
{
|
||||||
_add_localedirs( candidatePaths, d.canonicalPath() );
|
_add_localedirs( candidatePaths, d.canonicalPath() );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_add_localedirs( candidatePaths, QDir().canonicalPath() ); // .
|
_add_localedirs( candidatePaths, QDir().canonicalPath() ); // .
|
||||||
|
|
||||||
cDebug() << "Determining gettext path from" << candidatePaths;
|
cDebug() << "Determining gettext path from" << candidatePaths;
|
||||||
@ -296,4 +287,4 @@ gettext_path()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
} // namespace CalamaresPython
|
||||||
|
@ -35,29 +35,19 @@ int mount( const std::string& device_path,
|
|||||||
const std::string& filesystem_name = std::string(),
|
const std::string& filesystem_name = std::string(),
|
||||||
const std::string& options = std::string() );
|
const std::string& options = std::string() );
|
||||||
|
|
||||||
int target_env_call( const std::string& command,
|
int target_env_call( const std::string& command, const std::string& stdin = std::string(), int timeout = 0 );
|
||||||
const std::string& stdin = std::string(),
|
|
||||||
int timeout = 0 );
|
|
||||||
|
|
||||||
int target_env_call( const boost::python::list& args,
|
int target_env_call( const boost::python::list& args, const std::string& stdin = std::string(), int timeout = 0 );
|
||||||
const std::string& stdin = std::string(),
|
|
||||||
int timeout = 0 );
|
|
||||||
|
|
||||||
int check_target_env_call( const std::string& command,
|
int check_target_env_call( const std::string& command, const std::string& stdin = std::string(), int timeout = 0 );
|
||||||
const std::string& stdin = std::string(),
|
|
||||||
int timeout = 0 );
|
|
||||||
|
|
||||||
int check_target_env_call( const boost::python::list& args,
|
int check_target_env_call( const boost::python::list& args, const std::string& stdin = std::string(), int timeout = 0 );
|
||||||
const std::string& stdin = std::string(),
|
|
||||||
int timeout = 0 );
|
|
||||||
|
|
||||||
std::string check_target_env_output( const std::string& command,
|
std::string
|
||||||
const std::string& stdin = std::string(),
|
check_target_env_output( const std::string& command, const std::string& stdin = std::string(), int timeout = 0 );
|
||||||
int timeout = 0 );
|
|
||||||
|
|
||||||
std::string check_target_env_output( const boost::python::list& args,
|
std::string
|
||||||
const std::string& stdin = std::string(),
|
check_target_env_output( const boost::python::list& args, const std::string& stdin = std::string(), int timeout = 0 );
|
||||||
int timeout = 0 );
|
|
||||||
|
|
||||||
std::string obscure( const std::string& string );
|
std::string obscure( const std::string& string );
|
||||||
|
|
||||||
@ -85,6 +75,6 @@ private:
|
|||||||
Calamares::PythonJob* m_parent;
|
Calamares::PythonJob* m_parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace CalamaresPython
|
||||||
|
|
||||||
#endif // PYTHONJOBAPI_H
|
#endif // PYTHONJOBAPI_H
|
||||||
|
@ -41,7 +41,9 @@ requireString( const YAML::Node& config, const char* key )
|
|||||||
{
|
{
|
||||||
auto v = config[ key ];
|
auto v = config[ key ];
|
||||||
if ( hasValue( v ) )
|
if ( hasValue( v ) )
|
||||||
|
{
|
||||||
return QString::fromStdString( v.as< std::string >() );
|
return QString::fromStdString( v.as< std::string >() );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cWarning() << Logger::SubEntry << "Required settings.conf key" << key << "is missing.";
|
cWarning() << Logger::SubEntry << "Required settings.conf key" << key << "is missing.";
|
||||||
@ -55,7 +57,9 @@ requireBool( const YAML::Node& config, const char* key, bool d )
|
|||||||
{
|
{
|
||||||
auto v = config[ key ];
|
auto v = config[ key ];
|
||||||
if ( hasValue( v ) )
|
if ( hasValue( v ) )
|
||||||
|
{
|
||||||
return v.as< bool >();
|
return v.as< bool >();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cWarning() << Logger::SubEntry << "Required settings.conf key" << key << "is missing.";
|
cWarning() << Logger::SubEntry << "Required settings.conf key" << key << "is missing.";
|
||||||
@ -86,17 +90,17 @@ interpretModulesSearch( const bool debugMode, const QStringList& rawPaths, QStri
|
|||||||
// module search path in the build dir.
|
// module search path in the build dir.
|
||||||
if ( debugMode )
|
if ( debugMode )
|
||||||
{
|
{
|
||||||
QString buildDirModules = QDir::current().absolutePath() +
|
QString buildDirModules
|
||||||
QDir::separator() + "src" +
|
= QDir::current().absolutePath() + QDir::separator() + "src" + QDir::separator() + "modules";
|
||||||
QDir::separator() + "modules";
|
|
||||||
if ( QDir( buildDirModules ).exists() )
|
if ( QDir( buildDirModules ).exists() )
|
||||||
|
{
|
||||||
output.append( buildDirModules );
|
output.append( buildDirModules );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Install path is set in CalamaresAddPlugin.cmake
|
// Install path is set in CalamaresAddPlugin.cmake
|
||||||
output.append( CalamaresUtils::systemLibDir().absolutePath() +
|
output.append( CalamaresUtils::systemLibDir().absolutePath() + QDir::separator() + "calamares"
|
||||||
QDir::separator() + "calamares" +
|
+ QDir::separator() + "modules" );
|
||||||
QDir::separator() + "modules" );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -106,10 +110,12 @@ interpretModulesSearch( const bool debugMode, const QStringList& rawPaths, QStri
|
|||||||
output.append( d.absolutePath() );
|
output.append( d.absolutePath() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
cDebug() << Logger::SubEntry << "module-search entry non-existent" << path;
|
cDebug() << Logger::SubEntry << "module-search entry non-existent" << path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
interpretInstances( const YAML::Node& node, Settings::InstanceDescriptionList& customInstances )
|
interpretInstances( const YAML::Node& node, Settings::InstanceDescriptionList& customInstances )
|
||||||
@ -124,15 +130,17 @@ interpretInstances( const YAML::Node& node, Settings::InstanceDescriptionList& c
|
|||||||
for ( const QVariant& instancesVListItem : instances )
|
for ( const QVariant& instancesVListItem : instances )
|
||||||
{
|
{
|
||||||
if ( instancesVListItem.type() != QVariant::Map )
|
if ( instancesVListItem.type() != QVariant::Map )
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
QVariantMap instancesVListItemMap =
|
}
|
||||||
instancesVListItem.toMap();
|
QVariantMap instancesVListItemMap = instancesVListItem.toMap();
|
||||||
Settings::InstanceDescription instanceMap;
|
Settings::InstanceDescription instanceMap;
|
||||||
for ( auto it = instancesVListItemMap.constBegin();
|
for ( auto it = instancesVListItemMap.constBegin(); it != instancesVListItemMap.constEnd(); ++it )
|
||||||
it != instancesVListItemMap.constEnd(); ++it )
|
|
||||||
{
|
{
|
||||||
if ( it.value().type() != QVariant::String )
|
if ( it.value().type() != QVariant::String )
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
instanceMap.insert( it.key(), it.value().toString() );
|
instanceMap.insert( it.key(), it.value().toString() );
|
||||||
}
|
}
|
||||||
customInstances.append( instanceMap );
|
customInstances.append( instanceMap );
|
||||||
@ -149,37 +157,43 @@ interpretSequence( const YAML::Node& node, Settings::ModuleSequence& moduleSeque
|
|||||||
{
|
{
|
||||||
QVariant sequenceV = CalamaresUtils::yamlToVariant( node );
|
QVariant sequenceV = CalamaresUtils::yamlToVariant( node );
|
||||||
if ( !( sequenceV.type() == QVariant::List ) )
|
if ( !( sequenceV.type() == QVariant::List ) )
|
||||||
|
{
|
||||||
throw YAML::Exception( YAML::Mark(), "sequence key does not have a list-value" );
|
throw YAML::Exception( YAML::Mark(), "sequence key does not have a list-value" );
|
||||||
|
}
|
||||||
|
|
||||||
const auto sequence = sequenceV.toList();
|
const auto sequence = sequenceV.toList();
|
||||||
for ( const QVariant& sequenceVListItem : sequence )
|
for ( const QVariant& sequenceVListItem : sequence )
|
||||||
{
|
{
|
||||||
if ( sequenceVListItem.type() != QVariant::Map )
|
if ( sequenceVListItem.type() != QVariant::Map )
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
QString thisActionS = sequenceVListItem.toMap().firstKey();
|
QString thisActionS = sequenceVListItem.toMap().firstKey();
|
||||||
ModuleAction thisAction;
|
ModuleAction thisAction;
|
||||||
if ( thisActionS == "show" )
|
if ( thisActionS == "show" )
|
||||||
|
{
|
||||||
thisAction = ModuleAction::Show;
|
thisAction = ModuleAction::Show;
|
||||||
|
}
|
||||||
else if ( thisActionS == "exec" )
|
else if ( thisActionS == "exec" )
|
||||||
|
{
|
||||||
thisAction = ModuleAction::Exec;
|
thisAction = ModuleAction::Exec;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList thisActionRoster = sequenceVListItem
|
QStringList thisActionRoster = sequenceVListItem.toMap().value( thisActionS ).toStringList();
|
||||||
.toMap()
|
moduleSequence.append( qMakePair( thisAction, thisActionRoster ) );
|
||||||
.value( thisActionS )
|
|
||||||
.toStringList();
|
|
||||||
moduleSequence.append( qMakePair( thisAction,
|
|
||||||
thisActionRoster ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
throw YAML::Exception( YAML::Mark(), "sequence key is missing" );
|
throw YAML::Exception( YAML::Mark(), "sequence key is missing" );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Settings::Settings( const QString& settingsFilePath,
|
Settings::Settings( const QString& settingsFilePath, bool debugMode, QObject* parent )
|
||||||
bool debugMode,
|
|
||||||
QObject* parent )
|
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_debug( debugMode )
|
, m_debug( debugMode )
|
||||||
, m_doChroot( true )
|
, m_doChroot( true )
|
||||||
@ -198,7 +212,8 @@ Settings::Settings( const QString& settingsFilePath,
|
|||||||
YAML::Node config = YAML::Load( ba.constData() );
|
YAML::Node config = YAML::Load( ba.constData() );
|
||||||
Q_ASSERT( config.IsMap() );
|
Q_ASSERT( config.IsMap() );
|
||||||
|
|
||||||
interpretModulesSearch( debugMode, CalamaresUtils::yamlToStringList( config[ "modules-search" ] ), m_modulesSearchPaths );
|
interpretModulesSearch(
|
||||||
|
debugMode, CalamaresUtils::yamlToStringList( config[ "modules-search" ] ), m_modulesSearchPaths );
|
||||||
interpretInstances( config[ "instances" ], m_customModuleInstances );
|
interpretInstances( config[ "instances" ], m_customModuleInstances );
|
||||||
interpretSequence( config[ "sequence" ], m_modulesSequence );
|
interpretSequence( config[ "sequence" ], m_modulesSequence );
|
||||||
|
|
||||||
@ -283,4 +298,4 @@ Settings::disableCancelDuringExec() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
} // namespace Calamares
|
||||||
|
@ -36,9 +36,7 @@ class DLLEXPORT Settings : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Settings( const QString& settingsFilePath,
|
explicit Settings( const QString& settingsFilePath, bool debugMode, QObject* parent = nullptr );
|
||||||
bool debugMode,
|
|
||||||
QObject* parent = nullptr );
|
|
||||||
|
|
||||||
static Settings* instance();
|
static Settings* instance();
|
||||||
|
|
||||||
@ -88,6 +86,6 @@ private:
|
|||||||
bool m_disableCancelDuringExec;
|
bool m_disableCancelDuringExec;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace Calamares
|
||||||
|
|
||||||
#endif // SETTINGS_H
|
#endif // SETTINGS_H
|
||||||
|
Loading…
Reference in New Issue
Block a user