mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-24 10:55:46 -05:00
[libcalamares] Python API for callbacks from processes
This is an experiment in Python API that will allow a callback function in the Python module to be called for each output line. It builds on the run-a-process extensions that are being built simultaneously.
This commit is contained in:
parent
2de09d4001
commit
e0fdde06c9
3 changed files with 23 additions and 1 deletions
|
@ -36,6 +36,11 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_output_list_overloads,
|
|||
CalamaresPython::check_target_env_output,
|
||||
1,
|
||||
3 );
|
||||
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( target_env_output_overloads,
|
||||
target_env_output,
|
||||
2,
|
||||
4 );
|
||||
|
||||
BOOST_PYTHON_MODULE( libcalamares )
|
||||
{
|
||||
bp::object package = bp::scope();
|
||||
|
@ -56,7 +61,11 @@ BOOST_PYTHON_MODULE( libcalamares )
|
|||
&CalamaresPython::PythonJobInterface::setprogress,
|
||||
bp::args( "progress" ),
|
||||
"Reports the progress status of this job to Calamares, "
|
||||
"as a real number between 0 and 1." );
|
||||
"as a real number between 0 and 1." )
|
||||
.def( "target_env_output",
|
||||
&CalamaresPython::PythonJobInterface::target_env_output,
|
||||
target_env_output_overloads( bp::args( "args", "callback", "stdin", "timeout" ), "docstring"))
|
||||
;
|
||||
|
||||
bp::class_< CalamaresPython::GlobalStoragePythonWrapper >( "GlobalStorage",
|
||||
bp::init< Calamares::GlobalStorage* >() )
|
||||
|
|
|
@ -171,6 +171,13 @@ PythonJobInterface::setprogress( qreal progress )
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
PythonJobInterface::target_env_output( const boost::python::list& args, const std::string& callback, const std::string& stdin, int timeout )
|
||||
{
|
||||
cWarning() << "target env" << _bp_list_to_qstringlist(args) << "cb" << callback.c_str() << "stdin" << stdin.c_str() << "timeout" << timeout;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string
|
||||
obscure( const std::string& string )
|
||||
{
|
||||
|
|
|
@ -63,6 +63,12 @@ public:
|
|||
boost::python::dict configuration;
|
||||
|
||||
void setprogress( qreal progress );
|
||||
/** @brief Run the command @p args and process lines of output
|
||||
*
|
||||
* Calls the function @p callback from the job module on each
|
||||
* line of output. Returns the exit code of the command.
|
||||
*/
|
||||
int target_env_output( const boost::python::list& args, const std::string& callback, const std::string& stdin = std::string(), int timeout = 10 );
|
||||
|
||||
private:
|
||||
Calamares::PythonJob* m_parent;
|
||||
|
|
Loading…
Add table
Reference in a new issue