Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Start using adaptation-repos stringlist for adaptations, allow freefo…
…rm variables for adaptations
  • Loading branch information
Bernd Wachter committed Mar 27, 2013
1 parent f5f4f69 commit 9879903
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 20 deletions.
38 changes: 28 additions & 10 deletions board-mappings.ini
Expand Up @@ -24,14 +24,32 @@
# The found model (after resolving variants) will be used as category. The
# following keys are valid there:
# - family -- the device family, used for the family specific adaptation
# - adaptations -- list of additional adaptations, shared between families
# - adaptation-repos -- list of adaptation repositories for this family
#
# The value of adaptations gets converted into a QStringList, which uses
# commas as separator. If one of the adaptation names contains a comma it
# needs to be quoted:
# adaptation=foo
# adaptation="foo, bar", baz
# adaptation=foo, bar, baz
# The value of adaptation-repos gets converted into a QStringList, which
# uses commas as separator. If one of the adaptation names contains a comma
# it needs to be quoted:
# adaptation-repos=foo
# adaptation-repos="foo, bar", baz
# adaptation-repos=foo, bar, baz
#
# The adaptation list is used to create repo files for adaptation repos.
# A repository named 'adaptation0' operates on the first list element,
# 'adaptation2' on the 3rd, etc. The matching item in the list will be
# exported as adaptation variable.
#
# Freeform variable sections start with 'var-'. A variable section for an
# adaptation named 'n9xx' would be 'var-n9xx'. A variable section may
# contain freeform variables, or the keyword 'variables' to include any
# other section. Currently only one section may be included, and you may
# not specify additional variables:
#
# [var-n9]
# foo=bar
# bar=baz
#
# [var-n950]
# variables=n9
#
# The N9x mappings should be solved through sysinfo, but that's currently
# broken on Mer/Nemo
Expand All @@ -54,17 +72,17 @@ N950=N9

[N9]
family=n950-n9
adaptations=n9xx
adaptation-repos=n9xx-common,n950-n9

[N900]
family=n900
adaptations=n9xx
adaptation-repos=n9xx-common,n900

[SDK]

[generic-x86]
family=x86
adaptations=x86
adaptation-repos=x86

