[libcalamares] API for YAML-loading from Python

This commit is contained in:
Adriaan de Groot 2021-11-29 12:46:12 +01:00
parent 7f643010b2
commit fcbe8d3a3e
3 changed files with 23 additions and 1 deletions

View File

@ -79,6 +79,7 @@ BOOST_PYTHON_MODULE( libcalamares )
bp::scope utilsScope = utilsModule; bp::scope utilsScope = utilsModule;
Q_UNUSED( utilsScope ) Q_UNUSED( utilsScope )
// .. Logging functions
bp::def( bp::def(
"debug", &CalamaresPython::debug, bp::args( "s" ), "Writes the given string to the Calamares debug stream." ); "debug", &CalamaresPython::debug, bp::args( "s" ), "Writes the given string to the Calamares debug stream." );
bp::def( "warning", bp::def( "warning",
@ -92,6 +93,11 @@ BOOST_PYTHON_MODULE( libcalamares )
bp::def( bp::def(
"error", &CalamaresPython::warning, bp::args( "s" ), "Writes the given string to the Calamares error stream." ); "error", &CalamaresPython::warning, bp::args( "s" ), "Writes the given string to the Calamares error stream." );
// .. YAML functions
bp::def( "load_yaml", &CalamaresPython::load_yaml, bp::args( "path" ), "Loads YAML from a file." );
// .. Filesystem functions
bp::def( "mount", bp::def( "mount",
&CalamaresPython::mount, &CalamaresPython::mount,
mount_overloads( bp::args( "device_path", "mount_point", "filesystem_name", "options" ), mount_overloads( bp::args( "device_path", "mount_point", "filesystem_name", "options" ),
@ -100,6 +106,8 @@ BOOST_PYTHON_MODULE( libcalamares )
"-1 = QProcess crash\n" "-1 = QProcess crash\n"
"-2 = QProcess cannot start\n" "-2 = QProcess cannot start\n"
"-3 = bad arguments" ) ); "-3 = bad arguments" ) );
// .. Process functions
bp::def( bp::def(
"target_env_call", "target_env_call",
static_cast< int ( * )( const std::string&, const std::string&, int ) >( &CalamaresPython::target_env_call ), static_cast< int ( * )( const std::string&, const std::string&, int ) >( &CalamaresPython::target_env_call ),
@ -158,6 +166,7 @@ BOOST_PYTHON_MODULE( libcalamares )
host_env_process_output_overloads( bp::args( "command", "callback", "stdin", "timeout" ), host_env_process_output_overloads( bp::args( "command", "callback", "stdin", "timeout" ),
"Runs the specified command in the host system." ) ); "Runs the specified command in the host system." ) );
// .. String functions
bp::def( "obscure", bp::def( "obscure",
&CalamaresPython::obscure, &CalamaresPython::obscure,
bp::args( "s" ), bp::args( "s" ),
@ -166,7 +175,7 @@ BOOST_PYTHON_MODULE( libcalamares )
"Applying the function to a string obscured by this function will result " "Applying the function to a string obscured by this function will result "
"in the original string." ); "in the original string." );
// .. Translation functions
bp::def( "gettext_languages", bp::def( "gettext_languages",
&CalamaresPython::gettext_languages, &CalamaresPython::gettext_languages,
"Returns list of languages (most to least-specific) for gettext." ); "Returns list of languages (most to least-specific) for gettext." );

View File

@ -19,6 +19,7 @@
#include "utils/RAII.h" #include "utils/RAII.h"
#include "utils/Runner.h" #include "utils/Runner.h"
#include "utils/String.h" #include "utils/String.h"
#include "utils/Yaml.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QDir> #include <QDir>
@ -163,6 +164,13 @@ error( const std::string& s )
log_action( Logger::LOGERROR, s ); log_action( Logger::LOGERROR, s );
} }
boost::python::dict
load_yaml( const std::string& path )
{
return variantMapToPyDict( CalamaresUtils::loadYaml( QString::fromStdString( path ) ) );
}
PythonJobInterface::PythonJobInterface( Calamares::PythonJob* parent ) PythonJobInterface::PythonJobInterface( Calamares::PythonJob* parent )
: m_parent( parent ) : m_parent( parent )
{ {

View File

@ -62,6 +62,11 @@ void debug( const std::string& s );
void warning( const std::string& s ); void warning( const std::string& s );
void error( const std::string& s ); void error( const std::string& s );
/** @brief Loads YAML and returns (nested) dicts representing it
*
*/
boost::python::dict load_yaml( const std::string& path );
class PythonJobInterface class PythonJobInterface
{ {
public: public: