Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[ssu] Implement variable setting through ssu CLI
  • Loading branch information
Bernd Wachter committed Jan 4, 2015
1 parent ed8a08f commit f40daa9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libssu/ssurepomanager.cpp
Expand Up @@ -307,9 +307,15 @@ QStringList SsuRepoManager::repoVariables(QHash<QString, QString> *storageHash,
QStringList configSections;
SsuSettings repoSettings(SSU_REPO_CONFIGURATION, QSettings::IniFormat);

// fill in all arbitrary variables from ssu.ini
// fill in all arbitrary repo specific variables from ssu.ini
var.variableSection(settings, "repository-url-variables", storageHash);

// fill in all global variables from ssu.ini
// TODO: should be handled somewhere in core variable logic once variables
// are more widely used outside of repository urls, for now this is
// just for easier migration to "full" variable usage at a later point.
var.variableSection(settings, "global-variables", storageHash);

// add/overwrite some of the variables with sane ones
if (rnd){
storageHash->insert("flavour",
Expand Down
47 changes: 47 additions & 0 deletions ssucli/ssucli.cpp
Expand Up @@ -13,6 +13,7 @@
#include "libssu/ssudeviceinfo.h"
#include "libssu/ssurepomanager.h"
#include "libssu/ssucoreconfig.h"
#include "libssu/ssuvariables.h"

#include <QDebug>

Expand Down Expand Up @@ -470,6 +471,47 @@ void SsuCli::optRepos(QStringList opt){
state = Idle;
}

void SsuCli::optSet(QStringList opt){
QTextStream qout(stdout);
SsuVariables var;
SsuCoreConfig *settings = SsuCoreConfig::instance();
QHash<QString, QString> storageHash;

// set repository specific variable
if (opt.count() == 5 && opt.at(2) == "-r"){
settings->setValue("repository-url-variables/" + opt.at(3), opt.at(4));
// clear repo specific variable
} else if (opt.count() == 4 && opt.at(2) == "-r"){
settings->remove("repository-url-variables/" + opt.at(3));
// list repo specific variables
} else if (opt.count() == 3 && opt.at(2) == "-r"){
qout << "Repository specific variables:" << endl << endl;
var.variableSection(settings, "repository-url-variables", &storageHash);
// set global variable
} else if (opt.count() == 4){
settings->setValue("global-variables/" + opt.at(2), opt.at(3));
// clear global variable
} else if (opt.count() == 3){
settings->remove("global-variables/" + opt.at(2));
// list global variables
} else if (opt.count() == 2){
qout << "Global variables:" << endl << endl;
var.variableSection(settings, "global-variables", &storageHash);
}

settings->sync();

if (!storageHash.isEmpty()){
QHash<QString, QString>::const_iterator i = storageHash.constBegin();
while (i != storageHash.constEnd()){
qout << i.key() << "=" << i.value() << endl;
i++;
}
}

state = Idle;
}

void SsuCli::optStatus(QStringList opt){
QTextStream qout(stdout);
QTextStream qerr(stderr);
Expand Down Expand Up @@ -579,6 +621,7 @@ void SsuCli::run(){
"release", "re", 0, -1, &SsuCli::optRelease,
"update", "up", 0, -1, &SsuCli::optUpdateCredentials,
"domain", "do", 0, -1, &SsuCli::optDomain,
"set", "set", 0, -1, &SsuCli::optSet,
};

bool found = false;
Expand Down Expand Up @@ -651,6 +694,10 @@ void SsuCli::usage(QString message){
<< "\trelease, re \tdisplay release used" << endl
<< "\t [-r] \tuse RnD release" << endl
<< "\t [newrelease] \tset new (RnD)release" << endl
<< "\tset \tdisplay global variables" << endl
<< "\t [-r] \toperate on repository only variables" << endl
<< "\t <variable> \tdisplay value of <variable>" << endl
<< "\t <variable> <value> \tset value of <variable> to <value>" << endl
<< endl
<< "Device management:" << endl
<< "\tstatus, s \tprint registration status and device information" << endl
Expand Down
1 change: 1 addition & 0 deletions ssucli/ssucli.h
Expand Up @@ -40,6 +40,7 @@ class SsuCli: public QObject {
void optRegister(QStringList opt);
void optRelease(QStringList opt);
void optRepos(QStringList opt);
void optSet(QStringList opt);
void optStatus(QStringList opt);
void optUpdateCredentials(QStringList opt);
void optUpdateRepos(QStringList opt);
Expand Down

0 comments on commit f40daa9

Please sign in to comment.