Commit fc2841c5 authored by Aard's avatar Aard

Make use of filename template if no filename is given

parent 4623e986
......@@ -60,7 +60,8 @@ QString SsuDeviceInfo::adaptationVariables(const QString &adaptationName, QHash<
storageHash->insert("adaptation", adaptationRepo);
ssuLog->print(LOG_DEBUG, "Found first adaptation " + adaptationName);
QHash<QString, QString> h = variableSection(adaptationRepo);
QHash<QString, QString> h;
variableSection(adaptationRepo, &h);
QHash<QString, QString>::const_iterator i = h.constBegin();
while (i != h.constEnd()){
......@@ -263,26 +264,23 @@ QStringList SsuDeviceInfo::repos(bool rnd, int filter){
return result;
}
QHash<QString, QString> SsuDeviceInfo::variableSection(QString section){
QHash<QString, QString> result;
void SsuDeviceInfo::variableSection(QString section, QHash<QString, QString> *storageHash){
if (!section.startsWith("var-"))
section = "var-" + section;
if (boardMappings->contains(section + "/variables")){
return variableSection(boardMappings->value(section + "/variables").toString());
variableSection(boardMappings->value(section + "/variables").toString(), storageHash);
return;
}
boardMappings->beginGroup(section);
if (boardMappings->group() != section)
return result;
return;
QStringList keys = boardMappings->allKeys();
foreach (const QString &key, keys){
result.insert(key, boardMappings->value(key).toString());
storageHash->insert(key, boardMappings->value(key).toString());
}
return result;
}
void SsuDeviceInfo::setDeviceModel(QString model){
......
......@@ -76,7 +76,8 @@ class SsuDeviceInfo: public QObject {
* Return the requested variable section. 'var-' is automatically
* prepended to the section name if not specified already.
*/
QHash<QString, QString> variableSection(QString section);
void variableSection(QString section, QHash<QString, QString> *storageHash);
/**
* Return a value from an adaptation section. Returns an empty string
* or a given default value if key does not exist.
......
......@@ -10,18 +10,14 @@
#include <QDirIterator>
#include "ssukickstarter.h"
#include "libssu/ssurepomanager.h"
#include "libssu/ssuvariables.h"
#include "../constants.h"
/* TODO:
* - rnd/release handling.
* repo --name=adaptation0-@RNDRELEASE@
* --baseurl=https://releases.jollamobile.com/nemo/@RELEASE@-devel/adaptation-n9xx-common/@ARCH@/
* @RELEASE@ should be @RNDRELEASE@ in this case as well
* - commands from the command section should be verified
* - go through the variable lookup process for non-url variables as well
* - allow overriding brand key
* - use (and expand) filename key if no filename is given on command line
*/
......@@ -39,7 +35,9 @@ QStringList SsuKickstarter::commands(){
SsuDeviceInfo deviceInfo(deviceModel);
QStringList result;
QHash<QString, QString> h = deviceInfo.variableSection("kickstart-commands");
QHash<QString, QString> h;
deviceInfo.variableSection("kickstart-commands", &h);
// read commands from variable, ...
......@@ -168,27 +166,32 @@ void SsuKickstarter::setRepoParameters(QHash<QString, QString> parameters){
if (repoOverride.contains("model"))
deviceModel = repoOverride.value("model");
/*
else
repoOverride.insert("model", deviceInfo.deviceModel());
*/
}
void SsuKickstarter::write(QString kickstart){
bool SsuKickstarter::write(QString kickstart){
QFile ks;
QTextStream kout;
SsuDeviceInfo deviceInfo;
QTextStream qerr(stderr);
SsuDeviceInfo deviceInfo(deviceModel);
SsuRepoManager repoManager;
SsuVariables var;
if (kickstart.isEmpty())
ks.open(stdout, QIODevice::WriteOnly);
else {
ks.setFileName(kickstart);
ks.open(QIODevice::WriteOnly);
// rnd mode should not come from the defaults
if (repoOverride.contains("rnd")){
if (repoOverride.value("rnd") == "true")
rndMode = true;
else if (repoOverride.value("rnd") == "false")
rndMode = false;
}
kout.setDevice(&ks);
QHash<QString, QString> defaults;
// get generic repo variables; domain and adaptation specific bits are not interesting
// in the kickstart
repoManager.repoVariables(&defaults, rndMode);
// overwrite with kickstart defaults
deviceInfo.variableSection("kickstart-defaults", &defaults);
QHash<QString, QString> defaults = deviceInfo.variableSection("kickstart-defaults");
QHash<QString, QString>::const_iterator it = defaults.constBegin();
while (it != defaults.constEnd()){
if (!repoOverride.contains(it.key()))
......@@ -196,18 +199,37 @@ void SsuKickstarter::write(QString kickstart){
it++;
}
if (repoOverride.contains("rnd")){
if (repoOverride.value("rnd") == "true")
rndMode = true;
else if (repoOverride.value("rnd") == "false")
rndMode = false;
}
// in rnd mode both rndRelease an release should be the same,
// as the variable name used is %(release)
if (rndMode && repoOverride.contains("rndRelease"))
repoOverride.insert("release", repoOverride.value("rndRelease"));
// release mode variables should not contain flavourName
if (!rndMode && repoOverride.contains("flavourName"))
repoOverride.remove("flavourName");
//TODO: check for mandatory keys, brand, ..
if (!repoOverride.contains("deviceModel"))
repoOverride.insert("deviceModel", deviceInfo.deviceModel());
if (kickstart.isEmpty()){
if (repoOverride.contains("filename")){
ks.setFileName(var.resolveString(repoOverride.value("filename"),
&repoOverride));
ks.open(QIODevice::WriteOnly);
} else {
qerr << "No filename specified, and no default filename configured" << endl;
return false;
}
} else if (kickstart == "-")
ks.open(stdout, QIODevice::WriteOnly);
else {
ks.setFileName(kickstart);
ks.open(QIODevice::WriteOnly);
}
kout.setDevice(&ks);
kout << commands().join("\n") << endl << endl;
kout << partitions().join("\n") << endl << endl;
kout << repos().join("\n") << endl << endl;
......@@ -217,4 +239,6 @@ void SsuKickstarter::write(QString kickstart){
kout << scriptletSection("post", false).join("\n") << endl << endl;
// add flags as bitmask?
// POST, die-on-error
return true;
}
......@@ -23,7 +23,7 @@ class SsuKickstarter {
public:
SsuKickstarter();
void setRepoParameters(QHash<QString, QString> parameters);
void write(QString kickstart="");
bool write(QString kickstart="");
private:
QHash<QString, QString> repoOverride;
......
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