Mercurial > hg > octave-nkf
changeset 19414:672674d5e8d9
license.m: Speed up function by 12X
* license.m: Recode to use 'pkg list' rather than 'pkg describe all'
as the latter is extremely slow. Also fixes failing 'make check' if
no packages are installed.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 05 Oct 2014 20:55:35 -0700 |
parents | f5ad7470d957 |
children | eeb2a01cdc26 |
files | scripts/miscellaneous/license.m |
diffstat | 1 files changed, 28 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/miscellaneous/license.m +++ b/scripts/miscellaneous/license.m @@ -71,20 +71,18 @@ ## Then only give information about Octave core if (nargin == 0) retval = "GNU General Public License"; - return + return; endif - [features, desc, flags] = get_all_features (); + [features, loaded] = get_all_features (); - switch tolower (cmd) + switch (tolower (cmd)) case "inuse" if (nargin > 2) print_usage (); endif - unloaded = cellfun (@(x) x.name, desc(strcmpi (flags, "Not loaded")), - "UniformOutput", false); - features(ismember (features, unloaded)) = []; + features = features(loaded); if (nargin > 1) features = features(strcmp (features, feature)); @@ -105,9 +103,9 @@ ## don't need a license management system on Octave. This function ## will return true, even if anyone tries to disabled a license. switch tolower (toogle) - case "enable", # do nothing - case "disable", # do nothing - otherwise, error ("license: TOOGLE must be enable or disable"); + case "enable" # do nothing + case "disable" # do nothing + otherwise error ("license: TOOGLE must be enable or disable"); endswitch endif @@ -126,7 +124,7 @@ errmsg = ""; if (! retval) - errmsg = ["No package named \"" feature "\" installed"]; + errmsg = ['No package named "' feature '" installed']; endif otherwise @@ -144,45 +142,44 @@ endif endfunction -function [features, desc, loaded] = get_all_features () - [desc, loaded] = pkg ("describe", "all"); - pkg_names = cellfun (@(x) x.name, desc, "UniformOutput", false); - features = {"octave", pkg_names{:}}; +function [features, loaded] = get_all_features () + pkg_list = pkg ("list"); + features = {"octave", ... + cellfun(@(x) x.name, pkg_list, "uniformoutput", false){:}}; + loaded = [true, cellfun(@(x) x.loaded, pkg_list)]; endfunction + %!assert (license (), "GNU General Public License") %!assert ((license ("inuse", "octave")).feature, "octave") +%!shared list %!test -%! [desc, flags] = pkg ("describe", "all"); -%! for idx = 1: numel (desc) -%! name = desc{idx}.name; -%! switch (flags{idx}) -%! case "Loaded" -%! assert ((license ("inuse", name)).feature, name); -%! case "Not loaded" -%! rv = license ("inuse", name); -%! assert (isstruct (rv)); -%! assert (all (ismember ({"feature", "user"}, fieldnames (rv)))); -%! otherwise -%! error ("code in license out of date"); -%! endswitch +%! list = pkg ("list"); +%! for idx = 1: numel (list) +%! name = list{idx}.name; +%! if (list{idx}.loaded); +%! assert ((license ("inuse", name)).feature, name); +%! else +%! rv = license ("inuse", name); +%! assert (isstruct (rv)); +%! assert (all (isfield (rv, {"feature", "user"}))); +%! endif %! endfor %!assert (license ("test", "octave"), true) %!assert (license ("test", "not_a_valid package name"), false) %!test -%! desc = pkg ("describe", "all"); -%! for idx = 1: numel (desc) -%! assert (license ("test", desc{idx}.name), true) +%! for idx = 1: numel (list) +%! assert (license ("test", list{idx}.name), true) %! endfor %!assert (license ("checkout", "octave"), true) %!test %! [s, e] = license ("checkout", "NOT_A_PACKAGE"); -%! assert (e, "No package named \"NOT_A_PACKAGE\" installed"); +%! assert (e, 'No package named "NOT_A_PACKAGE" installed'); %% Test input validation %!error license ("not_inuse")