Add chrootOutput/check_chroot_output to libcalamares utils API.

This commit is contained in:
Teo Mrnjavac 2014-08-08 14:12:53 +02:00
parent 648befb9bb
commit f90bf469dd
4 changed files with 103 additions and 15 deletions

View File

@ -104,6 +104,43 @@ check_chroot_call( const bp::list& args,
} }
std::string
check_chroot_output( const std::string& command,
const std::string& stdin,
int timeout )
{
QString output;
int ec = CalamaresUtils::chrootOutput( QString::fromStdString( command ),
output,
QString::fromStdString( stdin ),
timeout );
_handle_check_chroot_call_error( ec, QString::fromStdString( command ) );
return output.toStdString();
}
std::string
check_chroot_output( const bp::list& args,
const std::string& stdin,
int timeout )
{
QString output;
QStringList list;
for ( int i = 0; i < bp::len( args ); ++i )
{
list.append( QString::fromStdString(
bp::extract< std::string >( args[ i ] ) ) );
}
int ec = CalamaresUtils::chrootOutput( list,
output,
QString::fromStdString( stdin ),
timeout );
_handle_check_chroot_call_error( ec, list.join( ' ' ) );
return output.toStdString();
}
int int
_handle_check_chroot_call_error( int ec, const QString& cmd ) _handle_check_chroot_call_error( int ec, const QString& cmd )
{ {

View File

@ -50,6 +50,15 @@ int check_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 );
std::string check_chroot_output( const std::string& command,
const std::string& stdin = std::string(),
int timeout = 0 );
std::string check_chroot_output( 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 ); inline int _handle_check_chroot_call_error( int ec, const QString& cmd );
void debug( const std::string& s ); void debug( const std::string& s );

View File

@ -28,10 +28,11 @@
namespace CalamaresUtils namespace CalamaresUtils
{ {
int mount( const QString& devicePath, int
const QString& mountPoint, mount( const QString& devicePath,
const QString& filesystemName, const QString& mountPoint,
const QString& options ) const QString& filesystemName,
const QString& options )
{ {
if ( devicePath.isEmpty() || mountPoint.isEmpty() ) if ( devicePath.isEmpty() || mountPoint.isEmpty() )
return -3; return -3;
@ -56,10 +57,38 @@ int mount( const QString& devicePath,
return QProcess::execute( program, args ); return QProcess::execute( program, args );
} }
int chrootCall( const QStringList& args, int
const QString& stdInput, chrootCall( const QStringList& args,
int timeoutSec ) const QString& stdInput,
int timeoutSec )
{ {
QString discard;
return chrootOutput( args,
discard,
stdInput,
timeoutSec );
}
int
chrootCall( const QString& command,
const QString& stdInput,
int timeoutSec )
{
return chrootCall( QStringList() = { command },
stdInput,
timeoutSec );
}
int
chrootOutput( const QStringList& args,
QString& output,
const QString& stdInput,
int timeoutSec )
{
output.clear();
if ( !Calamares::JobQueue::instance() ) if ( !Calamares::JobQueue::instance() )
return -3; return -3;
@ -107,8 +136,7 @@ int chrootCall( const QStringList& args,
return -4; return -4;
} }
cLog() << "Output:"; output.append( QString::fromLocal8Bit( process.readAllStandardOutput() ).trimmed() );
cLog() << process.readAllStandardOutput();
if ( process.exitStatus() == QProcess::CrashExit ) if ( process.exitStatus() == QProcess::CrashExit )
{ {
@ -121,14 +149,18 @@ int chrootCall( const QStringList& args,
} }
int chrootCall( const QString& command, int
const QString& stdInput, chrootOutput( const QString& command,
int timeoutSec ) QString& output,
const QString& stdInput,
int timeoutSec )
{ {
return chrootCall( QStringList() = { command }, return chrootOutput( QStringList() = { command },
stdInput, output,
timeoutSec ); stdInput,
timeoutSec );
} }
} }

View File

@ -51,6 +51,16 @@ DLLEXPORT int chrootCall( const QStringList& args,
DLLEXPORT int chrootCall( const QString& command, DLLEXPORT int chrootCall( const QString& command,
const QString& stdInput = QString(), const QString& stdInput = QString(),
int timeoutSec = 0 ); int timeoutSec = 0 );
DLLEXPORT int chrootOutput( const QStringList& args,
QString& output,
const QString& stdInput = QString(),
int timeoutSec = 0 );
DLLEXPORT int chrootOutput( const QString& command,
QString& output,
const QString& stdInput = QString(),
int timeoutSec = 0 );
} }
#endif // CALAMARESUTILSSYSTEM_H #endif // CALAMARESUTILSSYSTEM_H