Skip to content

Commit

Permalink
Start working on variable expander; move config section parsing there
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernd Wachter committed Mar 19, 2013
1 parent b28e7f8 commit a9249fe
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 31 deletions.
4 changes: 3 additions & 1 deletion libssu/libssu.pro
@@ -1,9 +1,11 @@
BUILD = ../build/libssu
HEADERS = ssu.h \
ssudeviceinfo.h \
ssuvariables.h \
../constants.h
SOURCES = ssu.cpp \
ssudeviceinfo.cpp
ssudeviceinfo.cpp \
ssuvariables.cpp
TEMPLATE = lib
TARGET = ssu
CONFIG += dll mobility link_pkgconfig
Expand Down
37 changes: 7 additions & 30 deletions libssu/ssu.cpp
Expand Up @@ -9,6 +9,7 @@

#include "ssu.h"
#include "../constants.h"
#include "ssuvariables.h"

Ssu::Ssu(QString fallbackLog): QObject(){
errorFlag = false;
Expand Down Expand Up @@ -241,17 +242,12 @@ QString Ssu::release(bool rnd){
QString Ssu::repoUrl(QString repoName, bool rndRepo, QHash<QString, QString> repoParameters){
QString r;
QStringList configSections;
QStringList repoVariables;
SsuVariables var;

errorFlag = false;

// fill in all arbitrary variables from ssu.ini
settings->beginGroup("repository-url-variables");
repoVariables = settings->allKeys();
foreach (const QString &key, repoVariables){
repoParameters.insert(key, settings->value(key).toString());
}
settings->endGroup();
var.resolveSection(settings, "repository-url-variables", &repoParameters);

// add/overwrite some of the variables with sane ones
if (rndRepo){
Expand All @@ -263,13 +259,7 @@ QString Ssu::repoUrl(QString repoName, bool rndRepo, QHash<QString, QString> rep

// Make it possible to give any values with the flavour as well.
// These values can be overridden later with domain if needed.
repoSettings->beginGroup(flavour()+"-flavour");
QStringList defKeys = repoSettings->allKeys();
foreach (const QString &key, defKeys){
repoParameters.insert(key, repoSettings->value(key).toString());
}
repoSettings->endGroup();

var.resolveSection(repoSettings, flavour()+"-flavour", &repoParameters);
} else {
repoParameters.insert("release", settings->value("release").toString());
configSections << "release" << "all";
Expand All @@ -287,23 +277,10 @@ QString Ssu::repoUrl(QString repoName, bool rndRepo, QHash<QString, QString> rep

// Domain variables
// first read all variables from default-domain
repoSettings->beginGroup("default-domain");
QStringList defKeys = repoSettings->allKeys();
foreach (const QString &key, defKeys){
repoParameters.insert(key, repoSettings->value(key).toString());
}
repoSettings->endGroup();
var.resolveSection(repoSettings, "default-domain", &repoParameters);

// then overwrite with domain specific things if that block is available
QString domainSection = domain() + "-domain";
QStringList sections = repoSettings->childGroups();
if (sections.contains(domainSection)){
repoSettings->beginGroup(domainSection);
QStringList domainKeys = repoSettings->allKeys();
foreach (const QString &key, domainKeys){
repoParameters.insert(key, repoSettings->value(key).toString());
}
repoSettings->endGroup();
}
var.resolveSection(repoSettings, domain()+"-domain", &repoParameters);

if (settings->contains("repository-urls/" + repoName))
r = settings->value("repository-urls/" + repoName).toString();
Expand Down
27 changes: 27 additions & 0 deletions libssu/ssuvariables.cpp
@@ -0,0 +1,27 @@
/**
* @file ssuvariables.cpp
* @copyright 2013 Jolla Ltd.
* @author Bernd Wachter <bwachter@lart.info>
* @date 2013
*/

#include <QStringList>

#include "ssuvariables.h"

// TODO: Add a simple variable parser to allow variable substitution; it should
// get called in the resolve sections
SsuVariables::SsuVariables(): QObject() {

}

void SsuVariables::resolveSection(QSettings *settings, QString section, QHash<QString, QString> *storageHash){
QStringList repoVariables;

settings->beginGroup(section);
repoVariables = settings->allKeys();
foreach (const QString &key, repoVariables){
storageHash->insert(key, settings->value(key).toString());
}
settings->endGroup();
}
28 changes: 28 additions & 0 deletions libssu/ssuvariables.h
@@ -0,0 +1,28 @@
/**
* @file ssuvariables.h
* @copyright 2013 Jolla Ltd.
* @author Bernd Wachter <bwachter@lart.info>
* @date 2013
*/

#ifndef _SSUVARIABLES_H
#define _SSUVARIABLES_H

#include <QObject>
#include <QSettings>
#include <QHash>

class SsuVariables: public QObject {
Q_OBJECT

public:
SsuVariables();
/**
* Look up all variables in the specified configuration file section,
* run them through the variable expander, and add them to the supplied
* QHash
*/
void resolveSection(QSettings *settings, QString section, QHash<QString, QString> *storageHash);
};

#endif

0 comments on commit a9249fe

Please sign in to comment.