summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2020-11-15 21:01:36 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2020-11-15 21:01:36 +0100
commit104ff3433a9f26009751cbd317d0024742d1310b (patch)
tree3bb5b2bad788ba6946212de3a97ebf1d39ed2682
parent2b2a7b9ae340e2f7273c79ebb8d6140b8fd7aa35 (diff)
downloadrockbox-104ff3433a9f26009751cbd317d0024742d1310b.tar.gz
rockbox-104ff3433a9f26009751cbd317d0024742d1310b.zip
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
-rw-r--r--rbutil/rbutilqt/base/serverinfo.cpp274
-rw-r--r--rbutil/rbutilqt/base/serverinfo.h8
-rw-r--r--rbutil/rbutilqt/rbutil.ini2
-rw-r--r--rbutil/rbutilqt/test/stubs/stubs-serverinfo.cpp3
4 files changed, 127 insertions, 160 deletions
diff --git a/rbutil/rbutilqt/base/serverinfo.cpp b/rbutil/rbutilqt/base/serverinfo.cpp
index 5a0719f375..c4d51d4431 100644
--- a/rbutil/rbutilqt/base/serverinfo.cpp
+++ b/rbutil/rbutilqt/base/serverinfo.cpp
@@ -21,184 +21,148 @@
#include "systeminfo.h"
#include "Logger.h"
+static QSettings* serverSettings = nullptr;
+
// server infos
const static struct {
ServerInfo::ServerInfos info;
const char* name;
- const char* def;
} ServerInfoList[] = {
- { ServerInfo::CurReleaseVersion, ":platform:/releaseversion", "" },
- { ServerInfo::CurReleaseUrl, ":platform:/releaseurl", "" },
- { ServerInfo::RelCandidateVersion, ":platform:/rcversion", "" },
- { ServerInfo::RelCandidateUrl, ":platform:/rcurl", "" },
- { ServerInfo::CurStatus, ":platform:/status", "Unknown" },
- { ServerInfo::ManualPdfUrl, ":platform:/manual_pdf", "" },
- { ServerInfo::ManualHtmlUrl, ":platform:/manual_html", "" },
- { ServerInfo::ManualZipUrl, ":platform:/manual_zip", "" },
- { ServerInfo::BleedingRevision, "bleedingrev", "" },
- { ServerInfo::BleedingDate, "bleedingdate", "" },
- { ServerInfo::CurDevelUrl, ":platform:/develurl", "" },
+ { ServerInfo::CurReleaseVersion, "release/:platform:" },
+ { ServerInfo::CurReleaseUrl, "release/:platform:" },
+ { ServerInfo::RelCandidateVersion, "release-candidate/:platform:" },
+ { ServerInfo::RelCandidateUrl, "release-candidate/:platform:" },
+ { ServerInfo::CurStatus, "status/:platform:" },
+ { ServerInfo::ManualPdfUrl, "" },
+ { ServerInfo::ManualHtmlUrl, "" },
+ { ServerInfo::ManualZipUrl, "" },
+ { ServerInfo::BleedingRevision, "bleeding/rev" },
+ { ServerInfo::BleedingDate, "bleeding/timestamp" },
+ { ServerInfo::CurDevelUrl, "" },
};
QMap<QString, QVariant> ServerInfo::serverInfos;
void ServerInfo::readBuildInfo(QString file)
{
- QString releaseBaseUrl = SystemInfo::value(SystemInfo::ReleaseUrl).toString();
- QString develBaseUrl = SystemInfo::value(SystemInfo::BleedingUrl).toString();
- QString manualBaseUrl = SystemInfo::value(SystemInfo::ManualUrl).toString();
-
- 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);
- }
- }
+ if (serverSettings)
+ delete serverSettings;
+ serverSettings = new QSettings(file, QSettings::IniFormat);
}
-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)
{
- // locate setting item
+ // locate setting item in server info file
int i = 0;
while(ServerInfoList[i].info != info)
i++;
+ // replace setting name
if(platform.isEmpty())
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;
s.replace(":platform:", platform);
- QString d = ServerInfoList[i].def;
- d.replace(":platform:", platform);
- LOG_INFO() << "GET:" << s << serverInfos.value(s, d).toString();
- return serverInfos.value(s, d);
+
+ // get value
+ QVariant value = QString();
+ 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;
}
diff --git a/rbutil/rbutilqt/base/serverinfo.h b/rbutil/rbutilqt/base/serverinfo.h
index 7588521b09..6c68bd3f5d 100644
--- a/rbutil/rbutilqt/base/serverinfo.h
+++ b/rbutil/rbutilqt/base/serverinfo.h
@@ -22,6 +22,10 @@
#define SERVERINFO_H
#include <QtCore>
+#define STATUS_RETIRED 0
+#define STATUS_UNUSABLE 1
+#define STATUS_UNSTABLE 2
+#define STATUS_STABLE 3
class ServerInfo : public QObject
{
@@ -47,10 +51,10 @@ class ServerInfo : public QObject
static void readBuildInfo(QString file);
//! get a value from server info for a named platform.
static QVariant platformValue(enum ServerInfos setting, QString platform = "");
+ //! Convert status number to string
+ static QString statusToString(int status);
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
ServerInfo() {}
diff --git a/rbutil/rbutilqt/rbutil.ini b/rbutil/rbutilqt/rbutil.ini
index 59a5ab3f6c..b92ddcd557 100644
--- a/rbutil/rbutilqt/rbutil.ini
+++ b/rbutil/rbutilqt/rbutil.ini
@@ -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
; 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
duke3d_url=http://download.rockbox.org/useful/duke3d.zip
quake_url=http://download.rockbox.org/useful/quake.zip
diff --git a/rbutil/rbutilqt/test/stubs/stubs-serverinfo.cpp b/rbutil/rbutilqt/test/stubs/stubs-serverinfo.cpp
index c223dee555..7d2016d6bd 100644
--- a/rbutil/rbutilqt/test/stubs/stubs-serverinfo.cpp
+++ b/rbutil/rbutilqt/test/stubs/stubs-serverinfo.cpp
@@ -42,8 +42,7 @@ QVariant SystemInfo::value(SystemInfo::SystemInfos info)
{
switch(info) {
case SystemInfo::ManualUrl:
- //return QString("https://unittest/manual/rockbox-%MODEL%%FORMAT%");
- return QString("https://unittest/manual/%MANUALBASENAME%.%EXTENSION%");
+ return QString("https://unittest/manual/rockbox-%MODEL%%FORMAT%");
break;
case SystemInfo::BleedingUrl:
return QString("https://unittest/dev/rockbox-%MODEL%.zip");