Add check_chroot_call to libcalamares Python interface.
This commit is contained in:
parent
26e5500e33
commit
45ac91c784
@ -43,6 +43,12 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( chroot_call_str_overloads,
|
|||||||
BOOST_PYTHON_FUNCTION_OVERLOADS( chroot_call_list_overloads,
|
BOOST_PYTHON_FUNCTION_OVERLOADS( chroot_call_list_overloads,
|
||||||
CalamaresPython::chroot_call,
|
CalamaresPython::chroot_call,
|
||||||
1, 3 );
|
1, 3 );
|
||||||
|
BOOST_PYTHON_FUNCTION_OVERLOADS( check_chroot_call_str_overloads,
|
||||||
|
CalamaresPython::check_chroot_call,
|
||||||
|
1, 3 );
|
||||||
|
BOOST_PYTHON_FUNCTION_OVERLOADS( check_chroot_call_list_overloads,
|
||||||
|
CalamaresPython::check_chroot_call,
|
||||||
|
1, 3 );
|
||||||
BOOST_PYTHON_MODULE( libcalamares )
|
BOOST_PYTHON_MODULE( libcalamares )
|
||||||
{
|
{
|
||||||
bp::scope().attr( "ORGANIZATION_NAME" ) = CALAMARES_ORGANIZATION_NAME;
|
bp::scope().attr( "ORGANIZATION_NAME" ) = CALAMARES_ORGANIZATION_NAME;
|
||||||
@ -73,43 +79,84 @@ BOOST_PYTHON_MODULE( libcalamares )
|
|||||||
Q_UNUSED( utilsScope );
|
Q_UNUSED( utilsScope );
|
||||||
|
|
||||||
bp::def( "debug", &CalamaresPython::debug );
|
bp::def( "debug", &CalamaresPython::debug );
|
||||||
bp::def( "mount",
|
bp::def(
|
||||||
&CalamaresPython::mount,
|
"mount",
|
||||||
mount_overloads( bp::args( "device_path",
|
&CalamaresPython::mount,
|
||||||
"mount_point",
|
mount_overloads(
|
||||||
"filesystem_name",
|
bp::args( "device_path",
|
||||||
"options" ),
|
"mount_point",
|
||||||
"Runs the mount utility with the specified parameters.\n"
|
"filesystem_name",
|
||||||
"Returns the program's exit code, or:\n"
|
"options" ),
|
||||||
"-1 = QProcess crash\n"
|
"Runs the mount utility with the specified parameters.\n"
|
||||||
"-2 = QProcess cannot start\n"
|
"Returns the program's exit code, or:\n"
|
||||||
"-3 = bad arguments" ) );
|
"-1 = QProcess crash\n"
|
||||||
bp::def( "chroot_call",
|
"-2 = QProcess cannot start\n"
|
||||||
static_cast< int (*)( const std::string&,
|
"-3 = bad arguments"
|
||||||
const std::string&,
|
)
|
||||||
int ) >( &CalamaresPython::chroot_call ),
|
);
|
||||||
chroot_call_str_overloads( bp::args( "command",
|
bp::def(
|
||||||
"stdin",
|
"chroot_call",
|
||||||
"timeout" ),
|
static_cast< int (*)( const std::string&,
|
||||||
"Runs the specified command in the chroot of the target system.\n"
|
const std::string&,
|
||||||
"Returns the program's exit code, or:\n"
|
int ) >( &CalamaresPython::chroot_call ),
|
||||||
"-1 = QProcess crash\n"
|
chroot_call_str_overloads(
|
||||||
"-2 = QProcess cannot start\n"
|
bp::args( "command",
|
||||||
"-3 = bad arguments\n"
|
"stdin",
|
||||||
"-4 = QProcess timeout" ) );
|
"timeout" ),
|
||||||
bp::def( "chroot_call",
|
"Runs the specified command in the chroot of the target system.\n"
|
||||||
static_cast< int (*)( const bp::list&,
|
"Returns the program's exit code, or:\n"
|
||||||
const std::string&,
|
"-1 = QProcess crash\n"
|
||||||
int ) >( &CalamaresPython::chroot_call ),
|
"-2 = QProcess cannot start\n"
|
||||||
chroot_call_list_overloads( bp::args( "args",
|
"-3 = bad arguments\n"
|
||||||
"stdin",
|
"-4 = QProcess timeout"
|
||||||
"timeout" ),
|
)
|
||||||
"Runs the specified command in the chroot of the target system.\n"
|
);
|
||||||
"Returns the program's exit code, or:\n"
|
bp::def(
|
||||||
"-1 = QProcess crash\n"
|
"chroot_call",
|
||||||
"-2 = QProcess cannot start\n"
|
static_cast< int (*)( const bp::list&,
|
||||||
"-3 = bad arguments\n"
|
const std::string&,
|
||||||
"-4 = QProcess timeout" ) );
|
int ) >( &CalamaresPython::chroot_call ),
|
||||||
|
chroot_call_list_overloads(
|
||||||
|
bp::args( "args",
|
||||||
|
"stdin",
|
||||||
|
"timeout" ),
|
||||||
|
"Runs the specified command in the chroot of the target system.\n"
|
||||||
|
"Returns the program's exit code, or:\n"
|
||||||
|
"-1 = QProcess crash\n"
|
||||||
|
"-2 = QProcess cannot start\n"
|
||||||
|
"-3 = bad arguments\n"
|
||||||
|
"-4 = QProcess timeout"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
bp::def(
|
||||||
|
"check_chroot_call",
|
||||||
|
static_cast< int (*)( const std::string&,
|
||||||
|
const std::string&,
|
||||||
|
int ) >( &CalamaresPython::check_chroot_call ),
|
||||||
|
check_chroot_call_str_overloads(
|
||||||
|
bp::args( "command",
|
||||||
|
"stdin",
|
||||||
|
"timeout" ),
|
||||||
|
"Runs the specified command in the chroot of the target system.\n"
|
||||||
|
"Returns 0, which is program's exit code if the program exited "
|
||||||
|
"successfully, or raises a subprocess.CalledProcessError."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
bp::def(
|
||||||
|
"check_chroot_call",
|
||||||
|
static_cast< int (*)( const bp::list&,
|
||||||
|
const std::string&,
|
||||||
|
int ) >( &CalamaresPython::check_chroot_call ),
|
||||||
|
check_chroot_call_list_overloads(
|
||||||
|
bp::args( "args",
|
||||||
|
"stdin",
|
||||||
|
"timeout" ),
|
||||||
|
"Runs the specified command in the chroot of the target system.\n"
|
||||||
|
"Returns 0, which is program's exit code if the program exited "
|
||||||
|
"successfully, or raises a subprocess.CalledProcessError."
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -185,7 +232,6 @@ PythonJob::exec()
|
|||||||
|
|
||||||
bp::object runResult = entryPoint();
|
bp::object runResult = entryPoint();
|
||||||
|
|
||||||
//QString message = QString::fromStdString( bp::extract< std::string >( entryPoint() ) );
|
|
||||||
if ( runResult.is_none() )
|
if ( runResult.is_none() )
|
||||||
{
|
{
|
||||||
return JobResult::ok();
|
return JobResult::ok();
|
||||||
|
@ -25,8 +25,9 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
#undef slots
|
#undef slots
|
||||||
#include <boost/python/extract.hpp>
|
#include <boost/python.hpp>
|
||||||
|
|
||||||
|
namespace bp = boost::python;
|
||||||
|
|
||||||
namespace CalamaresPython
|
namespace CalamaresPython
|
||||||
{
|
{
|
||||||
@ -56,15 +57,15 @@ chroot_call( const std::string& command,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
chroot_call( const boost::python::list& args,
|
chroot_call( const bp::list& args,
|
||||||
const std::string& stdin,
|
const std::string& stdin,
|
||||||
int timeout )
|
int timeout )
|
||||||
{
|
{
|
||||||
QStringList list;
|
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(
|
list.append( QString::fromStdString(
|
||||||
boost::python::extract< std::string >( args[ i ] ) ) );
|
bp::extract< std::string >( args[ i ] ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return CalamaresUtils::chrootCall( list,
|
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
|
void
|
||||||
debug( const std::string& s )
|
debug( const std::string& s )
|
||||||
{
|
{
|
||||||
@ -97,5 +144,4 @@ PythonJobInterface::setprogress( qreal progress )
|
|||||||
m_parent->emitProgress( progress );
|
m_parent->emitProgress( progress );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,16 @@ int chroot_call( const boost::python::list& args,
|
|||||||
const std::string& stdin = std::string(),
|
const std::string& stdin = std::string(),
|
||||||
int timeout = 0 );
|
int timeout = 0 );
|
||||||
|
|
||||||
|
int check_chroot_call( const std::string& command,
|
||||||
|
const std::string& stdin = std::string(),
|
||||||
|
int timeout = 0 );
|
||||||
|
|
||||||
|
int check_chroot_call( const boost::python::list& args,
|
||||||
|
const std::string& stdin = std::string(),
|
||||||
|
int timeout = 0 );
|
||||||
|
|
||||||
|
inline int _handle_check_chroot_call_error( int ec, const QString& cmd );
|
||||||
|
|
||||||
void debug( const std::string& s );
|
void debug( const std::string& s );
|
||||||
|
|
||||||
class PythonJobInterface
|
class PythonJobInterface
|
||||||
|
@ -60,8 +60,11 @@ int chrootCall( const QStringList& args,
|
|||||||
const QString& stdInput,
|
const QString& stdInput,
|
||||||
int timeoutSec )
|
int timeoutSec )
|
||||||
{
|
{
|
||||||
|
if ( !Calamares::JobQueue::instance() )
|
||||||
|
return -3;
|
||||||
|
|
||||||
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||||
if ( !gs->contains( "rootMountPoint" ) )
|
if ( !gs || !gs->contains( "rootMountPoint" ) )
|
||||||
{
|
{
|
||||||
cLog() << "No rootMountPoint in global storage";
|
cLog() << "No rootMountPoint in global storage";
|
||||||
return -3;
|
return -3;
|
||||||
|
Loading…
Reference in New Issue
Block a user