2014-06-18 18:05:04 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Module.h"
|
|
|
|
|
2014-07-14 14:29:24 +02:00
|
|
|
#include "ProcessJobModule.h"
|
2014-06-27 13:58:53 +02:00
|
|
|
#include "ViewModule.h"
|
2014-07-03 18:00:40 +02:00
|
|
|
#include "utils/YamlUtils.h"
|
2014-06-18 18:05:04 +02:00
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
|
|
|
#include <yaml-cpp/yaml.h>
|
|
|
|
|
2014-06-27 13:58:53 +02:00
|
|
|
#include <QDir>
|
2014-06-18 18:05:04 +02:00
|
|
|
#include <QFile>
|
2014-06-27 13:58:53 +02:00
|
|
|
#include <QFileInfo>
|
2014-06-18 18:05:04 +02:00
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
|
|
|
|
// Example module.conf
|
|
|
|
/*
|
|
|
|
---
|
|
|
|
type: "core" #core or view
|
|
|
|
name: "foo" #the module name. must be unique and same as the parent directory
|
|
|
|
interface: "qtplugin" #can be: qtplugin, python, process, ...
|
|
|
|
requires: [] #list of module names that must also be loaded. only applies to
|
|
|
|
#binary plugins! these are actual link-time dependencies, not
|
|
|
|
#conceptual dependencies for the setup procedure
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2014-06-27 13:58:53 +02:00
|
|
|
operator>>( const YAML::Node& node, Calamares::Module* m )
|
2014-06-18 18:05:04 +02:00
|
|
|
{
|
2014-06-27 13:58:53 +02:00
|
|
|
m->m_name = QString::fromStdString( node[ "name" ].as< std::string >() );
|
2014-06-18 18:05:04 +02:00
|
|
|
|
|
|
|
if ( node[ "requires" ] && node[ "requires" ].IsSequence() )
|
|
|
|
{
|
2014-06-27 13:58:53 +02:00
|
|
|
node[ "requires" ] >> m->m_requiredModules;
|
2014-06-18 18:05:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-27 13:58:53 +02:00
|
|
|
namespace Calamares
|
|
|
|
{
|
|
|
|
|
|
|
|
Module::~Module()
|
|
|
|
{}
|
2014-06-18 18:05:04 +02:00
|
|
|
|
2014-06-27 13:58:53 +02:00
|
|
|
Module*
|
|
|
|
Module::fromConfigFile( const QString& path )
|
2014-06-18 18:05:04 +02:00
|
|
|
{
|
2014-06-27 13:58:53 +02:00
|
|
|
Module* m = nullptr;
|
2014-06-18 18:05:04 +02:00
|
|
|
QFile metadataFile( path );
|
|
|
|
if ( metadataFile.exists() && metadataFile.open( QFile::ReadOnly | QFile::Text ) )
|
|
|
|
{
|
|
|
|
QByteArray ba = metadataFile.readAll();
|
|
|
|
cDebug() << Q_FUNC_INFO << "module metadata file: " << ba;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2014-07-14 14:29:24 +02:00
|
|
|
YAML::Node doc = YAML::Load( ba.constData() );
|
|
|
|
if ( !doc.IsMap() )
|
2014-06-18 18:05:04 +02:00
|
|
|
{
|
|
|
|
cDebug() << Q_FUNC_INFO << "bad module metadata format"
|
|
|
|
<< path;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-14 14:29:24 +02:00
|
|
|
if ( !doc[ "type" ] ||
|
|
|
|
!doc[ "interface" ] )
|
|
|
|
{
|
|
|
|
cDebug() << Q_FUNC_INFO << "bad module metadata format"
|
|
|
|
<< path;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString typeString = QString::fromStdString( doc[ "type" ].as< std::string >() );
|
|
|
|
QString intfString = QString::fromStdString( doc[ "interface" ].as< std::string >() );
|
|
|
|
|
|
|
|
if ( typeString == "view" && intfString == "qtplugin" )
|
|
|
|
{
|
|
|
|
m = new ViewModule();
|
|
|
|
}
|
|
|
|
else if ( typeString == "job" )
|
|
|
|
{
|
|
|
|
if ( intfString == "process" )
|
|
|
|
{
|
|
|
|
m = new ProcessJobModule();
|
|
|
|
}
|
|
|
|
else if ( intfString == "python" )
|
|
|
|
{
|
|
|
|
m = nullptr; //TODO: add Python module here
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !m )
|
|
|
|
{
|
|
|
|
cDebug() << Q_FUNC_INFO << "bad module type or interface string"
|
|
|
|
<< path << typeString << intfString;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-27 13:58:53 +02:00
|
|
|
|
|
|
|
QFileInfo mfi( path );
|
|
|
|
m->m_directory = mfi.absoluteDir().absolutePath();
|
|
|
|
|
2014-07-14 14:29:24 +02:00
|
|
|
m->initFrom( doc );
|
2014-06-18 18:05:04 +02:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
catch ( YAML::Exception& e )
|
|
|
|
{
|
|
|
|
cDebug() << "WARNING: YAML parser error " << e.what();
|
2014-06-27 13:58:53 +02:00
|
|
|
delete m;
|
2014-06-18 18:05:04 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
2014-07-10 12:27:53 +02:00
|
|
|
Module::name() const
|
2014-06-18 18:05:04 +02:00
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
2014-06-23 16:10:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
QStringList
|
2014-07-10 12:27:53 +02:00
|
|
|
Module::requiredModules() const
|
2014-06-23 16:10:19 +02:00
|
|
|
{
|
|
|
|
return m_requiredModules;
|
|
|
|
}
|
2014-06-27 13:58:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
QString
|
2014-07-10 12:27:53 +02:00
|
|
|
Module::location() const
|
2014-06-27 13:58:53 +02:00
|
|
|
{
|
|
|
|
return m_directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2014-07-10 12:27:53 +02:00
|
|
|
Module::isLoaded() const
|
2014-06-27 13:58:53 +02:00
|
|
|
{
|
|
|
|
return m_loaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Module::Module()
|
|
|
|
: m_loaded( false )
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Module::initFrom( const YAML::Node& node )
|
|
|
|
{
|
|
|
|
node >> this;
|
|
|
|
}
|
|
|
|
|
|
|
|
} //ns
|