Skip to content
Snippets Groups Projects
Commit 9cb827b3 authored by Moritz Warning's avatar Moritz Warning
Browse files

refactor code and make the listing of unmatches images optional

parent be1a8766
No related branches found
No related tags found
No related merge requests found
...@@ -183,13 +183,13 @@ var firmwarewizard = function() { ...@@ -183,13 +183,13 @@ var firmwarewizard = function() {
} }
// exclude file names containing a string // exclude file names containing a string
function isValidFileName(name) { function ignoreFileName(name) {
for (var i in IGNORED_ELEMENTS) { for (var i in IGNORED_ELEMENTS) {
if (name.indexOf(IGNORED_ELEMENTS[i]) != -1) { if (name.indexOf(IGNORED_ELEMENTS[i]) != -1) {
return false; return true;
} }
} }
return true; return false;
} }
// simplified version string sort // simplified version string sort
...@@ -215,6 +215,12 @@ var firmwarewizard = function() { ...@@ -215,6 +215,12 @@ var firmwarewizard = function() {
return m ? m[1] : ''; return m ? m[1] : '';
} }
function findRevision(name) {
// reversion identifier like a1, v2
var m = /-([a-z][0-9]+(.[0-9]+)?)[.-]/.exec(name);
return m ? m[1] : 'alle';
}
function findRegion(name) { function findRegion(name) {
var m = /-(eu|cn|de|jp|us)[.-]/.exec(name); var m = /-(eu|cn|de|jp|us)[.-]/.exec(name);
return m ? m[1] : ''; return m ? m[1] : '';
...@@ -228,6 +234,41 @@ var firmwarewizard = function() { ...@@ -228,6 +234,41 @@ var firmwarewizard = function() {
} }
} }
function parseFilePath(device, match, path, href, branch) {
if (device.model == '--ignore--' || device.revision == '--ignore--') {
return;
}
var location = path + href;
var type = findType(href);
var version = findVersion(href);
var region = findRegion(href);
var revision = device.revision;
if (revision.length == 0) {
revision = findRevision(href.replace(match, ''));
}
if (region.length) {
revision += '-' + region;
}
// collect branch versions
app.currentVersions[branch] = version;
if (!(device.vendor in images)) {
images[device.vendor] = {};
}
addArray(images[device.vendor], device.model, {
'revision': revision,
'branch': branch,
'type': type,
'version': version,
'location': location
});
}
function createOption(value, title, selectedOption) { function createOption(value, title, selectedOption) {
var o = document.createElement('option'); var o = document.createElement('option');
o.value = value; o.value = value;
...@@ -480,70 +521,32 @@ var firmwarewizard = function() { ...@@ -480,70 +521,32 @@ var firmwarewizard = function() {
return 0; return 0;
}); });
for (var indexPath in config.directories) { // match all links
var basePath = indexPath.substring(0, indexPath.lastIndexOf('/') + 1); var reLink = new RegExp('href="([^"]*)"', 'g');
var branch = config.directories[indexPath];
// match image files
var reMatch = new RegExp('('+matches.join('|')+')[.-]');
for (var indexPath in config.directories) {
// retrieve the contents of the directory // retrieve the contents of the directory
loadSite(indexPath, function(data, indexPath) { loadSite(indexPath, function(data, indexPath) {
// create regex for extracting image paths var basePath = indexPath.substring(0, indexPath.lastIndexOf('/') + 1);
var reIndex = new RegExp('="([^"]*[-.][^"]*)"', 'g'); var branch = config.directories[indexPath];
reLink.lastIndex = 0;
// find the correct reversion (e.g. a1, v2)
var reRevision = '[a-z][0-9]+(.[0-9]+)?';
var reMatches = new RegExp('('+matches.join('|')+')-?(rev-)?('+reRevision+')?(-sysupgrade)?.(img.gz|bin|tar|img|elf|vdi|vmdk)$');
var m; var m;
do { do {
m = reIndex.exec(data); m = reLink.exec(data);
if (m) { if (m) {
var href = m[1]; var href = m[1];
var match = reMatches.exec(href); var match = reMatch.exec(href);
if (isValidFileName(href)) {
if (match) { if (match) {
var devices = vendormodels_reverse[match[1]]; var devices = vendormodels_reverse[match[1]];
for (var i in devices) { for (var i in devices) {
if (devices[i].model == '--ignore--' || devices[i].revision == '--ignore--') { parseFilePath(devices[i], match, basePath, href, branch);
continue;
}
var location = basePath + href;
var type = findType(href);
var version = findVersion(href);
var revision = devices[i].revision;
if (revision.length == 0) {
revision = match[3] || 'alle';
href.replace(revision, '');
}
var region = findRegion(href);
if (region.length) {
revision += '-' + region;
}
// collect branch versions
app.currentVersions[branch] = version;
if (!(devices[i].vendor in images)) {
images[devices[i].vendor] = {};
}
addArray(images[devices[i].vendor], devices[i].model, {
'revision': revision,
'branch': branch,
'type': type,
'version': version,
'location': location
});
}
} else {
console.log("No rule for firmware image", href);
} }
} else if(config.listMissingImages && !ignoreFileName(href)) {
console.log("No rule for firmware image:", href);
} }
} }
} while (m); } while (m);
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
*/ */
var config = { var config = {
// list images on console that match no model
listMissingImages: false,
// see devices.js for different vendor model maps // see devices.js for different vendor model maps
vendormodels: vendormodels, vendormodels: vendormodels,
// relative image paths and branch // relative image paths and branch
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment