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
_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(),
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 );
void debug( const std::string& s );

View File

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

View File

@ -51,6 +51,16 @@ DLLEXPORT int chrootCall( const QStringList& args,
DLLEXPORT int chrootCall( const QString& command,
const QString& stdInput = QString(),
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