Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[ssu] Add basic feature manager
  • Loading branch information
Bernd Wachter committed Nov 17, 2013
1 parent aede9a2 commit 3725bec
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 10 deletions.
1 change: 1 addition & 0 deletions libssu/libssu.pro
Expand Up @@ -22,6 +22,7 @@ SOURCES = \
ssucoreconfig.cpp \
ssudeviceinfo.cpp \
ssulog.cpp \
ssufeaturemanager.cpp \
ssuvariables.cpp \
ssurepomanager.cpp \
ssusettings.cpp
Expand Down
80 changes: 80 additions & 0 deletions libssu/ssufeaturemanager.cpp
@@ -0,0 +1,80 @@
/**
* @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 "";
}
8 changes: 4 additions & 4 deletions libssu/ssufeaturemanager.h
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions libssu/ssurepomanager.cpp
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand All @@ -174,15 +177,15 @@ 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
QFile(it.filePath()).remove();
}

// ... 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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3725bec

Please sign in to comment.