[libcalamares] Refactor pretty_name() call
- Split out a general method-that-returns-string caller.
This commit is contained in:
parent
ed4cdbeacc
commit
252089e372
@ -215,6 +215,18 @@ PythonJob::prettyStatusMessage() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QString
|
||||||
|
pythonStringMethod( bp::dict& script, const char* funcName )
|
||||||
|
{
|
||||||
|
bp::object func = script.get( funcName, bp::object() );
|
||||||
|
if ( !func.is_none() )
|
||||||
|
{
|
||||||
|
bp::extract< std::string > result( func() );
|
||||||
|
return result.check() ? QString::fromStdString( result() ).trimmed() : QString();
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
JobResult
|
JobResult
|
||||||
PythonJob::exec()
|
PythonJob::exec()
|
||||||
@ -248,27 +260,12 @@ PythonJob::exec()
|
|||||||
calamaresNamespace[ "globalstorage" ]
|
calamaresNamespace[ "globalstorage" ]
|
||||||
= CalamaresPython::GlobalStoragePythonWrapper( JobQueue::instance()->globalStorage() );
|
= CalamaresPython::GlobalStoragePythonWrapper( JobQueue::instance()->globalStorage() );
|
||||||
|
|
||||||
|
cDebug() << "Job file" << scriptFI.absoluteFilePath();
|
||||||
bp::object execResult
|
bp::object execResult
|
||||||
= bp::exec_file( scriptFI.absoluteFilePath().toLocal8Bit().data(), scriptNamespace, scriptNamespace );
|
= bp::exec_file( scriptFI.absoluteFilePath().toLocal8Bit().data(), scriptNamespace, scriptNamespace );
|
||||||
|
|
||||||
bp::object entryPoint = scriptNamespace[ "run" ];
|
bp::object entryPoint = scriptNamespace[ "run" ];
|
||||||
bp::object prettyNameFunc = scriptNamespace.get( "pretty_name", bp::object() );
|
|
||||||
|
|
||||||
cDebug() << "Job file" << scriptFI.absoluteFilePath();
|
|
||||||
if ( !prettyNameFunc.is_none() )
|
|
||||||
{
|
|
||||||
bp::extract< std::string > prettyNameResult( prettyNameFunc() );
|
|
||||||
if ( prettyNameResult.check() )
|
|
||||||
{
|
|
||||||
m_description = QString::fromStdString( prettyNameResult() ).trimmed();
|
|
||||||
}
|
|
||||||
if ( !m_description.isEmpty() )
|
|
||||||
{
|
|
||||||
cDebug() << "Job description from pretty_name" << prettyName() << "=" << m_description;
|
|
||||||
emit progress( 0 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
m_description = pythonStringMethod( scriptNamespace, "pretty_name" );
|
||||||
if ( m_description.isEmpty() )
|
if ( m_description.isEmpty() )
|
||||||
{
|
{
|
||||||
bp::extract< std::string > entryPoint_doc_attr( entryPoint.attr( "__doc__" ) );
|
bp::extract< std::string > entryPoint_doc_attr( entryPoint.attr( "__doc__" ) );
|
||||||
@ -281,10 +278,14 @@ PythonJob::exec()
|
|||||||
{
|
{
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cDebug() << "Job description from pretty_name" << prettyName() << '=' << m_description;
|
||||||
|
}
|
||||||
|
emit progress( 0 );
|
||||||
|
|
||||||
bp::object runResult = entryPoint();
|
bp::object runResult = entryPoint();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user