mirror of
https://github.com/parchlinux/calamares.git
synced 2025-07-01 19:35:36 -04:00
Add check_chroot_call to libcalamares Python interface.
This commit is contained in:
parent
26e5500e33
commit
45ac91c784
4 changed files with 149 additions and 44 deletions
|
@ -25,8 +25,9 @@
|
|||
#include <QDir>
|
||||
|
||||
#undef slots
|
||||
#include <boost/python/extract.hpp>
|
||||
#include <boost/python.hpp>
|
||||
|
||||
namespace bp = boost::python;
|
||||
|
||||
namespace CalamaresPython
|
||||
{
|
||||
|
@ -56,15 +57,15 @@ chroot_call( const std::string& command,
|
|||
|
||||
|
||||
int
|
||||
chroot_call( const boost::python::list& args,
|
||||
chroot_call( const bp::list& args,
|
||||
const std::string& stdin,
|
||||
int timeout )
|
||||
{
|
||||
QStringList list;
|
||||
for ( int i = 0; i < boost::python::len( args ); ++i )
|
||||
for ( int i = 0; i < bp::len( args ); ++i )
|
||||
{
|
||||
list.append( QString::fromStdString(
|
||||
boost::python::extract< std::string >( args[ i ] ) ) );
|
||||
bp::extract< std::string >( args[ i ] ) ) );
|
||||
}
|
||||
|
||||
return CalamaresUtils::chrootCall( list,
|
||||
|
@ -73,6 +74,52 @@ chroot_call( const boost::python::list& args,
|
|||
}
|
||||
|
||||
|
||||
int
|
||||
check_chroot_call( const std::string& command,
|
||||
const std::string& stdin,
|
||||
int timeout )
|
||||
{
|
||||
int ec = chroot_call( command, stdin, timeout );
|
||||
return _handle_check_chroot_call_error( ec, QString::fromStdString( command ) );
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
check_chroot_call( const bp::list& args,
|
||||
const std::string& stdin,
|
||||
int timeout )
|
||||
{
|
||||
int ec = chroot_call( args, stdin, timeout );
|
||||
if ( !ec )
|
||||
return ec;
|
||||
|
||||
QStringList failedCmdList;
|
||||
for ( int i = 0; i < bp::len( args ); ++i )
|
||||
{
|
||||
failedCmdList.append( QString::fromStdString(
|
||||
bp::extract< std::string >( args[ i ] ) ) );
|
||||
}
|
||||
|
||||
return _handle_check_chroot_call_error( ec, failedCmdList.join( ' ' ) );
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_handle_check_chroot_call_error( int ec, const QString& cmd )
|
||||
{
|
||||
if ( !ec )
|
||||
return ec;
|
||||
|
||||
QString raise = QString( "import subprocess\n"
|
||||
"raise subprocess.CalledProcessError(%1,\"%2\")" )
|
||||
.arg( ec )
|
||||
.arg( cmd );
|
||||
bp::exec( raise.toStdString().c_str() );
|
||||
bp::throw_error_already_set();
|
||||
return ec;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
debug( const std::string& s )
|
||||
{
|
||||
|
@ -97,5 +144,4 @@ PythonJobInterface::setprogress( qreal progress )
|
|||
m_parent->emitProgress( progress );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue