Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Add testing options for os_list.json
Browse files Browse the repository at this point in the history
- If a os_list_v3.json is present in root of SD card, use that instead
  of downloading the file from repo server.
- Allow non-standard repository URL to be specified in recovery.cmdline
  repo=http://url/file.json
  • Loading branch information
maxnet committed Oct 30, 2016
1 parent 8d3c567 commit 0feffba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
51 changes: 49 additions & 2 deletions recovery/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,50 @@ MainWindow::MainWindow(const QString &defaultDisplay, QSplashScreen *splash, QWi

_model = getFileContents("/proc/device-tree/model");
QString cmdline = getFileContents("/proc/cmdline");

if (QFile::exists("/mnt/os_list_v3.json"))

This comment has been minimized.

Copy link
@lurch

lurch Oct 31, 2016

Collaborator

I realise this is only for testing purposes, but there's part of me that wonders if the "os_list_v3.json" part of this string should be moved to config.h ? (and then have it also used to construct the DEFAULT_REPO_SERVER value)

{
/* We have a local os_list_v3.json for testing purposes */
_repo = "/mnt/os_list_v3.json";

/* We need a somewhat accurate date for https to work. Normally we retrieve that from the repo server,
but since we are in testing mode, just set date to last modification time of our local file */
if (QDate::currentDate().year() < 2016)
{
QFileInfo fi(_repo);

struct timeval tv;
tv.tv_sec = fi.lastModified().toTime_t();
tv.tv_usec = 0;
settimeofday(&tv, NULL);
}
}
else if (cmdline.contains("repo="))

This comment has been minimized.

Copy link
@procount

procount Oct 31, 2016

Contributor

Most command line arguments are checked in main() but a few are checked like this - what's the reasoning (apart from being easier to code)? Shouldn't they be handled consistently?

This comment has been minimized.

Copy link
@maxnet

maxnet Oct 31, 2016

Author Collaborator

Was written by different authors, that all like to do it their own way :-)

You do are right that having a central place handling command parsing would be cleaner.
Don't think the way things are done in main() is that consistent either though.
The recovery.cmdline parsing first occurs in a shell script ( https://github.com/raspberrypi/noobs/blob/master/buildroot/package/recovery/init#L66 ) that then converts it to a different set of command line parameters used to start the program (e.g. display=something is transformed to -dispmode=something), which are then parsed again in main.

Might be better to rewrite all parsing and put it in a seperate class, however that takes time (especially to test all parameters), and does not benefit the end-user in any way.

{
QByteArray searchFor = "repo=";
int searchForLen = searchFor.length();
int pos = cmdline.indexOf(searchFor);
int end;

if (cmdline.length() > pos+searchForLen && cmdline.at(pos+searchForLen) == '"')
{
/* Value between quotes */
searchForLen++;
end = cmdline.indexOf('"', pos+searchForLen);
}
else
{
end = cmdline.indexOf(' ', pos+searchForLen);
}
if (end != -1)
end = end-pos-searchForLen;
_repo = cmdline.mid(pos+searchForLen, end);
}
else
{
_repo = DEFAULT_REPO_SERVER;
}

if (cmdline.contains("showall"))
{
_showAll = true;
Expand Down Expand Up @@ -991,11 +1035,14 @@ void MainWindow::downloadList(const QString &urlstring)
void MainWindow::downloadLists()
{
_numIconsToDownload = 0;
QStringList urls = QString(DEFAULT_REPO_SERVER).split(' ', QString::SkipEmptyParts);
QStringList urls = _repo.split(' ', QString::SkipEmptyParts);

foreach (QString url, urls)
{
downloadList(url);
if (url.startsWith("/"))

This comment has been minimized.

Copy link
@procount

procount Oct 31, 2016

Contributor

Ahh, interesting use, but I think it mixes up the 2 methods of getting the OS lists.
Incidentally, I have noticed the previous inclusion of osinfo, which I suppose is meant to harmonise the use of the OS information which is scattered about in different forms. So I took that principle and am trying to percolate osinfo throughout the code. In addition, I am introducing OsSource to wrap each source of OS lists (SD, USB, Network) and let each run independently. It will also avoid the current race conditions brought about by assuming the SD card is always read before the network comes up. It might be an interesting alternative approach to this method, if you are interested....

processJson( Json::parse(getFileContents(url)) );
else
downloadList(url);
}
}

Expand Down
2 changes: 1 addition & 1 deletion recovery/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MainWindow : public QMainWindow
QMessageBox *_displayModeBox;
QTimer _networkStatusPollTimer;
QTime _time;
QString _model;
QString _model, _repo;

QMap<QString,QVariantMap> listImages();
virtual void changeEvent(QEvent * event);
Expand Down

0 comments on commit 0feffba

Please sign in to comment.