Commit 3725bec3 authored by Aard's avatar Aard

[ssu] Add basic feature manager

parent aede9a2b
......@@ -22,6 +22,7 @@ SOURCES = \
ssucoreconfig.cpp \
ssudeviceinfo.cpp \
ssulog.cpp \
ssufeaturemanager.cpp \
ssuvariables.cpp \
ssurepomanager.cpp \
ssusettings.cpp
......
/**
* @file ssufeaturemanager.cpp
* @copyright 2013 Jolla Ltd.
* @author Bernd Wachter <bwachter@lart.info>
* @date 2013
*/
#include <QStringList>
#include <QRegExp>
#include <QDirIterator>
#include "ssudeviceinfo.h"
#include "ssufeaturemanager.h"
#include "ssucoreconfig.h"
#include "ssulog.h"
#include "ssuvariables.h"
#include "ssu.h"
#include "../constants.h"
#ifndef SSU_FEATURE_CONFIGURATION
/// Path to the main SSU configuration file
#define SSU_FEATURE_CONFIGURATION "/usr/share/ssu/features.ini"
#endif
#ifndef SSU_FEATURE_CONFIGURATION_DIR
/// Path to the main SSU configuration file
#define SSU_FEATURE_CONFIGURATION_DIR "/usr/share/ssu/features.d"
#endif
SsuFeatureManager::SsuFeatureManager(): QObject() {
featureSettings = new SsuSettings(SSU_FEATURE_CONFIGURATION, SSU_FEATURE_CONFIGURATION_DIR);
}
// @TODO - allow enabling/disabling features
// - export feature file for mic through ssu-ks
// - add feature header in ssu-ks
//
// all features have a list of repositories in the repos key
// if there are enabled/disabled features, check the repos keys from all enabled features
// and only enable the repositories from those
QStringList SsuFeatureManager::repos(bool rndRepo, int filter){
QStringList r;
QStringList keys;
SsuCoreConfig *settings = SsuCoreConfig::instance();
// @TODO features currently can't be blacklisted, but just ignoring user filter
// is still the best way atm
if (filter == Ssu::UserFilter)
return r;
QString repoHeader = QString("repositories-%1/")
.arg(rndRepo ? "rnd" : "release");
// take the global groups
featureSettings->beginGroup("repositories");
r.append(featureSettings->allKeys());
featureSettings->endGroup();
// and override with rnd/release specific groups
featureSettings->beginGroup(repoHeader);
r.append(featureSettings->allKeys());
featureSettings->endGroup();
r.removeDuplicates();
return r;
}
QString SsuFeatureManager::url(QString repo, bool rndRepo){
QString repoHeader = QString("repositories-%1/")
.arg(rndRepo ? "rnd" : "release");
if (featureSettings->contains(repoHeader + repo))
return featureSettings->value(repoHeader + repo).toString();
else if (featureSettings->contains("repositorios/" + repo))
return featureSettings->value("repositories/" + repo).toString();
return "";
}
......@@ -12,16 +12,16 @@
#include <QHash>
#include <QStringList>
#include "ssu.h"
#include "ssusettings.h"
class SsuFeatureManager: public QObject {
Q_OBJECT
public:
SsuFeatureManager(){};
// add rnd-flag?
QStringList repos(){};
QString url(QString repo){ return ""; };
SsuFeatureManager();
QStringList repos(bool rndRepo, int filter=Ssu::NoFilter);
QString url(QString repo, bool rndRepo);
private:
SsuSettings *featureSettings;
......
......@@ -118,6 +118,9 @@ QStringList SsuRepoManager::repos(bool rnd, SsuDeviceInfo &deviceInfo, int filte
QStringList result;
result = deviceInfo.repos(rnd, filter);
SsuFeatureManager featureManager;
result.append(featureManager.repos(rnd, filter));
result.sort();
result.removeDuplicates();
......@@ -149,12 +152,12 @@ void SsuRepoManager::update(){
rndMode = true;
// get list of device-specific repositories...
QStringList repos = deviceInfo.repos(rndMode);
QStringList repositoryList = repos(rndMode);
// strict mode enabled -> delete all repositories not prefixed by ssu
// assume configuration error if there are no device repos, and don't delete
// anything, even in strict mode
if ((deviceMode & Ssu::LenientMode) != Ssu::LenientMode && !repos.isEmpty()){
if ((deviceMode & Ssu::LenientMode) != Ssu::LenientMode && !repositoryList.isEmpty()){
QDirIterator it(Sandbox::map(ZYPP_REPO_PATH), QDir::AllEntries|QDir::NoDot|QDir::NoDotDot);
while (it.hasNext()){
it.next();
......@@ -174,7 +177,7 @@ void SsuRepoManager::update(){
QStringList parts = it.fileName().split("_");
// repo file structure is ssu_<reponame>_<rnd|release>.repo -> splits to 3 parts
if (parts.count() == 3){
if (!repos.contains(parts.at(1)) ||
if (!repositoryList.contains(parts.at(1)) ||
parts.at(2) != (rndMode ? "rnd.repo" : "release.repo" ))
QFile(it.filePath()).remove();
} else
......@@ -182,7 +185,7 @@ void SsuRepoManager::update(){
}
// ... and create all repositories required for this device
foreach (const QString &repo, repos){
foreach (const QString &repo, repositoryList){
// repo should be used where a unique identifier for silly human brains, or
// zypper is required. repoName contains the shortened form for ssu use
QString repoName = repo;
......@@ -326,8 +329,8 @@ QString SsuRepoManager::url(QString repoName, bool rndRepo,
if (settings->contains("repository-urls/" + repoName))
r = settings->value("repository-urls/" + repoName).toString();
else if (featureManager.url(repoName) != "")
r = featureManager.url(repoName);
else if (featureManager.url(repoName, rndRepo) != "")
r = featureManager.url(repoName, rndRepo);
else {
foreach (const QString &section, configSections){
repoSettings.beginGroup(section);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment