annotate scripts/miscellaneous/license.m @ 21634:96518f623c91

Backed out changeset dcf8922b724b
author Mike Miller <mtmiller@octave.org>
date Wed, 20 Apr 2016 11:06:03 -0700
parents dcf8922b724b
children b571fc85953f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
1 ## Copyright (C) 2005-2015 William Poetra Yoga Hadisoeseno
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
2 ## Copyright (C) 2014-2015 Carnë Draug
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
3 ##
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
4 ## This file is part of Octave.
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
5 ##
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6555
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6555
diff changeset
9 ## your option) any later version.
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
10 ##
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
14 ## General Public License for more details.
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
15 ##
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6555
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6555
diff changeset
18 ## <http://www.gnu.org/licenses/>.
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
19
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
21 ## @deftypefn {} {} license
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
22 ## @deftypefnx {} {} license inuse
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
23 ## @deftypefnx {} {} license inuse @var{feature}
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
24 ## @deftypefnx {} {} license ("inuse")
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
25 ## @deftypefnx {} {@var{retval} =} license ("inuse")
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
26 ## @deftypefnx {} {@var{retval} =} license ("test", @var{feature})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
27 ## @deftypefnx {} {@var{retval} =} license ("checkout", @var{feature})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
28 ## @deftypefnx {} {[@var{retval}, @var{errmsg}] =} license ("checkout", @var{feature})
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
29 ## Get license information for Octave and Octave packages.
16491
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
30 ##
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
31 ## GNU Octave is free software distributed under the GNU General Public
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
32 ## License (GPL), and a license manager makes no sense. This function is
19405
cbce5d1bcaf9 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19222
diff changeset
33 ## provided only for @sc{matlab} compatibility.
16491
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
34 ##
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
35 ## When called with no extra input arguments, it returns the Octave license,
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
36 ## otherwise the first input defines the operation mode and must be one of
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
37 ## the following strings: @code{inuse}, @code{test}, and @code{checkout}.
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
38 ## The optional @var{feature} argument can either be @qcode{"octave"} (core),
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
39 ## or an Octave package.
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
40 ##
11595
5ec6aa05638d Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
41 ## @table @asis
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
42 ## @item @qcode{"inuse"}
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
43 ## Returns a list of loaded features, i.e., octave and the list of loaded
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
44 ## packages. If an output is requested, it returns a struct array with
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
45 ## the fields @qcode{"feature"}, and @qcode{"user"}.
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
46 ##
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
47 ## @item @qcode{"test"}
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
48 ## Return true if the specified @var{feature} is installed, false otherwise.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
49 ##
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
50 ## An optional third argument @qcode{"enable"} or @qcode{"disable"} is
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
51 ## accepted but ignored.
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
52 ##
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
53 ## @item @qcode{"checkout"}
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
54 ## Return true if the specified @var{feature} is installed, false otherwise.
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
55 ## An optional second output will have an error message if a package is not
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
56 ## installed.
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
57 ##
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
58 ## @end table
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
59 ##
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
60 ## @seealso{pkg, ver, version}
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
61 ## @end deftypefn
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
62
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
63 ## Author: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
64
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
65 function [retval, errmsg] = license (cmd, feature, toogle)
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
66
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
67 if (nargin > 3)
13825
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
68 print_usage ();
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
69 endif
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
70
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
71 ## Then only give information about Octave core
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
72 if (nargin == 0)
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
73 retval = "GNU General Public License";
19222
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
74 return;
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
75 endif
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
76
19222
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
77 [features, loaded] = get_all_features ();
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
78
19222
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
79 switch (tolower (cmd))
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
80 case "inuse"
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
81 if (nargin > 2)
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
82 print_usage ();
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
83 endif
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
84
19222
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
85 features = features(loaded);
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
86
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
87 if (nargin > 1)
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
88 features = features(strcmp (features, feature));
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
89 endif
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
90 if (nargout == 0)
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
91 printf ("%s\n", features{:});
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
92 else
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
93 retval = struct ("feature", features, "user", get_username ());
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
94 endif
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
95
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
96 case "test"
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
97 if (nargin < 2)
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
98 print_usage ();
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
99 endif
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
100
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
101 if (nargin > 2)
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
102 ## We ignore the toogle argument because... what's the point? We
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
103 ## don't need a license management system on Octave. This function
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
104 ## will return true, even if anyone tries to disabled a license.
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
105 switch (tolower (toogle))
19222
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
106 case "enable" # do nothing
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
107 case "disable" # do nothing
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
108 otherwise error ("license: TOOGLE must be enable or disable");
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
109 endswitch
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
110 endif
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
111
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
112 retval = any (strcmp (features, feature));
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
113
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
114 case "checkout"
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
115 ## I guess we could have the checkout command load packages but it's not
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
116 ## really the same thing. The closest we have is simply to check if
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
117 ## there is a package with the feature name, and give an error if not.
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
118
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
119 if (nargin != 2)
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
120 print_usage ();
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
121 endif
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
122
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
123 retval = any (strcmp (features, feature));
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
124 errmsg = "";
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
125
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
126 if (! retval)
19222
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
127 errmsg = ['No package named "' feature '" installed'];
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
128 endif
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
129
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
130 otherwise
13825
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
131 print_usage ();
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
132 endswitch
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
133
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
134 endfunction
13825
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
135
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
136 function username = get_username ()
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
137 pw = getpwuid (getuid ());
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
138 if (isstruct (pw))
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
139 username = pw.name;
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
140 else
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
141 username = "octave_user";
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
142 endif
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
143 endfunction
13825
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
144
19222
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
145 function [features, loaded] = get_all_features ()
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
146 pkg_list = pkg ("list");
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
147 features = {"octave", ...
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
148 cellfun(@(x) x.name, pkg_list, "uniformoutput", false){:}};
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
149 loaded = [true, cellfun(@(x) x.loaded, pkg_list)];
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
150 endfunction
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
151
19222
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
152
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
153 %!assert (license (), "GNU General Public License")
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
154 %!assert ((license ("inuse", "octave")).feature, "octave")
13825
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
155
19222
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
156 %!shared list
13825
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
157 %!test
19222
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
158 %! list = pkg ("list");
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
159 %! for idx = 1: numel (list)
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
160 %! name = list{idx}.name;
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
161 %! if (list{idx}.loaded);
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
162 %! assert ((license ("inuse", name)).feature, name);
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
163 %! else
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
164 %! rv = license ("inuse", name);
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
165 %! assert (isstruct (rv));
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
166 %! assert (all (isfield (rv, {"feature", "user"})));
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
167 %! endif
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
168 %! endfor
13825
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
169
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
170 %!assert (license ("test", "octave"), true)
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
171 %!assert (license ("test", "not_a_valid package name"), false)
13825
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
172
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
173 %!test
19222
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
174 %! for idx = 1: numel (list)
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
175 %! assert (license ("test", list{idx}.name), true);
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
176 %! endfor
13825
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
177
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
178 %!assert (license ("checkout", "octave"), true)
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
179
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
180 %!test
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
181 %! [s, e] = license ("checkout", "NOT_A_PACKAGE");
19222
672674d5e8d9 license.m: Speed up function by 12X
Rik <rik@octave.org>
parents: 19203
diff changeset
182 %! assert (e, 'No package named "NOT_A_PACKAGE" installed');
13825
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
183
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
184 ## Test input validation
13825
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
185 %!error license ("not_inuse")
19203
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
186 %!error license ("not_test", "octave", "enable")
6dfce51a7b40 license.m: update to treat packages as features (bug #43154).
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
187 %!error <TOOGLE must be enable or disable> license ("test", "octave", "invalid_toogle")
13825
45f4ff9a6247 license.m: Update to modern coding standards. Add functional and input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12480
diff changeset
188