[libcalamares] Introduce host_env_process_output, too
- run commands consistently, with optional output-processing, in host or target; - raises exception on error, like the check_* functions.
This commit is contained in:
parent
e5323ec487
commit
3120abbce8
@ -139,10 +139,15 @@ BOOST_PYTHON_MODULE( libcalamares )
|
||||
"Returns the program's standard output, and raises a "
|
||||
"subprocess.CalledProcessError if something went wrong." ) );
|
||||
bp::def( "target_env_process_output",
|
||||
static_cast< int ( * )( const bp::list&, bp::object& ) >( &CalamaresPython::target_env_process_output ),
|
||||
&CalamaresPython::target_env_process_output,
|
||||
bp::args( "command", "callback" ),
|
||||
"Runs the specified command in the target system, and "
|
||||
"calls the callback function with each line of output." );
|
||||
bp::def( "host_env_process_output",
|
||||
&CalamaresPython::host_env_process_output,
|
||||
bp::args( "command", "callback" ),
|
||||
"Runs the specified command in the host system, and "
|
||||
"calls the callback function with each line of output." );
|
||||
|
||||
bp::def( "obscure",
|
||||
&CalamaresPython::obscure,
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "utils/CalamaresUtilsSystem.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/RAII.h"
|
||||
#include "utils/Runner.h"
|
||||
#include "utils/String.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
@ -171,14 +172,45 @@ PythonJobInterface::setprogress( qreal progress )
|
||||
}
|
||||
}
|
||||
|
||||
static inline int
|
||||
_process_output( Calamares::Utils::RunLocation location,
|
||||
const boost::python::list& args,
|
||||
boost::python::object& callback )
|
||||
{
|
||||
Calamares::Utils::Runner r( _bp_list_to_qstringlist( args ) );
|
||||
r.setLocation( location );
|
||||
if ( !callback.is_none() )
|
||||
{
|
||||
r.enableOutputProcessing();
|
||||
QObject::connect(
|
||||
&r, &decltype( r )::output, [&callback]( const QString& s ) { callback( s.toStdString() ); } );
|
||||
}
|
||||
auto result = r.run();
|
||||
|
||||
if ( result.getExitCode() )
|
||||
{
|
||||
return _handle_check_target_env_call_error( result, r.executable() );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
target_env_process_output( const boost::python::list& args, boost::python::object& callback )
|
||||
{
|
||||
cWarning() << "target env" << _bp_list_to_qstringlist( args );
|
||||
callback( std::string( "derp" ) );
|
||||
return 0;
|
||||
return _process_output(
|
||||
|
||||
Calamares::Utils::RunLocation::RunInTarget, args, callback );
|
||||
}
|
||||
|
||||
int
|
||||
host_env_process_output( const boost::python::list& args, boost::python::object& callback )
|
||||
{
|
||||
return _process_output(
|
||||
|
||||
Calamares::Utils::RunLocation::RunInHost, args, callback );
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
obscure( const std::string& string )
|
||||
{
|
||||
|
@ -44,6 +44,8 @@ check_target_env_output( const boost::python::list& args, const std::string& std
|
||||
|
||||
int target_env_process_output( const boost::python::list& args, boost::python::object& callback );
|
||||
|
||||
int host_env_process_output( const boost::python::list& args, boost::python::object& callback );
|
||||
|
||||
std::string obscure( const std::string& string );
|
||||
|
||||
boost::python::object gettext_path();
|
||||
|
Loading…
Reference in New Issue
Block a user