From f2142bc4b3d2c9fdf896b7c6a4315a9d6a53de95 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 3 Nov 2021 11:53:44 +0100 Subject: [PATCH] [libcalamares] Move Python callback to utils submodule - don't need the job to do the callback - allow callable objects from Python - doesn't actually run the process yet --- src/libcalamares/PythonJob.cpp | 16 +++++++--------- src/libcalamares/PythonJobApi.cpp | 5 +++-- src/libcalamares/PythonJobApi.h | 8 ++------ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index 56a616ea2..cba190287 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -36,10 +36,6 @@ 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 ) { @@ -61,11 +57,7 @@ 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." ) - .def( "target_env_output", - &CalamaresPython::PythonJobInterface::target_env_output, - target_env_output_overloads( bp::args( "args", "callback", "stdin", "timeout" ), "docstring")) - ; + "as a real number between 0 and 1." ); bp::class_< CalamaresPython::GlobalStoragePythonWrapper >( "GlobalStorage", bp::init< Calamares::GlobalStorage* >() ) @@ -146,6 +138,12 @@ BOOST_PYTHON_MODULE( libcalamares ) "Runs the specified command in the chroot of the target system.\n" "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 ), + bp::args( "command", "callback" ), + "Runs the specified command in the target system, and " + "calls the callback function with each line of output." ); + bp::def( "obscure", &CalamaresPython::obscure, bp::args( "s" ), diff --git a/src/libcalamares/PythonJobApi.cpp b/src/libcalamares/PythonJobApi.cpp index 16b6e523a..7fb8b2af1 100644 --- a/src/libcalamares/PythonJobApi.cpp +++ b/src/libcalamares/PythonJobApi.cpp @@ -172,9 +172,10 @@ PythonJobInterface::setprogress( qreal progress ) } int -PythonJobInterface::target_env_output( const boost::python::list& args, const std::string& callback, const std::string& stdin, int timeout ) +target_env_process_output( const boost::python::list& args, boost::python::object& callback ) { - cWarning() << "target env" << _bp_list_to_qstringlist(args) << "cb" << callback.c_str() << "stdin" << stdin.c_str() << "timeout" << timeout; + cWarning() << "target env" << _bp_list_to_qstringlist( args ); + callback( std::string( "derp" ) ); return 0; } diff --git a/src/libcalamares/PythonJobApi.h b/src/libcalamares/PythonJobApi.h index a1597ad98..c20dafe72 100644 --- a/src/libcalamares/PythonJobApi.h +++ b/src/libcalamares/PythonJobApi.h @@ -42,6 +42,8 @@ check_target_env_output( const std::string& command, const std::string& stdin = std::string check_target_env_output( const boost::python::list& args, const std::string& stdin = std::string(), int timeout = 0 ); +int target_env_process_output( const boost::python::list& args, boost::python::object& callback ); + std::string obscure( const std::string& string ); boost::python::object gettext_path(); @@ -63,12 +65,6 @@ 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;