[UNKNOWN]
family=UNKNOWN
43 changes: 41 additions & 2 deletions libssu/ssu.cpp
Expand Up @@ -153,6 +153,7 @@ QString Ssu::repoUrl(QString repoName, bool rndRepo, QHash<QString, QString> rep
QString r;
QStringList configSections;
SsuVariables var;
SsuLog *ssuLog = SsuLog::instance();

errorFlag = false;

Expand Down Expand Up @@ -181,19 +182,57 @@ QString Ssu::repoUrl(QString repoName, bool rndRepo, QHash<QString, QString> rep
if (!repoParameters.contains("arch"))
repoParameters.insert("arch", settings->value("arch").toString());

repoParameters.insert("adaptation", settings->value("adaptation").toString());
// todo: allow override of deviceModel for cli url resolving
QStringList adaptationRepos = deviceInfo.adaptationRepos();

// read adaptation from settings, in case it can't be determined from
// board mappings. this is obsolete, and will be dropped soon
if (settings->contains("adaptation"))
repoParameters.insert("adaptation", settings->value("adaptation").toString());

repoParameters.insert("deviceFamily", deviceInfo.deviceFamily());
repoParameters.insert("deviceModel", deviceInfo.deviceModel());

// Those keys have now been obsoleted by generic variables, support for
// it will be removed soon
QStringList keys;
keys << "chip" << "adaptation" << "vendor";

foreach(QString key, keys){
QString value;
if (deviceInfo.getValue(key,value))
repoParameters.insert(key, value);
}

// special handling for adaptation-repositories
// - check if repo is in right format (adaptation\d*)
// - check if the configuration has that many adaptation repos
// - export the entry in the adaptation list as %(adaptation)
// - look up variables for that adaptation, and export matching
// adaptation variable
QRegExp regex("adaptation\\\d*", Qt::CaseSensitive, QRegExp::RegExp2);
if (regex.exactMatch(repoName)){
regex.setPattern("\\\d*");
regex.lastIndexIn(repoName);
int n = regex.cap().toInt();

if (adaptationRepos.size() > n) {
QString adaptationRepo = adaptationRepos.at(n);
repoParameters.insert("adaptation", adaptationRepo);
ssuLog->print(LOG_DEBUG, "Found first adaptation " + repoName);

QHash<QString, QString> h = deviceInfo.variableSection(adaptationRepo);

QHash<QString, QString>::const_iterator i = h.constBegin();
while (i != h.constEnd()){
repoParameters.insert(i.key(), i.value());
i++;
}
} else
ssuLog->print(LOG_INFO, "Note: adaptation repo for invalid repo requested " + repoName);

repoName = "adaptation";
}

// Domain variables
// first read all variables from default-domain
var.resolveSection(repoSettings, "default-domain", &repoParameters);
Expand Down
56 changes: 49 additions & 7 deletions libssu/ssudeviceinfo.cpp
Expand Up @@ -20,18 +20,28 @@ SsuDeviceInfo::SsuDeviceInfo(): QObject(){
boardMappings = new SsuSettings(SSU_BOARD_MAPPING_CONFIGURATION, SSU_BOARD_MAPPING_CONFIGURATION_DIR);
}

QString SsuDeviceInfo::deviceFamily(){
QString model = deviceModel();
QStringList SsuDeviceInfo::adaptationRepos(){
QStringList result;

QString model = deviceVariant();
if (model == "")
model = deviceModel();

if (boardMappings->contains(model + "/adaptation-repos"))
result = boardMappings->value(model + "/adaptation-repos").toStringList();

return result;
}

QString SsuDeviceInfo::deviceFamily(){
if (!cachedFamily.isEmpty())
return cachedFamily;

cachedFamily = "UNKNOWN";
QString model = deviceVariant();
if (model == "")
model = deviceModel();

if (boardMappings->contains("variants/" + model)) {
model = boardMappings->value("variants/" + model).toString();
cachedVariant = model;
}
cachedFamily = "UNKNOWN";

if (boardMappings->contains(model + "/family"))
cachedFamily = boardMappings->value(model + "/family").toString();
Expand Down Expand Up @@ -143,6 +153,28 @@ QString SsuDeviceInfo::deviceUid(){
return IMEI;
}

QHash<QString, QString> SsuDeviceInfo::variableSection(QString section){
QHash<QString, QString> result;

if (!section.startsWith("var-"))
section = "var-" + section;

if (boardMappings->contains(section + "/variables")){
return variableSection(boardMappings->value(section + "/variables").toString());
}

boardMappings->beginGroup(section);
if (boardMappings->group() != section)
return result;

QStringList keys = boardMappings->allKeys();
foreach (const QString &key, keys){
result.insert(key, boardMappings->value(key).toString());
}

return result;
}

bool SsuDeviceInfo::getValue(const QString& key, QString& value){
if (boardMappings->contains(deviceVariant()+"/"+key)){
value = boardMappings->value(deviceVariant()+"/"+key).toString();
Expand All @@ -154,3 +186,13 @@ bool SsuDeviceInfo::getValue(const QString& key, QString& value){
}
return false;
}

void SsuDeviceInfo::setDeviceModel(QString model){
if (model == "")
cachedModel = "";
else
cachedModel = model;

cachedFamily = "";
cachedVariant = "";
}
16 changes: 16 additions & 0 deletions libssu/ssudeviceinfo.h
Expand Up @@ -18,6 +18,10 @@ class SsuDeviceInfo: public QObject {

public:
SsuDeviceInfo();
/**
* Return the list of adaptations used for the set model
*/
QStringList adaptationRepos();
/**
* Try to find the device family for the system this is running on
*/
Expand All @@ -35,7 +39,19 @@ class SsuDeviceInfo: public QObject {
* @return QSystemDeviceInfo::imei(), if available, or QSystemDeviceInfo::uniqueDeviceID()
*/
Q_INVOKABLE QString deviceUid();
/**
* Override device model autodetection
*/
Q_INVOKABLE void setDeviceModel(QString model="");
/**
* Return the requested variable section. 'var-' is automatically
* prepended to the section name if not specified already.
*/
QHash<QString, QString> variableSection(QString section);

/**
* Get a key from an adaptation section. Deprecated, don't use.
*/
bool getValue(const QString& key, QString& value);

private:
Expand Down
3 changes: 3 additions & 0 deletions rpm/ssu.changes
@@ -1,3 +1,6 @@
* Wed Mar 27 2013 Bernd Wachter <bernd.wachter@jollamobile.com> - 0.26
- Take all adaptations from adaptation-repos list, allow freeform variables for adaptations

* Fri Mar 22 2013 Bernd Wachter <bernd.wachter@jollamobile.com> - 0.25
- Add variable substitution

Expand Down
2 changes: 1 addition & 1 deletion rpm/ssu.spec
@@ -1,5 +1,5 @@
Name: ssu
Version: 0.25
Version: 0.26
Release: 1
Summary: SSU enabler for RND
Group: System/Base
Expand Down

0 comments on commit 9879903

Please sign in to comment.