Skip to content

Commit

Permalink
Move adaptation specific variable resolving into DeviceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernd Wachter committed Apr 1, 2013
1 parent c87815a commit 56fb038
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 38 deletions.
55 changes: 54 additions & 1 deletion libssu/ssudeviceinfo.cpp
Expand Up @@ -11,14 +11,17 @@

#include "ssudeviceinfo.h"
#include "ssucoreconfig.h"
#include "ssulog.h"

#include "../constants.h"

QTM_USE_NAMESPACE

SsuDeviceInfo::SsuDeviceInfo(): QObject(){
SsuDeviceInfo::SsuDeviceInfo(QString model): QObject(){

boardMappings = new SsuSettings(SSU_BOARD_MAPPING_CONFIGURATION, SSU_BOARD_MAPPING_CONFIGURATION_DIR);
if (!model.isEmpty())
cachedModel = model;
}

QStringList SsuDeviceInfo::adaptationRepos(){
Expand All @@ -32,6 +35,46 @@ QStringList SsuDeviceInfo::adaptationRepos(){
return result;
}

QString SsuDeviceInfo::adaptationVariables(const QString &adaptationName, QHash<QString, QString> *storageHash){
SsuLog *ssuLog = SsuLog::instance();
QStringList adaptationRepoList = adaptationRepos();
// 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(adaptationName)){
regex.setPattern("\\\d*");
regex.lastIndexIn(adaptationName);
int n = regex.cap().toInt();

if (!adaptationRepoList.isEmpty()){
if (adaptationRepoList.size() <= n) {
ssuLog->print(LOG_INFO, "Note: repo index out of bounds, substituting 0" + adaptationName);
n = 0;
}

QString adaptationRepo = adaptationRepoList.at(n);
storageHash->insert("adaptation", adaptationRepo);
ssuLog->print(LOG_DEBUG, "Found first adaptation " + adaptationName);

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

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

return "adaptation";
}
return adaptationName;
}

QString SsuDeviceInfo::deviceFamily(){
if (!cachedFamily.isEmpty())
return cachedFamily;
Expand Down Expand Up @@ -263,3 +306,13 @@ void SsuDeviceInfo::setDeviceModel(QString model){
cachedFamily = "";
cachedVariant = "";
}

QVariant SsuDeviceInfo::value(const QString &key, const QVariant &value){
if (boardMappings->contains(deviceVariant()+"/"+key)){
return boardMappings->value(deviceVariant()+"/"+key);
} else if (boardMappings->contains(deviceModel()+"/"+key)){
return boardMappings->value(deviceModel()+"/"+key);
}

return value;
}
15 changes: 14 additions & 1 deletion libssu/ssudeviceinfo.h
Expand Up @@ -24,11 +24,19 @@ class SsuDeviceInfo: public QObject {
BoardFilterUserBlacklist
};

SsuDeviceInfo();
/**
* Initialize with device to override autodetection
*/
SsuDeviceInfo(QString model="");
/**
* Return the list of adaptations used for the set model
*/
QStringList adaptationRepos();
/**
* Resolve adaptation-specific variables for adaptationName, and store them in storageHash
* Returns "adaptation" if a valid adaptation was found, adaptationName otherwise
*/
QString adaptationVariables(const QString &adaptationName, QHash<QString, QString> *storageHash);
/**
* Try to find the device family for the system this is running on
*/
Expand Down Expand Up @@ -69,6 +77,11 @@ class SsuDeviceInfo: public QObject {
* prepended to the section name if not specified already.
*/
QHash<QString, QString> variableSection(QString section);
/**
* Return a value from an adaptation section. Returns an empty string
* or a given default value if key does not exist.
*/
QVariant value(const QString &key, const QVariant &value=QVariant());

/**
* Get a key from an adaptation section. Deprecated, don't use.
Expand Down
37 changes: 1 addition & 36 deletions libssu/ssurepomanager.cpp
Expand Up @@ -220,8 +220,6 @@ QString SsuRepoManager::url(QString repoName, bool rndRepo,
if (parametersOverride.contains("model"))
deviceInfo.setDeviceModel(parametersOverride.value("model"));

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"))
Expand All @@ -240,40 +238,7 @@ QString SsuRepoManager::url(QString repoName, bool rndRepo,
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.isEmpty()){
if (adaptationRepos.size() <= n) {
ssuLog->print(LOG_INFO, "Note: repo index out of bounds, substituting 0" + repoName);
n = 0;
}

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";
}
repoName = deviceInfo.adaptationVariables(repoName, &repoParameters);

// Domain variables
// first read all variables from default-domain
Expand Down

0 comments on commit 56fb038

Please sign in to comment.