forked from len0rd/rockbox
rbutil: Rework server info data handling.
Don't create our own in-memory map with server data. Instead use the configuration file retrieved from the download server, and do the resolve / replacement on the fly. Simplifies things, and prepares for cleaner handling for different build types. Change-Id: Ifd027b21486e402fda3df9c2f7a30264651f733d
This commit is contained in:
parent
2b2a7b9ae3
commit
104ff3433a
4 changed files with 127 additions and 160 deletions
|
|
@ -21,184 +21,148 @@
|
||||||
#include "systeminfo.h"
|
#include "systeminfo.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
||||||
|
static QSettings* serverSettings = nullptr;
|
||||||
|
|
||||||
// server infos
|
// server infos
|
||||||
const static struct {
|
const static struct {
|
||||||
ServerInfo::ServerInfos info;
|
ServerInfo::ServerInfos info;
|
||||||
const char* name;
|
const char* name;
|
||||||
const char* def;
|
|
||||||
} ServerInfoList[] = {
|
} ServerInfoList[] = {
|
||||||
{ ServerInfo::CurReleaseVersion, ":platform:/releaseversion", "" },
|
{ ServerInfo::CurReleaseVersion, "release/:platform:" },
|
||||||
{ ServerInfo::CurReleaseUrl, ":platform:/releaseurl", "" },
|
{ ServerInfo::CurReleaseUrl, "release/:platform:" },
|
||||||
{ ServerInfo::RelCandidateVersion, ":platform:/rcversion", "" },
|
{ ServerInfo::RelCandidateVersion, "release-candidate/:platform:" },
|
||||||
{ ServerInfo::RelCandidateUrl, ":platform:/rcurl", "" },
|
{ ServerInfo::RelCandidateUrl, "release-candidate/:platform:" },
|
||||||
{ ServerInfo::CurStatus, ":platform:/status", "Unknown" },
|
{ ServerInfo::CurStatus, "status/:platform:" },
|
||||||
{ ServerInfo::ManualPdfUrl, ":platform:/manual_pdf", "" },
|
{ ServerInfo::ManualPdfUrl, "" },
|
||||||
{ ServerInfo::ManualHtmlUrl, ":platform:/manual_html", "" },
|
{ ServerInfo::ManualHtmlUrl, "" },
|
||||||
{ ServerInfo::ManualZipUrl, ":platform:/manual_zip", "" },
|
{ ServerInfo::ManualZipUrl, "" },
|
||||||
{ ServerInfo::BleedingRevision, "bleedingrev", "" },
|
{ ServerInfo::BleedingRevision, "bleeding/rev" },
|
||||||
{ ServerInfo::BleedingDate, "bleedingdate", "" },
|
{ ServerInfo::BleedingDate, "bleeding/timestamp" },
|
||||||
{ ServerInfo::CurDevelUrl, ":platform:/develurl", "" },
|
{ ServerInfo::CurDevelUrl, "" },
|
||||||
};
|
};
|
||||||
|
|
||||||
QMap<QString, QVariant> ServerInfo::serverInfos;
|
QMap<QString, QVariant> ServerInfo::serverInfos;
|
||||||
|
|
||||||
void ServerInfo::readBuildInfo(QString file)
|
void ServerInfo::readBuildInfo(QString file)
|
||||||
{
|
{
|
||||||
QString releaseBaseUrl = SystemInfo::value(SystemInfo::ReleaseUrl).toString();
|
if (serverSettings)
|
||||||
QString develBaseUrl = SystemInfo::value(SystemInfo::BleedingUrl).toString();
|
delete serverSettings;
|
||||||
QString manualBaseUrl = SystemInfo::value(SystemInfo::ManualUrl).toString();
|
serverSettings = new QSettings(file, QSettings::IniFormat);
|
||||||
|
|
||||||
QSettings info(file, QSettings::IniFormat);
|
|
||||||
|
|
||||||
QString developmentRevision = info.value("bleeding/rev").toString();
|
|
||||||
setPlatformValue(ServerInfo::BleedingRevision, "", developmentRevision);
|
|
||||||
QDateTime date = QDateTime::fromString(info.value("bleeding/timestamp").toString(), "yyyyMMddThhmmssZ");
|
|
||||||
setPlatformValue(ServerInfo::BleedingDate, "", date.toString(Qt::ISODate));
|
|
||||||
|
|
||||||
info.beginGroup("release");
|
|
||||||
QStringList releasekeys = info.allKeys();
|
|
||||||
info.endGroup();
|
|
||||||
info.beginGroup("release-candidate");
|
|
||||||
QStringList rckeys = info.allKeys();
|
|
||||||
info.endGroup();
|
|
||||||
|
|
||||||
// get base platforms, handle variants with platforms in the loop
|
|
||||||
QStringList platforms = SystemInfo::platforms(SystemInfo::PlatformBaseDisabled);
|
|
||||||
for(int i = 0; i < platforms.size(); i++)
|
|
||||||
{
|
|
||||||
// check if there are rbutil-variants of the current platform and handle
|
|
||||||
// them the same time.
|
|
||||||
QStringList variants;
|
|
||||||
variants = SystemInfo::platforms(SystemInfo::PlatformVariantDisabled, platforms.at(i));
|
|
||||||
QString releaseVersion;
|
|
||||||
QString releaseUrl;
|
|
||||||
QString relCandidateVersion;
|
|
||||||
QString relCandidateUrl;
|
|
||||||
// support two formats for "release" sections:
|
|
||||||
// - <target>=<version>. In this case the URL is constructed.
|
|
||||||
// - <target>=<version>,<url>.
|
|
||||||
info.beginGroup("release");
|
|
||||||
if(releasekeys.contains(platforms.at(i))) {
|
|
||||||
QStringList entry = info.value(platforms.at(i)).toStringList();
|
|
||||||
releaseVersion = entry.at(0);
|
|
||||||
if(entry.size() > 1) {
|
|
||||||
releaseUrl = entry.at(1);
|
|
||||||
}
|
|
||||||
else if(!releaseVersion.isEmpty()) {
|
|
||||||
// construct release download URL
|
|
||||||
releaseUrl = releaseBaseUrl;
|
|
||||||
releaseUrl.replace("%MODEL%", platforms.at(i));
|
|
||||||
releaseUrl.replace("%RELVERSION%", releaseVersion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
info.endGroup();
|
|
||||||
// "release-candidate" section currently only support the 2nd format.
|
|
||||||
info.beginGroup("release-candidate");
|
|
||||||
if(rckeys.contains(platforms.at(i))) {
|
|
||||||
QStringList entry = info.value(platforms.at(i)).toStringList();
|
|
||||||
if(entry.size() > 1) {
|
|
||||||
relCandidateVersion = entry.at(0);
|
|
||||||
relCandidateUrl = entry.at(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
info.endGroup();
|
|
||||||
|
|
||||||
// "bleeding" section (development) does not provide individual
|
|
||||||
// information but only a global revision value.
|
|
||||||
QString develUrl = develBaseUrl;
|
|
||||||
develUrl.replace("%MODEL%", platforms.at(i));
|
|
||||||
develUrl.replace("%RELVERSION%", developmentRevision);
|
|
||||||
|
|
||||||
info.beginGroup("status");
|
|
||||||
QString status = tr("Unknown");
|
|
||||||
switch(info.value(platforms.at(i), -1).toInt())
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
status = tr("Stable (Retired)");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
status = tr("Unusable");
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
status = tr("Unstable");
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
status = tr("Stable");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
info.endGroup();
|
|
||||||
|
|
||||||
// manual URLs
|
|
||||||
QString manualPdfUrl = manualBaseUrl;
|
|
||||||
QString manualHtmlUrl = manualBaseUrl;
|
|
||||||
QString manualZipUrl = manualBaseUrl;
|
|
||||||
|
|
||||||
QString buildservermodel = SystemInfo::platformValue(
|
|
||||||
SystemInfo::BuildserverModel, platforms.at(i)).toString();
|
|
||||||
QString modelman = SystemInfo::platformValue(
|
|
||||||
SystemInfo::Manual, platforms.at(i)).toString();
|
|
||||||
QString manualBaseName = "rockbox-";
|
|
||||||
|
|
||||||
if(modelman.isEmpty()) manualBaseName += buildservermodel;
|
|
||||||
else manualBaseName += modelman;
|
|
||||||
|
|
||||||
manualPdfUrl.replace("%EXTENSION%", "pdf");
|
|
||||||
manualPdfUrl.replace("%MANUALBASENAME%", manualBaseName);
|
|
||||||
manualHtmlUrl.replace("%EXTENSION%", "html");
|
|
||||||
manualHtmlUrl.replace("%MANUALBASENAME%", manualBaseName + "/rockbox-build");
|
|
||||||
manualZipUrl.replace("%EXTENSION%", "zip");
|
|
||||||
manualZipUrl.replace("%MANUALBASENAME%", manualBaseName + "-html");
|
|
||||||
|
|
||||||
// set variants (if any)
|
|
||||||
for(int j = 0; j < variants.size(); ++j) {
|
|
||||||
setPlatformValue(ServerInfo::CurStatus, variants.at(j), status);
|
|
||||||
if(!releaseUrl.isEmpty()) {
|
|
||||||
setPlatformValue(ServerInfo::CurReleaseVersion, variants.at(j), releaseVersion);
|
|
||||||
setPlatformValue(ServerInfo::CurReleaseUrl, variants.at(j), releaseUrl);
|
|
||||||
}
|
|
||||||
if(!relCandidateUrl.isEmpty()) {
|
|
||||||
setPlatformValue(ServerInfo::RelCandidateVersion, variants.at(j), relCandidateVersion);
|
|
||||||
setPlatformValue(ServerInfo::RelCandidateUrl, variants.at(j), relCandidateUrl);
|
|
||||||
}
|
|
||||||
setPlatformValue(ServerInfo::CurDevelUrl, variants.at(j), develUrl);
|
|
||||||
|
|
||||||
setPlatformValue(ServerInfo::ManualPdfUrl, variants.at(j), manualPdfUrl);
|
|
||||||
setPlatformValue(ServerInfo::ManualHtmlUrl, variants.at(j), manualHtmlUrl);
|
|
||||||
setPlatformValue(ServerInfo::ManualZipUrl, variants.at(j), manualZipUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ServerInfo::setPlatformValue(enum ServerInfos info, QString platform, QVariant value)
|
|
||||||
{
|
|
||||||
// locate setting item
|
|
||||||
int i = 0;
|
|
||||||
while(ServerInfoList[i].info != info)
|
|
||||||
i++;
|
|
||||||
|
|
||||||
QString s = ServerInfoList[i].name;
|
|
||||||
s.replace(":platform:", platform);
|
|
||||||
serverInfos.insert(s, value);
|
|
||||||
LOG_INFO() << "SET:" << s << serverInfos.value(s).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant ServerInfo::platformValue(enum ServerInfos info, QString platform)
|
QVariant ServerInfo::platformValue(enum ServerInfos info, QString platform)
|
||||||
{
|
{
|
||||||
// locate setting item
|
// locate setting item in server info file
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(ServerInfoList[i].info != info)
|
while(ServerInfoList[i].info != info)
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
|
// replace setting name
|
||||||
if(platform.isEmpty())
|
if(platform.isEmpty())
|
||||||
platform = RbSettings::value(RbSettings::CurrentPlatform).toString();
|
platform = RbSettings::value(RbSettings::CurrentPlatform).toString();
|
||||||
|
|
||||||
|
// split of variant for platform.
|
||||||
|
// we can have an optional variant part in the platform string.
|
||||||
|
// For build info we don't use that.
|
||||||
|
platform = platform.split('.').at(0);
|
||||||
|
|
||||||
QString s = ServerInfoList[i].name;
|
QString s = ServerInfoList[i].name;
|
||||||
s.replace(":platform:", platform);
|
s.replace(":platform:", platform);
|
||||||
QString d = ServerInfoList[i].def;
|
|
||||||
d.replace(":platform:", platform);
|
// get value
|
||||||
LOG_INFO() << "GET:" << s << serverInfos.value(s, d).toString();
|
QVariant value = QString();
|
||||||
return serverInfos.value(s, d);
|
if(!s.isEmpty() && serverSettings)
|
||||||
|
value = serverSettings->value(s, "");
|
||||||
|
|
||||||
|
// depending on the actual value we need more replacements.
|
||||||
|
switch(info) {
|
||||||
|
case ServerInfo::CurStatus:
|
||||||
|
value = ServerInfo::statusToString(value.toInt());
|
||||||
|
break;
|
||||||
|
case CurReleaseVersion:
|
||||||
|
value = value.toStringList().at(0);
|
||||||
|
break;
|
||||||
|
case RelCandidateVersion:
|
||||||
|
// currently only the <version>,<url> format is supported here.
|
||||||
|
if (value.toStringList().size() > 1)
|
||||||
|
value = value.toStringList().at(0);
|
||||||
|
else
|
||||||
|
value.clear();
|
||||||
|
break;
|
||||||
|
case CurReleaseUrl:
|
||||||
|
{
|
||||||
|
QString version = value.toStringList().at(0);
|
||||||
|
if(value.toStringList().size() > 1)
|
||||||
|
value = value.toStringList().at(1);
|
||||||
|
else if(!version.isEmpty()) // if value is empty, return empty url.
|
||||||
|
value = SystemInfo::value(SystemInfo::ReleaseUrl).toString()
|
||||||
|
.replace("%MODEL%", platform)
|
||||||
|
.replace("%RELVERSION%", version);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RelCandidateUrl:
|
||||||
|
if(value.toStringList().size() > 1)
|
||||||
|
value = value.toStringList().at(1);
|
||||||
|
else
|
||||||
|
value.clear();
|
||||||
|
break;
|
||||||
|
case CurDevelUrl:
|
||||||
|
value = SystemInfo::value(SystemInfo::BleedingUrl).toString()
|
||||||
|
.replace("%MODEL%", platform);
|
||||||
|
break;
|
||||||
|
case ManualPdfUrl:
|
||||||
|
case ManualZipUrl:
|
||||||
|
case ManualHtmlUrl:
|
||||||
|
{
|
||||||
|
QString url = SystemInfo::value(SystemInfo::ManualUrl).toString();
|
||||||
|
QString modelman = SystemInfo::platformValue(
|
||||||
|
SystemInfo::Manual, platform).toString();
|
||||||
|
url.replace("%MODEL%", modelman.isEmpty() ? platform : modelman);
|
||||||
|
if(info == ManualPdfUrl)
|
||||||
|
url.replace("%FORMAT%", ".pdf");
|
||||||
|
else if(info == ManualZipUrl)
|
||||||
|
url.replace("%FORMAT%", "-html.zip");
|
||||||
|
else if(info == ManualHtmlUrl)
|
||||||
|
url.replace("%FORMAT%", "/rockbox-build.html");
|
||||||
|
value = url;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BleedingDate:
|
||||||
|
// TODO: get rid of this, it's location specific.
|
||||||
|
value = QDateTime::fromString(value.toString(),
|
||||||
|
"yyyyMMddThhmmssZ").toString(Qt::ISODate);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFO() << "Server:" << value;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ServerInfo::statusToString(int status)
|
||||||
|
{
|
||||||
|
QString value;
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
case STATUS_RETIRED:
|
||||||
|
value = tr("Stable (Retired)");
|
||||||
|
break;
|
||||||
|
case STATUS_UNUSABLE:
|
||||||
|
value = tr("Unusable");
|
||||||
|
break;
|
||||||
|
case STATUS_UNSTABLE:
|
||||||
|
value = tr("Unstable");
|
||||||
|
break;
|
||||||
|
case STATUS_STABLE:
|
||||||
|
value = tr("Stable");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
value = tr("Unknown");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@
|
||||||
#define SERVERINFO_H
|
#define SERVERINFO_H
|
||||||
|
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
|
#define STATUS_RETIRED 0
|
||||||
|
#define STATUS_UNUSABLE 1
|
||||||
|
#define STATUS_UNSTABLE 2
|
||||||
|
#define STATUS_STABLE 3
|
||||||
|
|
||||||
class ServerInfo : public QObject
|
class ServerInfo : public QObject
|
||||||
{
|
{
|
||||||
|
|
@ -47,10 +51,10 @@ class ServerInfo : public QObject
|
||||||
static void readBuildInfo(QString file);
|
static void readBuildInfo(QString file);
|
||||||
//! get a value from server info for a named platform.
|
//! get a value from server info for a named platform.
|
||||||
static QVariant platformValue(enum ServerInfos setting, QString platform = "");
|
static QVariant platformValue(enum ServerInfos setting, QString platform = "");
|
||||||
|
//! Convert status number to string
|
||||||
|
static QString statusToString(int status);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! set a value for a server info for a named platform.
|
|
||||||
static void setPlatformValue(enum ServerInfos setting, QString platform, QVariant value);
|
|
||||||
//! you shouldnt call this, its a fully static class
|
//! you shouldnt call this, its a fully static class
|
||||||
ServerInfo() {}
|
ServerInfo() {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ release_font_url=http://download.rockbox.org/release/%RELEASEVER%/rockbox-fonts-
|
||||||
daily_font_url=http://download.rockbox.org/daily/fonts/rockbox-fonts.zip
|
daily_font_url=http://download.rockbox.org/daily/fonts/rockbox-fonts.zip
|
||||||
|
|
||||||
; other
|
; other
|
||||||
manual_url=http://download.rockbox.org/manual/%MANUALBASENAME%.%EXTENSION%
|
manual_url=http://download.rockbox.org/manual/rockbox-%MODEL%%FORMAT%
|
||||||
doom_url=http://download.rockbox.org/useful/rockdoom.zip
|
doom_url=http://download.rockbox.org/useful/rockdoom.zip
|
||||||
duke3d_url=http://download.rockbox.org/useful/duke3d.zip
|
duke3d_url=http://download.rockbox.org/useful/duke3d.zip
|
||||||
quake_url=http://download.rockbox.org/useful/quake.zip
|
quake_url=http://download.rockbox.org/useful/quake.zip
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,7 @@ QVariant SystemInfo::value(SystemInfo::SystemInfos info)
|
||||||
{
|
{
|
||||||
switch(info) {
|
switch(info) {
|
||||||
case SystemInfo::ManualUrl:
|
case SystemInfo::ManualUrl:
|
||||||
//return QString("https://unittest/manual/rockbox-%MODEL%%FORMAT%");
|
return QString("https://unittest/manual/rockbox-%MODEL%%FORMAT%");
|
||||||
return QString("https://unittest/manual/%MANUALBASENAME%.%EXTENSION%");
|
|
||||||
break;
|
break;
|
||||||
case SystemInfo::BleedingUrl:
|
case SystemInfo::BleedingUrl:
|
||||||
return QString("https://unittest/dev/rockbox-%MODEL%.zip");
|
return QString("https://unittest/dev/rockbox-%MODEL%.zip");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue