diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index af660fec2..f4838ae46 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -21,6 +21,12 @@ list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_UI ) +if( WITH_PYTHON ) + list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_SOURCES + modulesystem/PythonJobModule.cpp + ) +endif() + calamares_add_library( ${CALAMARESUI_LIBRARY_TARGET} SOURCES ${${CALAMARESUI_LIBRARY_TARGET}_SOURCES} UI ${${CALAMARESUI_LIBRARY_TARGET}_UI} diff --git a/src/libcalamaresui/modulesystem/Module.cpp b/src/libcalamaresui/modulesystem/Module.cpp index 324a26203..f564b45f1 100644 --- a/src/libcalamaresui/modulesystem/Module.cpp +++ b/src/libcalamaresui/modulesystem/Module.cpp @@ -22,6 +22,11 @@ #include "ViewModule.h" #include "utils/YamlUtils.h" #include "utils/Logger.h" +#include "CalamaresConfig.h" + +#ifdef WITH_PYTHON +#include "PythonJobModule.h" +#endif #include @@ -106,10 +111,12 @@ Module::fromConfigFile( const QString& path ) { m = new ProcessJobModule(); } +#ifdef WITH_PYTHON else if ( intfString == "python" ) { - m = nullptr; //TODO: add Python module here + m = new PythonJobModule(); } +#endif } if ( !m ) diff --git a/src/libcalamaresui/modulesystem/PythonJobModule.cpp b/src/libcalamaresui/modulesystem/PythonJobModule.cpp new file mode 100644 index 000000000..2e01e6a51 --- /dev/null +++ b/src/libcalamaresui/modulesystem/PythonJobModule.cpp @@ -0,0 +1,82 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "PythonJobModule.h" + +#include "JobQueue.h" +#include "PythonJob.h" + +#include + +#include + + +namespace Calamares { + + +Module::Type +PythonJobModule::type() const +{ + return Job; +} + + +Module::Interface +PythonJobModule::interface() const +{ + return Python; +} + + +void +PythonJobModule::loadSelf() +{ + if ( m_loaded ) + return; + + Calamares::job_ptr j = Calamares::job_ptr( new PythonJob( m_scriptFileName, + m_workingPath ) ); + JobQueue::instance()->enqueue( j ); + m_loaded = true; +} + + +void +PythonJobModule::initFrom( const YAML::Node& node ) +{ + Module::initFrom( node ); + QDir directory( location() ); + m_workingPath = directory.absolutePath(); + + if ( node[ "script" ] ) + { + m_scriptFileName = QString::fromStdString( node[ "script" ].as< std::string >() ); + } +} + + +PythonJobModule::PythonJobModule() + : Module() +{} + + +PythonJobModule::~PythonJobModule() +{} + + +} // namespace Calamares diff --git a/src/libcalamaresui/modulesystem/PythonJobModule.h b/src/libcalamaresui/modulesystem/PythonJobModule.h new file mode 100644 index 000000000..95b318929 --- /dev/null +++ b/src/libcalamaresui/modulesystem/PythonJobModule.h @@ -0,0 +1,50 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef CALAMARES_PYTHONJOBMODULE_H +#define CALAMARES_PYTHONJOBMODULE_H + +#include "Module.h" + +#include "UiDllMacro.h" + +namespace Calamares { + +class UIDLLEXPORT PythonJobModule : public Module +{ +public: + Type type() const override; + Interface interface() const override; + + void loadSelf() override; + +protected: + void initFrom( const YAML::Node &node ) override; + +private: + friend class Module; + explicit PythonJobModule(); + virtual ~PythonJobModule(); + + QString m_scriptFileName; + QString m_workingPath; +}; + +} // namespace Calamares + +#endif // CALAMARES_PYTHONJOBMODULE_H