Skip to content

Commit

Permalink
IDE: display details about the Bela version in the IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliomoro committed Feb 1, 2021
1 parent 4af6629 commit 1d5be8e
Show file tree
Hide file tree
Showing 16 changed files with 488 additions and 43 deletions.
33 changes: 18 additions & 15 deletions IDE/dist/FileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,26 +401,29 @@ function read_subfolders(dir_path) {
exports.read_subfolders = read_subfolders;
function read_directory(dir_path) {
return __awaiter(this, void 0, void 0, function () {
var out;
var out, e_4;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, lock.acquire()];
case 1:
_a.sent();
_a.label = 2;
case 2:
_a.trys.push([2, , 4, 5]);
_a.trys.push([2, 4, 5, 6]);
return [4 /*yield*/, fs.readdirAsync(dir_path)];
case 3:
out = _a.sent();
out.sort(function (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
return [3 /*break*/, 5];
return [3 /*break*/, 6];
case 4:
e_4 = _a.sent();
return [3 /*break*/, 6];
case 5:
lock.release();
return [7 /*endfinally*/];
case 5: return [2 /*return*/, out];
case 6: return [2 /*return*/, out];
}
});
});
Expand Down Expand Up @@ -539,7 +542,7 @@ exports.save_file = SaveFile_1.save_file;
// recursively read the contents of a directory, returning an array of File_Descriptors
function deep_read_directory(dir_path) {
return __awaiter(this, void 0, void 0, function () {
var contents, output, contents_1, contents_1_1, name_1, original_path, path, stat, maxLevels, levels, desc, _a, e_4_1, e_4, _b;
var contents, output, contents_1, contents_1_1, name_1, original_path, path, stat, maxLevels, levels, desc, _a, e_5_1, e_5, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, read_directory(dir_path)];
Expand Down Expand Up @@ -600,14 +603,14 @@ function deep_read_directory(dir_path) {
return [3 /*break*/, 3];
case 13: return [3 /*break*/, 16];
case 14:
e_4_1 = _c.sent();
e_4 = { error: e_4_1 };
e_5_1 = _c.sent();
e_5 = { error: e_5_1 };
return [3 /*break*/, 16];
case 15:
try {
if (contents_1_1 && !contents_1_1.done && (_b = contents_1.return)) _b.call(contents_1);
}
finally { if (e_4) throw e_4.error; }
finally { if (e_5) throw e_5.error; }
return [7 /*endfinally*/];
case 16: return [2 /*return*/, output];
}
Expand Down Expand Up @@ -691,7 +694,7 @@ function file_exists(file_path) {
exports.file_exists = file_exists;
function delete_matching_recursive(path, matches) {
return __awaiter(this, void 0, void 0, function () {
var all, contents, matching, updated, matching_1, matching_1_1, match, full_path, e_5_1, contents_2, contents_2_1, file, full_path, stat, e_6_1, e_5, _a, e_6, _b;
var all, contents, matching, updated, matching_1, matching_1_1, match, full_path, e_6_1, contents_2, contents_2_1, file, full_path, stat, e_7_1, e_6, _a, e_7, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, read_directory(path)];
Expand Down Expand Up @@ -724,14 +727,14 @@ function delete_matching_recursive(path, matches) {
return [3 /*break*/, 4];
case 7: return [3 /*break*/, 10];
case 8:
e_5_1 = _c.sent();
e_5 = { error: e_5_1 };
e_6_1 = _c.sent();
e_6 = { error: e_6_1 };
return [3 /*break*/, 10];
case 9:
try {
if (matching_1_1 && !matching_1_1.done && (_a = matching_1.return)) _a.call(matching_1);
}
finally { if (e_5) throw e_5.error; }
finally { if (e_6) throw e_6.error; }
return [7 /*endfinally*/];
case 10:
if (!updated) return [3 /*break*/, 12];
Expand Down Expand Up @@ -759,14 +762,14 @@ function delete_matching_recursive(path, matches) {
return [3 /*break*/, 13];
case 16: return [3 /*break*/, 19];
case 17:
e_6_1 = _c.sent();
e_6 = { error: e_6_1 };
e_7_1 = _c.sent();
e_7 = { error: e_7_1 };
return [3 /*break*/, 19];
case 18:
try {
if (contents_2_1 && !contents_2_1.done && (_b = contents_2.return)) _b.call(contents_2);
}
finally { if (e_6) throw e_6.error; }
finally { if (e_7) throw e_7.error; }
return [7 /*endfinally*/];
case 19: return [2 /*return*/];
}
Expand Down
12 changes: 8 additions & 4 deletions IDE/dist/SocketManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ function init_message(socket) {
return [4 /*yield*/, IDE.board_detect().catch(function (e) { return console.log('error in board detect', e); })];
case 6:
_a.board_string = _b.sent();
return [4 /*yield*/, IDE.get_xenomai_version()
// status : await process_manager.status()
];
return [4 /*yield*/, IDE.get_xenomai_version()];
case 7:
message = (_a.xenomai_version = _b.sent(),
_a.xenomai_version = _b.sent();
return [4 /*yield*/, IDE.get_bela_image_version()];
case 8:
_a.bela_image_version = _b.sent();
return [4 /*yield*/, IDE.get_bela_core_version()];
case 9:
message = (_a.bela_core_version = _b.sent(),
_a);
socket.emit('init', message);
return [2 /*return*/];
Expand Down
138 changes: 138 additions & 0 deletions IDE/dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
};
Object.defineProperty(exports, "__esModule", { value: true });
var express = require("express");
var http = require("http");
Expand Down Expand Up @@ -186,6 +196,134 @@ function setup_routes(app) {
// gui
app.use('/gui', express.static(paths.gui));
}
function get_bela_core_version() {
var _this = this;
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
var data, updateLog, e_1, tokens, matches, keys, tokens_1, tokens_1_1, str, n, reg, stat, dir, cmd, e_2, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
data = {};
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, fs.readFileAsync(paths.update_log, 'utf8')];
case 2:
updateLog = _b.sent();
return [3 /*break*/, 4];
case 3:
e_1 = _b.sent();
return [3 /*break*/, 4];
case 4:
if (!updateLog) return [3 /*break*/, 7];
tokens = updateLog.toString().split('\n');
matches = [/^FILENAME=/, /^DATE=/, /^SUCCESS=/, /^METHOD=/];
keys = ['fileName', 'date', 'success', 'method'];
try {
for (tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) {
str = tokens_1_1.value;
for (n in matches) {
reg = matches[n];
if (str.match(reg)) {
str = str.replace(reg, '').trim();
data[keys[n]] = str;
}
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
}
finally { if (e_2) throw e_2.error; }
}
if ('true' === data.success)
data.success = 1;
else
data.success = 0;
if (!(!data.fileName && !data.date && !data.method)) return [3 /*break*/, 7];
// old update logs, for backwards compatibilty:
// - guess date from file's modification time
// - fix method
// - guess fileName from backup path
// - get success from legacy string
data = {};
return [4 /*yield*/, fs.statAsync(paths.update_log)];
case 5:
stat = _b.sent();
data.date = stat.mtime;
data.method = 'make update (legacy)';
return [4 /*yield*/, file_manager.read_directory(paths.update_backup)];
case 6:
dir = _b.sent();
if (dir && dir.length > 1)
data.fileName = dir[0];
if (-1 !== updateLog.indexOf('Update successful'))
data.success = 1;
else
data.success = -1; //unknown
_b.label = 7;
case 7:
cmd = 'git -C ' + paths.Bela + ' describe --always --dirty';
child_process.exec(cmd, function (err, stdout, stderr) {
if (err) {
console.log('error executing: ' + cmd);
}
var ret = {
fileName: data.fileName,
date: data.date,
method: data.method,
success: data.success,
git_desc: stdout.trim(),
log: updateLog,
};
resolve(ret);
});
return [2 /*return*/];
}
});
}); });
}
exports.get_bela_core_version = get_bela_core_version;
function get_bela_image_version() {
return new Promise(function (resolve, reject) {
return __awaiter(this, void 0, void 0, function () {
var buffer, tokens, str, tokens_2, tokens_2_1, e_3, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, fs.readFileAsync('/etc/motd', 'utf8')];
case 1:
buffer = _b.sent();
if (!buffer) {
reject();
return [2 /*return*/];
}
tokens = buffer.toString().split('\n');
try {
for (tokens_2 = __values(tokens), tokens_2_1 = tokens_2.next(); !tokens_2_1.done; tokens_2_1 = tokens_2.next()) {
str = tokens_2_1.value;
if (str.match(/^Bela image.*/)) {
resolve(str);
return [2 /*return*/];
}
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (tokens_2_1 && !tokens_2_1.done && (_a = tokens_2.return)) _a.call(tokens_2);
}
finally { if (e_3) throw e_3.error; }
}
reject();
return [2 /*return*/];
}
});
});
});
}
exports.get_bela_image_version = get_bela_image_version;
function get_xenomai_version() {
if (globals.local_dev)
return new Promise(function (resolve) { return resolve("3.0"); });
Expand Down
2 changes: 2 additions & 0 deletions IDE/dist/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function set_Bela(new_path) {
exports.lockfile = exports.Bela + 'IDE/.lockfile';
exports.xenomai_stat = '/proc/xenomai/sched/stat';
exports.update = exports.Bela + 'updates/';
exports.update_backup = exports.Bela + '../_BelaUpdateBackup/updates/';
exports.update_log = exports.Bela + '../update.log';
exports.tmp = "/tmp/";
}
exports.set_Bela = set_Bela;
Expand Down
2 changes: 2 additions & 0 deletions IDE/frontend-dev/src/IDE-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ socket.on('init', (data) => {

$('[data-run-on-boot]').val(data.boot_project);

models.settings.setKey('belaCoreVersion', data.bela_core_version);
models.settings.setKey('belaImageVersion', data.bela_image_version);
models.settings.setKey('xenomaiVersion', data.xenomai_version);

console.log('running on', data.board_string);
Expand Down
60 changes: 59 additions & 1 deletion IDE/frontend-dev/src/Views/SettingsView.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
var View = require('./View');
var popup = require('../popup');
var json = require('../site-text.json');
var utils = require('../utils');

var belaCoreVersionString;
var belaImageVersionString;
var inputChangedTimeout;

class SettingsView extends View {
Expand Down Expand Up @@ -58,7 +61,6 @@ class SettingsView extends View {
var func = data.func;
var key = data.key;
var val = $element.val();
console.log(func, key, val);
if (func && this[func]){
if (val) {
this[func](func, key, $element.val());
Expand Down Expand Up @@ -433,5 +435,61 @@ class SettingsView extends View {
$('[data-accordion="' + exceptions['sections'][sect] + '"]').css('display', 'none');
}
}

versionPopup() {
var strings = {};
strings.title = json.popups.version.title;
strings.button = json.popups.version.button;
// popup.code is the only one that accepts HTML, so we have to use that
// to make it pickup the line breaks
strings.code = utils.formatString('<p>{0}</p><p>Core code:<br />{1}</p>',
belaImageVersionString, belaCoreVersionString);
popup.ok(strings);
}

_belaCoreVersion(ver) {
var format = utils.formatString;
var s = [];
var templates = json.popups.version;
console.log(ver);
if(ver.date || ver.fileName) {
var t;
switch(ver.success) {
case 0:
t = templates.textTemplateFailed;
break;
case 1:
t = templates.textTemplateSuccess;
break;
default:
case -1:
t = templates.textTemplateUnknown; // unknown success (e.g.: incomplete legacy log)
break;
}
if(ver.date) {
var date = new Date(ver.date);
var dateString = date.getDay() + ' ' + date.toLocaleString('default', {month: "short"}) + ' '
+ date.getFullYear() + ' ' + date.toTimeString().replace(/GMT.*/, '');
//e.toLocaleString(json.locale, {time: 'full'});
s.push(format(t[0], dateString));
}
if(ver.fileName)
s.push(format(t[1], ver.fileName));
if(ver.method)
s.push(format(t[2], ver.method));
s.push(t[3]);
} else {
s.push(templates.textUnknown); // no info available
}
if(ver.git_desc)
s.push(format(templates.textTemplateGitDesc, ver.git_desc));
belaCoreVersionString = s.join('<br \>');
}

_belaImageVersion(ver){
console.log('Bela image version:', ver);
belaImageVersionString = ver;
}

}
module.exports = SettingsView;
Loading

0 comments on commit 1d5be8e

Please sign in to comment.