From f5aec1ad8a8e6f62dd87b602ee1c6541ede42a1c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Nov 2017 08:53:40 -0500 Subject: [PATCH] [libcalamares] Add output to CalledProcessError - Refactor, internal _handle_check_target_env_call_error doesn't need to be in header or visible. - Add optional output (of the command) to the Python exception. --- src/libcalamares/PythonJobApi.cpp | 35 ++++++++++++++++--------------- src/libcalamares/PythonJobApi.h | 2 -- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/libcalamares/PythonJobApi.cpp b/src/libcalamares/PythonJobApi.cpp index 595f53a76..c9a3873bd 100644 --- a/src/libcalamares/PythonJobApi.cpp +++ b/src/libcalamares/PythonJobApi.cpp @@ -36,6 +36,24 @@ namespace bp = boost::python; +static int +_handle_check_target_env_call_error( int ec, const QString& cmd, const QString& output = QString() ) +{ + if ( !ec ) + return ec; + + QString raise = QString( "import subprocess\n" + "e = subprocess.CalledProcessError(%1,\"%2\")\n" ) + .arg( ec ) + .arg( cmd ); + if ( !output.isEmpty() ) + raise.append( QStringLiteral("e.output = \"\"\"%1\"\"\"\n").arg( output ) ); + raise.append("raise e"); + bp::exec( raise.toStdString().c_str() ); + bp::throw_error_already_set(); + return ec; +} + namespace CalamaresPython { @@ -156,23 +174,6 @@ check_target_env_output( const bp::list& args, return output.toStdString(); } - -int -_handle_check_target_env_call_error( int ec, const QString& cmd ) -{ - if ( !ec ) - return ec; - - QString raise = QString( "import subprocess\n" - "raise subprocess.CalledProcessError(%1,\"%2\")" ) - .arg( ec ) - .arg( cmd ); - bp::exec( raise.toStdString().c_str() ); - bp::throw_error_already_set(); - return ec; -} - - void debug( const std::string& s ) { diff --git a/src/libcalamares/PythonJobApi.h b/src/libcalamares/PythonJobApi.h index 3d31c474e..c88101d28 100644 --- a/src/libcalamares/PythonJobApi.h +++ b/src/libcalamares/PythonJobApi.h @@ -67,8 +67,6 @@ boost::python::list gettext_languages(); void debug( const std::string& s ); -inline int _handle_check_target_env_call_error( int ec, const QString& cmd ); - class PythonJobInterface { public: