mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2026-01-27 04:40:34 +03:00
luci: service: Add method getPackageDict
This commit is contained in:
@@ -50,7 +50,7 @@ return view.extend({
|
||||
fs.exec(tools.execPath, [ 'enabled' ]), // svc_en
|
||||
tools.getSvcInfo(), // svc_info
|
||||
fs.exec('/bin/busybox', [ 'ps' ]), // process list
|
||||
fs.exec(tools.packager.path, tools.packager.args), // installed packages
|
||||
tools.getPackageDict(), // installed packages
|
||||
tools.getStratList(), // nfqws strategy list
|
||||
fs.exec('/bin/cat', [ '/etc/openwrt_release' ]), // CPU arch
|
||||
uci.load(tools.appName), // config
|
||||
@@ -75,7 +75,7 @@ return view.extend({
|
||||
let svc_en = status_array[1]; // stdout: empty or error text
|
||||
let svc_info = status_array[2]; // stdout: JSON as text
|
||||
let proc_list = status_array[3]; // stdout: multiline text
|
||||
let pkg_list = status_array[4]; // stdout: installed packages
|
||||
let pkg_dict = status_array[4]; // stdout: installed packages
|
||||
let stratlist = status_array[5]; // array of strat names
|
||||
let sys_info = status_array[6]; // stdout: openwrt distrib info
|
||||
|
||||
@@ -95,8 +95,8 @@ return view.extend({
|
||||
this.disableButtons(true, -1, elems);
|
||||
return;
|
||||
}
|
||||
if (pkg_list.code != 0) {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': setAppStatus()'));
|
||||
if (!pkg_dict) {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': getPackageDict()'));
|
||||
this.disableButtons(true, -1, elems);
|
||||
return;
|
||||
}
|
||||
@@ -342,9 +342,9 @@ return view.extend({
|
||||
}
|
||||
let cfg = uci.get(tools.appName, 'config');
|
||||
|
||||
let pkg_list = status_array[4];
|
||||
if (pkg_list === undefined || typeof(pkg_list) !== 'object' || pkg_list.code != 0) {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': setAppStatus()'));
|
||||
let pkgdict = status_array[4];
|
||||
if (pkgdict == null) {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': render()'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -431,12 +431,12 @@ return view.extend({
|
||||
poll.add(L.bind(this.statusPoll, this));
|
||||
|
||||
let page_title = tools.AppName;
|
||||
let pkgdict = tools.decode_pkg_list(pkg_list.stdout, false);
|
||||
page_title += '   ';
|
||||
if (pkgdict[tools.appName] === undefined || pkgdict[tools.appName] == '') {
|
||||
page_title += 'unknown version';
|
||||
} else {
|
||||
page_title += 'v' + pkgdict[tools.appName];
|
||||
page_title = page_title.replace(/-r1$/, '');
|
||||
}
|
||||
let aux1 = E('em');
|
||||
let aux2 = E('em');
|
||||
|
||||
@@ -101,6 +101,30 @@ return baseclass.extend({
|
||||
});
|
||||
},
|
||||
|
||||
getPackageDict: function()
|
||||
{
|
||||
let ses_var_name = this.appName+'_pkgdict';
|
||||
let exec_cmd = this.packager.path;
|
||||
let exec_arg = this.packager.args;
|
||||
return fs.exec(exec_cmd, exec_arg).then(res => {
|
||||
let pdict_json = sessionStorage.getItem(ses_var_name);
|
||||
if (res.code != 0) {
|
||||
console.log(this.appName + ': Unable to enumerate installed packages. code = ' + res.code);
|
||||
if (pdict_json != null) {
|
||||
return JSON.parse(pdict_json); // return cached value
|
||||
}
|
||||
return null;
|
||||
}
|
||||
let pdict = this.decode_pkg_list(res.stdout);
|
||||
if (pdict != pdict_json) {
|
||||
sessionStorage.setItem(ses_var_name, JSON.stringify(pdict)); // renew cache
|
||||
}
|
||||
return pdict;
|
||||
}).catch(e => {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages.') + ' Error: %s'.format(e)));
|
||||
});
|
||||
},
|
||||
|
||||
getStratList: function() {
|
||||
let exec_cmd = '/bin/busybox';
|
||||
let exec_arg = [ 'awk', '-F', '"', '/if \\[ "\\$strat" = "/ {print $4}', this.defCfgPath ];
|
||||
@@ -141,7 +165,7 @@ return baseclass.extend({
|
||||
return m ? m[2] : defval;
|
||||
},
|
||||
|
||||
decode_pkg_list: function(pkg_list, with_suffix_r1 = true) {
|
||||
decode_pkg_list: function(pkg_list) {
|
||||
let pkg_dict = { };
|
||||
if (!pkg_list) {
|
||||
return pkg_dict;
|
||||
@@ -180,12 +204,8 @@ return baseclass.extend({
|
||||
}
|
||||
}
|
||||
if (rev >= 0) {
|
||||
if (rev == 1 && !with_suffix_r1) {
|
||||
// nothing
|
||||
} else {
|
||||
ver += '-r' + rev;
|
||||
}
|
||||
}
|
||||
pkg_dict[name] = ver;
|
||||
}
|
||||
return pkg_dict;
|
||||
|
||||
Reference in New Issue
Block a user