Mercurial > octave
annotate scripts/pkg/pkg.m @ 12561:0ade5992e374
Add documentation for '-forge' option (bug #32464).
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 31 Mar 2011 20:57:37 -0700 |
parents | ad636c1f353b |
children | f96b9b9f141b |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2005-2011 S�ren Hauberg |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
2 ## Copyright (C) 2010 VZLU Prague, a.s. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3 ## |
6440 | 4 ## This file is part of Octave. |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
6440 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
5801 | 16 ## You should have received a copy of the GNU General Public License |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5801 | 19 |
20 ## -*- texinfo -*- | |
11547 | 21 ## @deftypefn {Command} {} pkg @var{command} @var{pkg_name} |
22 ## @deftypefnx {Command} {} pkg @var{command} @var{option} @var{pkg_name} | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
23 ## This command interacts with the package manager. Different actions will |
6378 | 24 ## be taken depending on the value of @var{command}. |
6032 | 25 ## |
26 ## @table @samp | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
27 ## |
6032 | 28 ## @item install |
6070 | 29 ## Install named packages. For example, |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
30 ## |
6070 | 31 ## @example |
32 ## pkg install image-1.0.0.tar.gz | |
33 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
34 ## |
6070 | 35 ## @noindent |
9307
c2923c27c877
Various documentation improvements
Rik <rdrider0-list@yahoo.com>
parents:
9258
diff
changeset
|
36 ## installs the package found in the file @file{image-1.0.0.tar.gz}. |
6070 | 37 ## |
6645 | 38 ## The @var{option} variable can contain options that affect the manner |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
39 ## in which a package is installed. These options can be one or more of |
6645 | 40 ## |
41 ## @table @code | |
42 ## @item -nodeps | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
43 ## The package manager will disable the dependency checking. That way it |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
44 ## is possible to install a package even if it depends on another package |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
45 ## that's not installed on the system. @strong{Use this option with care.} |
6645 | 46 ## |
47 ## @item -noauto | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
48 ## The package manager will not automatically load the installed package |
6645 | 49 ## when starting Octave, even if the package requests that it is. |
6258 | 50 ## |
6645 | 51 ## @item -auto |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
52 ## The package manager will automatically load the installed package when |
6645 | 53 ## starting Octave, even if the package requests that it isn't. |
54 ## | |
55 ## @item -local | |
56 ## A local installation is forced, even if the user has system privileges. | |
6258 | 57 ## |
6645 | 58 ## @item -global |
59 ## A global installation is forced, even if the user doesn't normally have | |
60 ## system privileges | |
12561
0ade5992e374
Add documentation for '-forge' option (bug #32464).
Rik <octave@nomad.inbox5.com>
parents:
12167
diff
changeset
|
61 ## |
0ade5992e374
Add documentation for '-forge' option (bug #32464).
Rik <octave@nomad.inbox5.com>
parents:
12167
diff
changeset
|
62 ## @item -forge |
0ade5992e374
Add documentation for '-forge' option (bug #32464).
Rik <octave@nomad.inbox5.com>
parents:
12167
diff
changeset
|
63 ## Install a package directly from the Octave-Forge repository. This |
0ade5992e374
Add documentation for '-forge' option (bug #32464).
Rik <octave@nomad.inbox5.com>
parents:
12167
diff
changeset
|
64 ## requires an internet connection and the cURL library. |
6614 | 65 ## |
6645 | 66 ## @item -verbose |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
67 ## The package manager will print the output of all of the commands that are |
6645 | 68 ## performed. |
69 ## @end table | |
70 ## | |
6032 | 71 ## @item uninstall |
6070 | 72 ## Uninstall named packages. For example, |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
73 ## |
6070 | 74 ## @example |
75 ## pkg uninstall image | |
76 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
77 ## |
6070 | 78 ## @noindent |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
79 ## removes the @code{image} package from the system. If another installed |
6070 | 80 ## package depends on the @code{image} package an error will be issued. |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10685
diff
changeset
|
81 ## The package can be uninstalled anyway by using the @option{-nodeps} option. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
82 ## |
6032 | 83 ## @item load |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
84 ## Add named packages to the path. After loading a package it is |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
85 ## possible to use the functions provided by the package. For example, |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
86 ## |
6070 | 87 ## @example |
88 ## pkg load image | |
89 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
90 ## |
6070 | 91 ## @noindent |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
92 ## adds the @code{image} package to the path. It is possible to load all |
6070 | 93 ## installed packages at once with the command |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
94 ## |
6070 | 95 ## @example |
96 ## pkg load all | |
97 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
98 ## |
6203 | 99 ## @item unload |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
100 ## Removes named packages from the path. After unloading a package it is |
6203 | 101 ## no longer possible to use the functions provided by the package. |
102 ## This command behaves like the @code{load} command. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
103 ## |
6032 | 104 ## @item list |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
105 ## Show a list of the currently installed packages. By requesting one or two |
6070 | 106 ## output argument it is possible to get a list of the currently installed |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
107 ## packages. For example, |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
108 ## |
6070 | 109 ## @example |
110 ## installed_packages = pkg list; | |
111 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
112 ## |
6070 | 113 ## @noindent |
114 ## returns a cell array containing a structure for each installed package. | |
115 ## The command | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
116 ## |
6070 | 117 ## @example |
118 ## [@var{user_packages}, @var{system_packages}] = pkg list | |
119 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
120 ## |
6070 | 121 ## @noindent |
122 ## splits the list of installed packages into those who are installed by | |
123 ## the current user, and those installed by the system administrator. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
124 ## |
12561
0ade5992e374
Add documentation for '-forge' option (bug #32464).
Rik <octave@nomad.inbox5.com>
parents:
12167
diff
changeset
|
125 ## The option '-forge' lists packages available at the Octave-Forge repository. |
0ade5992e374
Add documentation for '-forge' option (bug #32464).
Rik <octave@nomad.inbox5.com>
parents:
12167
diff
changeset
|
126 ## This requires an internet connection and the cURL library. |
0ade5992e374
Add documentation for '-forge' option (bug #32464).
Rik <octave@nomad.inbox5.com>
parents:
12167
diff
changeset
|
127 ## |
7497 | 128 ## @item describe |
129 ## Show a short description of the named installed packages, with the option | |
130 ## '-verbose' also list functions provided by the package, e.g.: | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
131 ## |
7497 | 132 ## @example |
133 ## pkg describe -verbose all | |
134 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
135 ## |
7497 | 136 ## @noindent |
137 ## will describe all installed packages and the functions they provide. | |
138 ## If one output is requested a cell of structure containing the | |
139 ## description and list of functions of each package is returned as | |
140 ## output rather than printed on screen: | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
141 ## |
7497 | 142 ## @example |
143 ## desc = pkg ("describe", "secs1d", "image") | |
144 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
145 ## |
7497 | 146 ## @noindent |
147 ## If any of the requested packages is not installed, pkg returns an | |
148 ## error, unless a second output is requested: | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
149 ## |
7497 | 150 ## @example |
151 ## [ desc, flag] = pkg ("describe", "secs1d", "image") | |
152 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
153 ## |
7497 | 154 ## @noindent |
155 ## @var{flag} will take one of the values "Not installed", "Loaded" or | |
156 ## "Not loaded" for each of the named packages. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
157 ## |
6034 | 158 ## @item prefix |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
159 ## Set the installation prefix directory. For example, |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
160 ## |
6070 | 161 ## @example |
162 ## pkg prefix ~/my_octave_packages | |
163 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
164 ## |
6070 | 165 ## @noindent |
9307
c2923c27c877
Various documentation improvements
Rik <rdrider0-list@yahoo.com>
parents:
9258
diff
changeset
|
166 ## sets the installation prefix to @file{~/my_octave_packages}. |
6070 | 167 ## Packages will be installed in this directory. |
6034 | 168 ## |
6070 | 169 ## It is possible to get the current installation prefix by requesting an |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
170 ## output argument. For example: |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
171 ## |
6070 | 172 ## @example |
173 ## p = pkg prefix | |
174 ## @end example | |
6925 | 175 ## |
176 ## The location in which to install the architecture dependent files can be | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
177 ## independent specified with an addition argument. For example: |
6925 | 178 ## |
179 ## @example | |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
180 ## pkg prefix ~/my_octave_packages ~/my_arch_dep_pkgs |
6925 | 181 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
182 ## |
6189 | 183 ## @item local_list |
184 ## Set the file in which to look for information on the locally | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
185 ## installed packages. Locally installed packages are those that are |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
186 ## typically available only to the current user. For example: |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
187 ## |
6189 | 188 ## @example |
189 ## pkg local_list ~/.octave_packages | |
190 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
191 ## |
6189 | 192 ## It is possible to get the current value of local_list with the following |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
193 ## |
6189 | 194 ## @example |
195 ## pkg local_list | |
196 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
197 ## |
6189 | 198 ## @item global_list |
199 ## Set the file in which to look for, for information on the globally | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
200 ## installed packages. Globally installed packages are those that are |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
201 ## typically available to all users. For example: |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
202 ## |
6189 | 203 ## @example |
204 ## pkg global_list /usr/share/octave/octave_packages | |
205 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
206 ## |
6189 | 207 ## It is possible to get the current value of global_list with the following |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
208 ## |
6189 | 209 ## @example |
210 ## pkg global_list | |
211 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
212 ## |
6645 | 213 ## @item rebuild |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
214 ## Rebuilds the package database from the installed directories. This can |
6645 | 215 ## be used in cases where for some reason the package database is corrupted. |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10685
diff
changeset
|
216 ## It can also take the @option{-auto} and @option{-noauto} options to allow the |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
217 ## autoloading state of a package to be changed. For example, |
6645 | 218 ## |
219 ## @example | |
220 ## pkg rebuild -noauto image | |
221 ## @end example | |
222 ## | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
223 ## @noindent |
6645 | 224 ## will remove the autoloading status of the image package. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
225 ## |
6675 | 226 ## @item build |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
227 ## Builds a binary form of a package or packages. The binary file produced |
6675 | 228 ## will itself be an Octave package that can be installed normally with |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
229 ## @code{pkg}. The form of the command to build a binary package is |
6675 | 230 ## |
231 ## @example | |
232 ## pkg build builddir image-1.0.0.tar.gz @dots{} | |
233 ## @end example | |
234 ## | |
235 ## @noindent | |
9079
4d610aba7347
Cleanup documentation for system.texi, package.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
236 ## where @code{builddir} is the name of a directory where the temporary |
6675 | 237 ## installation will be produced and the binary packages will be found. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
238 ## The options @option{-verbose} and @option{-nodeps} are respected, while |
6675 | 239 ## the other options are ignored. |
6032 | 240 ## @end table |
11547 | 241 ## @end deftypefn |
5947 | 242 |
6496 | 243 function [local_packages, global_packages] = pkg (varargin) |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8174
diff
changeset
|
244 ## Installation prefix (FIXME: what should these be on windows?) |
6645 | 245 persistent user_prefix = false; |
6496 | 246 persistent prefix = -1; |
6925 | 247 persistent archprefix = -1; |
7498 | 248 persistent local_list = tilde_expand (fullfile ("~", ".octave_packages")); |
6496 | 249 persistent global_list = fullfile (OCTAVE_HOME (), "share", "octave", |
10549 | 250 "octave_packages"); |
6496 | 251 mlock (); |
6189 | 252 |
6925 | 253 global_install = issuperuser (); |
6683 | 254 |
6496 | 255 if (prefix == -1) |
6645 | 256 if (global_install) |
6496 | 257 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); |
7498 | 258 archprefix = fullfile (octave_config_info ("libexecdir"), |
10549 | 259 "octave", "packages"); |
6496 | 260 else |
261 prefix = fullfile ("~", "octave"); | |
6925 | 262 archprefix = prefix; |
5801 | 263 endif |
6645 | 264 prefix = tilde_expand (prefix); |
6925 | 265 archprefix = tilde_expand (archprefix); |
6496 | 266 endif |
267 | |
7498 | 268 available_actions = {"list", "install", "uninstall", "load", ... |
10549 | 269 "unload", "prefix", "local_list", ... |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
270 "global_list", "rebuild", "build","describe"}; |
6496 | 271 ## Handle input |
272 if (length (varargin) == 0 || ! iscellstr (varargin)) | |
273 print_usage (); | |
274 endif | |
275 files = {}; | |
276 deps = true; | |
277 auto = 0; | |
278 action = "none"; | |
6614 | 279 verbose = false; |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
280 octave_forge = false; |
6496 | 281 for i = 1:length (varargin) |
282 switch (varargin{i}) | |
283 case "-nodeps" | |
10549 | 284 deps = false; |
6496 | 285 case "-noauto" |
10549 | 286 auto = -1; |
6496 | 287 case "-auto" |
10549 | 288 auto = 1; |
6614 | 289 case "-verbose" |
10549 | 290 verbose = true; |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
291 case "-forge" |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
292 octave_forge = true; |
6645 | 293 case "-local" |
10549 | 294 global_install = false; |
295 if (! user_prefix) | |
296 prefix = tilde_expand (fullfile ("~", "octave")); | |
297 archprefix = prefix; | |
298 endif | |
6645 | 299 case "-global" |
10549 | 300 global_install = true; |
301 if (! user_prefix) | |
302 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); | |
303 archprefix = fullfile (octave_config_info ("libexecdir"), | |
304 "octave", "packages"); | |
305 endif | |
7497 | 306 case available_actions |
10549 | 307 if (strcmp (action, "none")) |
308 action = varargin{i}; | |
309 else | |
310 error ("more than one action specified"); | |
311 endif | |
6496 | 312 otherwise |
10549 | 313 files{end+1} = varargin{i}; |
5801 | 314 endswitch |
6496 | 315 endfor |
316 | |
10685
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
317 if (octave_forge && ! any (strcmp (action, {"install", "list"}))) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
318 error ("-forge can only be used with install or list"); |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
319 endif |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
320 |
6496 | 321 ## Take action |
322 switch (action) | |
323 case "list" | |
10685
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
324 if (octave_forge) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
325 if (nargout > 0) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
326 local_packages = list_forge_packages (); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
327 else |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
328 list_forge_packages (); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
329 endif |
6496 | 330 else |
10685
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
331 if (nargout == 0) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
332 installed_packages (local_list, global_list); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
333 elseif (nargout == 1) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
334 local_packages = installed_packages (local_list, global_list); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
335 elseif (nargout == 2) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
336 [local_packages, global_packages] = installed_packages (local_list, |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
337 global_list); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
338 else |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
339 error ("too many output arguments requested"); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
340 endif |
6496 | 341 endif |
342 | |
343 case "install" | |
344 if (length (files) == 0) | |
10549 | 345 error ("you must specify at least one filename when calling 'pkg install'"); |
6496 | 346 endif |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
347 |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
348 local_files = {}; |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
349 unwind_protect |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
350 |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
351 if (octave_forge) |
11191
01ddaedd6ad5
Reverse changeset b1f4bdc276b6. Use all lower case for "uniformoutput" option.
Rik <octave@nomad.inbox5.com>
parents:
11190
diff
changeset
|
352 [urls, local_files] = cellfun (@get_forge_download, files, "uniformoutput", false); |
01ddaedd6ad5
Reverse changeset b1f4bdc276b6. Use all lower case for "uniformoutput" option.
Rik <octave@nomad.inbox5.com>
parents:
11190
diff
changeset
|
353 [files, succ] = cellfun (@urlwrite, urls, local_files, "uniformoutput", false); |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
354 succ = [succ{:}]; |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
355 if (! all (succ)) |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
356 i = find (! succ, 1); |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
357 error ("could not download file %s from url %s", local_files{i}, urls{i}); |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
358 endif |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
359 endif |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
360 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
361 install (files, deps, auto, prefix, archprefix, verbose, local_list, |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
362 global_list, global_install); |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
363 |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
364 unwind_protect_cleanup |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
365 cellfun (@unlink, local_files); |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
366 end_unwind_protect |
6496 | 367 |
368 case "uninstall" | |
369 if (length (files) == 0) | |
10549 | 370 error ("you must specify at least one package when calling 'pkg uninstall'"); |
6496 | 371 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
372 uninstall (files, deps, verbose, local_list, |
10549 | 373 global_list, global_install); |
6496 | 374 |
375 case "load" | |
376 if (length (files) == 0) | |
10549 | 377 error ("you must specify at least one package, 'all' or 'auto' when calling 'pkg load'"); |
6496 | 378 endif |
379 load_packages (files, deps, local_list, global_list); | |
380 | |
381 case "unload" | |
382 if (length (files) == 0) | |
10549 | 383 error ("you must specify at least one package or 'all' when calling 'pkg unload'"); |
6496 | 384 endif |
385 unload_packages (files, deps, local_list, global_list); | |
386 | |
387 case "prefix" | |
388 if (length (files) == 0 && nargout == 0) | |
10549 | 389 printf ("Installation prefix: %s\n", prefix); |
390 printf ("Architecture dependent prefix: %s\n", archprefix); | |
6925 | 391 elseif (length (files) == 0 && nargout >= 1) |
10549 | 392 local_packages = prefix; |
393 global_packages = archprefix; | |
6925 | 394 elseif (length (files) >= 1 && nargout <= 2 && ischar (files{1})) |
10549 | 395 prefix = files{1}; |
396 prefix = absolute_pathname (prefix); | |
397 local_packages = prefix; | |
398 user_prefix = true; | |
399 if (length (files) >= 2 && ischar (files{2})) | |
400 archprefix = files{2}; | |
401 try | |
402 archprefix = absolute_pathname (archprefix); | |
6925 | 403 catch |
10549 | 404 mkdir (archprefix); |
405 warning ("creating the directory %s\n", archprefix); | |
406 archprefix = absolute_pathname (archprefix); | |
407 end_try_catch | |
408 global_packages = archprefix; | |
409 endif | |
6496 | 410 else |
10549 | 411 error ("you must specify a prefix directory, or request an output argument"); |
6496 | 412 endif |
413 | |
414 case "local_list" | |
415 if (length (files) == 0 && nargout == 0) | |
10549 | 416 disp (local_list); |
6496 | 417 elseif (length (files) == 0 && nargout == 1) |
10549 | 418 local_packages = local_list; |
6496 | 419 elseif (length (files) == 1 && nargout == 0 && ischar (files{1})) |
10549 | 420 try |
421 local_list = absolute_pathname (files{1}); | |
422 catch | |
423 ## Force file to be created | |
424 fclose (fopen (files{1}, "wt")); | |
425 local_list = absolute_pathname (files{1}); | |
426 end_try_catch | |
6496 | 427 else |
10549 | 428 error ("you must specify a local_list file, or request an output argument"); |
6496 | 429 endif |
430 | |
431 case "global_list" | |
432 if (length (files) == 0 && nargout == 0) | |
10549 | 433 disp(global_list); |
6496 | 434 elseif (length (files) == 0 && nargout == 1) |
10549 | 435 local_packages = global_list; |
6496 | 436 elseif (length (files) == 1 && nargout == 0 && ischar (files{1})) |
10549 | 437 try |
438 global_list = absolute_pathname (files{1}); | |
439 catch | |
440 ## Force file to be created | |
441 fclose (fopen (files{1}, "wt")); | |
442 global_list = absolute_pathname (files{1}); | |
443 end_try_catch | |
6496 | 444 else |
10549 | 445 error ("you must specify a global_list file, or request an output argument"); |
6496 | 446 endif |
6645 | 447 |
448 case "rebuild" | |
449 if (global_install) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
450 global_packages = rebuild (prefix, archprefix, global_list, files, |
10549 | 451 auto, verbose); |
452 global_packages = save_order (global_packages); | |
453 save (global_list, "global_packages"); | |
454 if (nargout > 0) | |
455 local_packages = global_packages; | |
456 endif | |
6645 | 457 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
458 local_packages = rebuild (prefix, archprefix, local_list, files, auto, |
10549 | 459 verbose); |
460 local_packages = save_order (local_packages); | |
461 save (local_list, "local_packages"); | |
462 if (nargout == 0) | |
463 clear ("local_packages"); | |
464 endif | |
6645 | 465 endif |
466 | |
6675 | 467 case "build" |
468 if (length (files) < 2) | |
10549 | 469 error ("you must specify at least the build directory and one filename\nwhen calling 'pkg build'"); |
6675 | 470 endif |
471 build (files, deps, auto, verbose); | |
472 | |
7497 | 473 case "describe" |
474 if (length (files) == 0) | |
10549 | 475 error ("you must specify at least one package or 'all' when calling 'pkg describe'"); |
7497 | 476 endif |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8174
diff
changeset
|
477 ## FIXME: the name of the output variables is inconsistent |
7497 | 478 ## with their content |
479 switch (nargout) | |
10549 | 480 case 0 |
481 describe (files, verbose, local_list, global_list); | |
482 case 1 | |
483 pkg_desc_list = describe (files, verbose, local_list, ... | |
484 global_list); | |
485 local_packages = pkg_desc_list; | |
486 case 2 | |
487 [pkg_desc_list, flag] = describe (files, verbose, local_list, ... | |
488 global_list); | |
489 local_packages = pkg_desc_list; | |
490 global_packages = flag; | |
491 otherwise | |
492 error ("you can request at most two outputs when calling 'pkg describe'"); | |
7498 | 493 endswitch |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
494 |
6496 | 495 otherwise |
496 error ("you must specify a valid action for 'pkg'. See 'help pkg' for details"); | |
497 endswitch | |
498 endfunction | |
499 | |
6925 | 500 function descriptions = rebuild (prefix, archprefix, list, files, auto, verbose) |
6645 | 501 if (isempty (files)) |
502 [dirlist, err, msg] = readdir (prefix); | |
503 if (err) | |
504 error ("couldn't read directory %s: %s", prefix, msg); | |
505 endif | |
506 ## the two first entries of dirlist are "." and ".." | |
507 dirlist([1,2]) = []; | |
508 else | |
509 old_descriptions = installed_packages (list, list); | |
510 wd = pwd (); | |
6663 | 511 unwind_protect |
512 cd (prefix); | |
11191
01ddaedd6ad5
Reverse changeset b1f4bdc276b6. Use all lower case for "uniformoutput" option.
Rik <octave@nomad.inbox5.com>
parents:
11190
diff
changeset
|
513 dirlist = glob (cellfun(@(x) cstrcat(x, '-*'), files, 'uniformoutput', 0)); |
6663 | 514 unwind_protect_cleanup |
515 cd (wd); | |
516 end_unwind_protect | |
6645 | 517 endif |
518 descriptions = {}; | |
519 for k = 1:length (dirlist) | |
520 descfile = fullfile (prefix, dirlist{k}, "packinfo", "DESCRIPTION"); | |
521 if (verbose) | |
522 printf ("recreating package description from %s\n", dirlist{k}); | |
523 endif | |
524 if (exist (descfile, "file")) | |
525 desc = get_description (descfile); | |
526 desc.dir = fullfile (prefix, dirlist{k}); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
527 desc.archprefix = fullfile (archprefix, cstrcat (desc.name, "-", |
10549 | 528 desc.version)); |
6645 | 529 if (auto != 0) |
10549 | 530 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file")) |
531 unlink (fullfile (desc.dir, "packinfo", ".autoload")); | |
532 endif | |
6645 | 533 if (auto < 0) |
10549 | 534 desc.autoload = 0; |
535 elseif (auto > 0) | |
536 desc.autoload = 1; | |
537 fclose (fopen (fullfile (desc.dir, "packinfo", ".autoload"), "wt")); | |
538 endif | |
6645 | 539 else |
10549 | 540 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file")) |
541 desc.autoload = 1; | |
542 else | |
543 desc.autoload = 0; | |
544 endif | |
6645 | 545 endif |
546 descriptions{end + 1} = desc; | |
547 elseif (verbose) | |
548 warning ("directory %s is not a valid package", dirlist{k}); | |
549 endif | |
550 endfor | |
551 | |
6663 | 552 if (! isempty (files)) |
6645 | 553 ## We are rebuilding for a particular package(s) so we should take |
554 ## care to keep the other untouched packages in the descriptions | |
6663 | 555 descriptions = {descriptions{:}, old_descriptions{:}}; |
6645 | 556 |
557 dup = []; | |
558 for i = 1:length (descriptions) | |
559 if (find (dup, i)) | |
10549 | 560 continue; |
6645 | 561 endif |
562 for j = (i+1):length (descriptions) | |
10549 | 563 if (find (dup, j)) |
564 continue; | |
565 endif | |
566 if (strcmp (descriptions{i}.name, descriptions{j}.name)) | |
567 dup = [dup, j]; | |
568 endif | |
6645 | 569 endfor |
570 endfor | |
571 if (! isempty (dup)) | |
572 descriptions (dup) = []; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
573 endif |
6645 | 574 endif |
575 endfunction | |
576 | |
6675 | 577 function build (files, handle_deps, autoload, verbose) |
578 if (length (files) < 1) | |
579 error ("insufficient number of files"); | |
580 endif | |
581 builddir = files{1}; | |
582 if (! exist (builddir, "dir")) | |
583 warning ("creating build directory %s", builddir); | |
584 [status, msg] = mkdir (builddir); | |
585 if (status != 1) | |
586 error ("could not create installation directory: %s", msg); | |
587 endif | |
6496 | 588 endif |
6675 | 589 builddir = absolute_pathname (builddir); |
590 installdir = fullfile (builddir, "install"); | |
591 if (! exist (installdir, "dir")) | |
592 [status, msg] = mkdir (installdir); | |
593 if (status != 1) | |
594 error ("could not create installation directory: %s", msg); | |
595 endif | |
596 endif | |
597 files(1) = []; | |
598 buildlist = fullfile (builddir, "octave_packages"); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
599 install (files, handle_deps, autoload, installdir, installdir, verbose, |
10549 | 600 buildlist, "", false); |
6675 | 601 unwind_protect |
602 repackage (builddir, buildlist); | |
603 unwind_protect_cleanup | |
604 unload_packages ({"all"}, handle_deps, buildlist, ""); | |
605 if (exist (installdir, "dir")) | |
606 rm_rf (installdir); | |
607 endif | |
608 if (exist (buildlist, "file")) | |
609 unlink (buildlist); | |
610 endif | |
611 end_unwind_protect | |
5801 | 612 endfunction |
613 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
614 function install (files, handle_deps, autoload, prefix, archprefix, verbose, |
10549 | 615 local_list, global_list, global_install) |
6496 | 616 |
8506 | 617 ## Check that the directory in prefix exist. If it doesn't: create it! |
6496 | 618 if (! exist (prefix, "dir")) |
619 warning ("creating installation directory %s", prefix); | |
620 [status, msg] = mkdir (prefix); | |
621 if (status != 1) | |
622 error ("could not create installation directory: %s", msg); | |
623 endif | |
624 endif | |
625 | |
8506 | 626 ## Get the list of installed packages. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
627 [local_packages, global_packages] = installed_packages (local_list, |
10549 | 628 global_list); |
6496 | 629 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
630 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 631 |
632 if (global_install) | |
633 packages = global_packages; | |
634 else | |
635 packages = local_packages; | |
636 endif | |
637 | |
8506 | 638 ## Uncompress the packages and read the DESCRIPTION files. |
6496 | 639 tmpdirs = packdirs = descriptions = {}; |
640 try | |
8506 | 641 ## Warn about non existent files. |
6683 | 642 for i = 1:length (files) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
643 if (isempty (glob(files{i}))) |
10549 | 644 warning ("file %s does not exist", files{i}); |
6683 | 645 endif |
646 endfor | |
647 | |
8506 | 648 ## Unpack the package files and read the DESCRIPTION files. |
6496 | 649 files = glob (files); |
650 packages_to_uninstall = []; | |
651 for i = 1:length (files) | |
652 tgz = files{i}; | |
653 | |
6645 | 654 if (exist (tgz, "file")) |
10549 | 655 ## Create a temporary directory. |
656 tmpdir = tmpnam (); | |
657 tmpdirs{end+1} = tmpdir; | |
6645 | 658 if (verbose) |
10549 | 659 printf ("mkdir (%s)\n", tmpdir); |
660 endif | |
661 [status, msg] = mkdir (tmpdir); | |
662 if (status != 1) | |
663 error ("couldn't create temporary directory: %s", msg); | |
664 endif | |
6496 | 665 |
10549 | 666 ## Uncompress the package. |
667 if (verbose) | |
668 printf ("untar (%s, %s)\n", tgz, tmpdir); | |
669 endif | |
670 untar (tgz, tmpdir); | |
6496 | 671 |
10549 | 672 ## Get the name of the directories produced by tar. |
673 [dirlist, err, msg] = readdir (tmpdir); | |
674 if (err) | |
675 error ("couldn't read directory produced by tar: %s", msg); | |
676 endif | |
6496 | 677 |
10549 | 678 if (length (dirlist) > 3) |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11588
diff
changeset
|
679 error ("bundles of packages are not allowed"); |
10549 | 680 endif |
7632
d6e63a15cc75
Allow installation of already extracted packages
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
7548
diff
changeset
|
681 endif |
6496 | 682 |
8506 | 683 ## The filename pointed to an uncompressed package to begin with. |
7632
d6e63a15cc75
Allow installation of already extracted packages
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
7548
diff
changeset
|
684 if (exist (tgz, "dir")) |
10549 | 685 dirlist = {".", "..", tgz}; |
7632
d6e63a15cc75
Allow installation of already extracted packages
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
7548
diff
changeset
|
686 endif |
6645 | 687 |
7632
d6e63a15cc75
Allow installation of already extracted packages
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
7548
diff
changeset
|
688 if (exist (tgz, "file") || exist (tgz, "dir")) |
10549 | 689 ## The two first entries of dirlist are "." and "..". |
690 if (exist (tgz, "file")) | |
691 packdir = fullfile (tmpdir, dirlist{3}); | |
692 else | |
693 packdir = fullfile (pwd(), dirlist{3}); | |
694 endif | |
695 packdirs{end+1} = packdir; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
696 |
10549 | 697 ## Make sure the package contains necessary files. |
698 verify_directory (packdir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
699 |
10549 | 700 ## Read the DESCRIPTION file. |
701 filename = fullfile (packdir, "DESCRIPTION"); | |
702 desc = get_description (filename); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
703 |
10549 | 704 ## Verify that package name corresponds with filename. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
705 [dummy, nm] = fileparts (tgz); |
10549 | 706 if ((length (nm) >= length (desc.name)) |
707 && ! strcmp (desc.name, nm(1:length(desc.name)))) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
708 error ("package name '%s' doesn't correspond to its filename '%s'", |
10549 | 709 desc.name, nm); |
710 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
711 |
10549 | 712 ## Set default installation directory. |
713 desc.dir = fullfile (prefix, cstrcat (desc.name, "-", desc.version)); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
714 |
10549 | 715 ## Set default architectire dependent installation directory. |
716 desc.archprefix = fullfile (archprefix, cstrcat (desc.name, "-", | |
717 desc.version)); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
718 |
10549 | 719 ## Save desc. |
720 descriptions{end+1} = desc; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
721 |
10549 | 722 ## Are any of the new packages already installed? |
723 ## If so we'll remove the old version. | |
724 for j = 1:length (packages) | |
725 if (strcmp (packages{j}.name, desc.name)) | |
726 packages_to_uninstall(end+1) = j; | |
727 endif | |
728 endfor | |
6645 | 729 endif |
6496 | 730 endfor |
731 catch | |
8506 | 732 ## Something went wrong, delete tmpdirs. |
6496 | 733 for i = 1:length (tmpdirs) |
734 rm_rf (tmpdirs{i}); | |
735 endfor | |
6655 | 736 rethrow (lasterror ()); |
6496 | 737 end_try_catch |
738 | |
8506 | 739 ## Check dependencies. |
6496 | 740 if (handle_deps) |
741 ok = true; | |
742 error_text = ""; | |
743 for i = 1:length (descriptions) | |
744 desc = descriptions{i}; | |
10196
69bb6e1e10d2
complement->setdiff in pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
745 idx2 = setdiff (1:length(descriptions), i); |
6695 | 746 if (global_install) |
10549 | 747 ## Global installation is not allowed to have dependencies on locally |
748 ## installed packages. | |
749 idx1 = setdiff (1:length(global_packages), packages_to_uninstall); | |
750 pseudo_installed_packages = {global_packages{idx1}, ... | |
751 descriptions{idx2}}; | |
6695 | 752 else |
10549 | 753 idx1 = setdiff (1:length(local_packages), packages_to_uninstall); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
754 pseudo_installed_packages = {local_packages{idx1}, ... |
10549 | 755 global_packages{:}, ... |
756 descriptions{idx2}}; | |
6695 | 757 endif |
6496 | 758 bad_deps = get_unsatisfied_deps (desc, pseudo_installed_packages); |
759 ## Are there any unsatisfied dependencies? | |
760 if (! isempty (bad_deps)) | |
10549 | 761 ok = false; |
762 for i = 1:length (bad_deps) | |
763 dep = bad_deps{i}; | |
764 error_text = cstrcat (error_text, " ", desc.name, " needs ", | |
765 dep.package, " ", dep.operator, " ", | |
766 dep.version, "\n"); | |
767 endfor | |
6496 | 768 endif |
769 endfor | |
770 | |
771 ## Did we find any unsatisfied dependencies? | |
772 if (! ok) | |
773 error ("the following dependencies where unsatisfied:\n %s", error_text); | |
774 endif | |
775 endif | |
776 | |
8506 | 777 ## Prepare each package for installation. |
6496 | 778 try |
779 for i = 1:length (descriptions) | |
780 desc = descriptions{i}; | |
781 pdir = packdirs{i}; | |
782 prepare_installation (desc, pdir); | |
6614 | 783 configure_make (desc, pdir, verbose); |
6496 | 784 endfor |
785 catch | |
8506 | 786 ## Something went wrong, delete tmpdirs. |
6496 | 787 for i = 1:length (tmpdirs) |
788 rm_rf (tmpdirs{i}); | |
789 endfor | |
6655 | 790 rethrow (lasterror ()); |
6496 | 791 end_try_catch |
792 | |
8506 | 793 ## Uninstall the packages that will be replaced. |
6496 | 794 try |
795 for i = packages_to_uninstall | |
6695 | 796 if (global_install) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
797 uninstall ({global_packages{i}.name}, false, verbose, local_list, |
10549 | 798 global_list, global_install); |
6695 | 799 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
800 uninstall ({local_packages{i}.name}, false, verbose, local_list, |
10549 | 801 global_list, global_install); |
6695 | 802 endif |
6496 | 803 endfor |
804 catch | |
8506 | 805 ## Something went wrong, delete tmpdirs. |
6496 | 806 for i = 1:length (tmpdirs) |
807 rm_rf (tmpdirs{i}); | |
808 endfor | |
6655 | 809 rethrow (lasterror ()); |
6496 | 810 end_try_catch |
811 | |
8506 | 812 ## Install each package. |
6496 | 813 try |
814 for i = 1:length (descriptions) | |
815 desc = descriptions{i}; | |
816 pdir = packdirs{i}; | |
6925 | 817 copy_files (desc, pdir, global_install); |
818 create_pkgadddel (desc, pdir, "PKG_ADD", global_install); | |
819 create_pkgadddel (desc, pdir, "PKG_DEL", global_install); | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
820 finish_installation (desc, pdir, global_install); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
821 generate_lookfor_cache (desc); |
6496 | 822 endfor |
823 catch | |
8506 | 824 ## Something went wrong, delete tmpdirs. |
6496 | 825 for i = 1:length (tmpdirs) |
826 rm_rf (tmpdirs{i}); | |
827 endfor | |
828 for i = 1:length (descriptions) | |
829 rm_rf (descriptions{i}.dir); | |
6925 | 830 rm_rf (getarchdir (descriptions{i})); |
6496 | 831 endfor |
6655 | 832 rethrow (lasterror ()); |
6496 | 833 end_try_catch |
834 | |
835 ## Check if the installed directory is empty. If it is remove it | |
8506 | 836 ## from the list. |
6496 | 837 for i = length (descriptions):-1:1 |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
838 if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
839 && dirempty (getarchdir (descriptions{i}))) |
6655 | 840 warning ("package %s is empty\n", descriptions{i}.name); |
6496 | 841 rm_rf (descriptions{i}.dir); |
6925 | 842 rm_rf (getarchdir (descriptions{i})); |
6496 | 843 descriptions(i) = []; |
844 endif | |
845 endfor | |
846 | |
847 ## If the package requested that it is autoloaded, or the installer | |
848 ## requested that it is, then mark the package as autoloaded. | |
849 for i = length (descriptions):-1:1 | |
850 if (autoload > 0 || (autoload == 0 && isautoload (descriptions(i)))) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
851 fclose (fopen (fullfile (descriptions{i}.dir, "packinfo", |
10549 | 852 ".autoload"), "wt")); |
6695 | 853 descriptions{i}.autoload = 1; |
6496 | 854 endif |
855 endfor | |
856 | |
8506 | 857 ## Add the packages to the package list. |
6496 | 858 try |
859 if (global_install) | |
10196
69bb6e1e10d2
complement->setdiff in pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
860 idx = setdiff (1:length(global_packages), packages_to_uninstall); |
6695 | 861 global_packages = save_order ({global_packages{idx}, descriptions{:}}); |
6496 | 862 save (global_list, "global_packages"); |
6820 | 863 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 864 else |
10196
69bb6e1e10d2
complement->setdiff in pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
865 idx = setdiff (1:length(local_packages), packages_to_uninstall); |
6695 | 866 local_packages = save_order ({local_packages{idx}, descriptions{:}}); |
6496 | 867 save (local_list, "local_packages"); |
6820 | 868 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 869 endif |
870 catch | |
8506 | 871 ## Something went wrong, delete tmpdirs. |
6496 | 872 for i = 1:length (tmpdirs) |
873 rm_rf (tmpdirs{i}); | |
874 endfor | |
875 for i = 1:length (descriptions) | |
876 rm_rf (descriptions{i}.dir); | |
877 endfor | |
878 if (global_install) | |
6695 | 879 printf ("error: couldn't append to %s\n", global_list); |
6496 | 880 else |
6695 | 881 printf ("error: couldn't append to %s\n", local_list); |
6496 | 882 endif |
6695 | 883 rethrow (lasterror ()); |
6496 | 884 end_try_catch |
885 | |
8506 | 886 ## All is well, let's clean up. |
6496 | 887 for i = 1:length (tmpdirs) |
888 [status, msg] = rm_rf (tmpdirs{i}); | |
889 if (status != 1) | |
890 warning ("couldn't clean up after my self: %s\n", msg); | |
891 endif | |
892 endfor | |
893 | |
894 ## Add the newly installed packages to the path, so the user | |
8506 | 895 ## can begin using them. Only load them if they are marked autoload. |
6496 | 896 if (length (descriptions) > 0) |
6695 | 897 idx = []; |
6496 | 898 for i = 1:length (descriptions) |
6695 | 899 if (isautoload (descriptions(i))) |
10549 | 900 nm = descriptions{i}.name; |
901 for j = 1:length (installed_pkgs_lst) | |
902 if (strcmp (nm, installed_pkgs_lst{j}.name)) | |
903 idx (end + 1) = j; | |
904 break; | |
905 endif | |
906 endfor | |
6614 | 907 endif |
6496 | 908 endfor |
6925 | 909 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, |
10549 | 910 global_install); |
6496 | 911 endif |
912 endfunction | |
913 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
914 function uninstall (pkgnames, handle_deps, verbose, local_list, |
10549 | 915 global_list, global_install) |
8506 | 916 ## Get the list of installed packages. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
917 [local_packages, global_packages] = installed_packages(local_list, |
10549 | 918 global_list); |
6645 | 919 if (global_install) |
6820 | 920 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 921 else |
6820 | 922 installed_pkgs_lst = local_packages; |
6496 | 923 endif |
924 | |
6820 | 925 num_packages = length (installed_pkgs_lst); |
6496 | 926 delete_idx = []; |
927 for i = 1:num_packages | |
6820 | 928 cur_name = installed_pkgs_lst{i}.name; |
6496 | 929 if (any (strcmp (cur_name, pkgnames))) |
930 delete_idx(end+1) = i; | |
931 endif | |
932 endfor | |
933 | |
934 ## Are all the packages that should be uninstalled already installed? | |
935 if (length (delete_idx) != length (pkgnames)) | |
6645 | 936 if (global_install) |
8506 | 937 ## Try again for a locally installed package. |
6820 | 938 installed_pkgs_lst = local_packages; |
6496 | 939 |
6820 | 940 num_packages = length (installed_pkgs_lst); |
6496 | 941 delete_idx = []; |
942 for i = 1:num_packages | |
10549 | 943 cur_name = installed_pkgs_lst{i}.name; |
944 if (any (strcmp (cur_name, pkgnames))) | |
945 delete_idx(end+1) = i; | |
946 endif | |
6496 | 947 endfor |
948 if (length (delete_idx) != length (pkgnames)) | |
10549 | 949 ## FIXME: We should have a better error message. |
950 warning ("some of the packages you want to uninstall are not installed"); | |
6496 | 951 endif |
952 else | |
8506 | 953 ## FIXME: We should have a better error message. |
8664 | 954 warning ("some of the packages you want to uninstall are not installed"); |
6496 | 955 endif |
956 endif | |
957 | |
8506 | 958 ## Compute the packages that will remain installed. |
10196
69bb6e1e10d2
complement->setdiff in pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
959 idx = setdiff (1:num_packages, delete_idx); |
6820 | 960 remaining_packages = {installed_pkgs_lst{idx}}; |
6496 | 961 |
8506 | 962 ## Check dependencies. |
6496 | 963 if (handle_deps) |
964 error_text = ""; | |
965 for i = 1:length (remaining_packages) | |
966 desc = remaining_packages{i}; | |
967 bad_deps = get_unsatisfied_deps (desc, remaining_packages); | |
968 | |
969 ## Will the uninstallation break any dependencies? | |
970 if (! isempty (bad_deps)) | |
10549 | 971 for i = 1:length (bad_deps) |
972 dep = bad_deps{i}; | |
973 error_text = cstrcat (error_text, " ", desc.name, " needs ", | |
974 dep.package, " ", dep.operator, " ", | |
975 dep.version, "\n"); | |
976 endfor | |
6496 | 977 endif |
978 endfor | |
979 | |
980 if (! isempty (error_text)) | |
981 error ("the following dependencies where unsatisfied:\n %s", error_text); | |
982 endif | |
983 endif | |
984 | |
8506 | 985 ## Delete the directories containing the packages. |
6496 | 986 for i = delete_idx |
6820 | 987 desc = installed_pkgs_lst{i}; |
6496 | 988 ## If an 'on_uninstall.m' exist, call it! |
989 if (exist (fullfile (desc.dir, "packinfo", "on_uninstall.m"), "file")) | |
6614 | 990 wd = pwd (); |
7498 | 991 cd (fullfile (desc.dir, "packinfo")); |
6614 | 992 on_uninstall (desc); |
993 cd (wd); | |
6496 | 994 endif |
8506 | 995 ## Do the actual deletion. |
6675 | 996 if (desc.loaded) |
997 rmpath (desc.dir); | |
6925 | 998 if (exist (getarchdir (desc))) |
10549 | 999 rmpath (getarchdir (desc)); |
6675 | 1000 endif |
6614 | 1001 endif |
6496 | 1002 if (exist (desc.dir, "dir")) |
1003 [status, msg] = rm_rf (desc.dir); | |
1004 if (status != 1) | |
10549 | 1005 error ("couldn't delete directory %s: %s", desc.dir, msg); |
6496 | 1006 endif |
6925 | 1007 [status, msg] = rm_rf (getarchdir (desc)); |
1008 if (status != 1) | |
10549 | 1009 error ("couldn't delete directory %s: %s", getarchdir (desc), msg); |
6925 | 1010 endif |
1011 if (dirempty (desc.archprefix)) | |
10549 | 1012 rm_rf (desc.archprefix); |
6925 | 1013 endif |
6496 | 1014 else |
1015 warning ("directory %s previously lost", desc.dir); | |
1016 endif | |
1017 endfor | |
1018 | |
8506 | 1019 ## Write a new ~/.octave_packages. |
6645 | 1020 if (global_install) |
6496 | 1021 if (length (remaining_packages) == 0) |
1022 unlink (global_list); | |
1023 else | |
6695 | 1024 global_packages = save_order (remaining_packages); |
6496 | 1025 save (global_list, "global_packages"); |
1026 endif | |
1027 else | |
1028 if (length (remaining_packages) == 0) | |
1029 unlink (local_list); | |
1030 else | |
6695 | 1031 local_packages = save_order (remaining_packages); |
6496 | 1032 save (local_list, "local_packages"); |
1033 endif | |
1034 endif | |
1035 | |
1036 endfunction | |
1037 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1038 function [pkg_desc_list, flag] = describe (pkgnames, verbose, |
10549 | 1039 local_list, global_list) |
7497 | 1040 |
8506 | 1041 ## Get the list of installed packages. |
7497 | 1042 installed_pkgs_lst = installed_packages(local_list, global_list); |
7498 | 1043 num_packages = length (installed_pkgs_lst); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1044 |
7497 | 1045 |
7498 | 1046 describe_all = false; |
1047 if (any (strcmp ("all", pkgnames))) | |
1048 describe_all = true; | |
8455
fd11a08a9b31
disallow invalid {}-indexed assigments
Jaroslav Hajek <highegg@gmail.com>
parents:
8202
diff
changeset
|
1049 flag(1:num_packages) = {"Not Loaded"}; |
7498 | 1050 num_pkgnames = num_packages; |
7497 | 1051 else |
7498 | 1052 num_pkgnames = length (pkgnames); |
8455
fd11a08a9b31
disallow invalid {}-indexed assigments
Jaroslav Hajek <highegg@gmail.com>
parents:
8202
diff
changeset
|
1053 flag(1:num_pkgnames) = {"Not installed"}; |
7498 | 1054 endif |
7497 | 1055 |
1056 for i = 1:num_packages | |
8507 | 1057 curr_name = installed_pkgs_lst{i}.name; |
7497 | 1058 if (describe_all) |
1059 name_pos = i; | |
1060 else | |
1061 name_pos = find(strcmp (curr_name, pkgnames)); | |
7498 | 1062 endif |
1063 | |
1064 if (! isempty (name_pos)) | |
7497 | 1065 if (installed_pkgs_lst{i}.loaded) |
10549 | 1066 flag{name_pos} = "Loaded"; |
7497 | 1067 else |
10549 | 1068 flag{name_pos} = "Not loaded"; |
7497 | 1069 endif |
1070 | |
7498 | 1071 pkg_desc_list{name_pos}.name = installed_pkgs_lst{i}.name; |
9258
a653c61ee98c
let pkg describe return version information
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9220
diff
changeset
|
1072 pkg_desc_list{name_pos}.version = installed_pkgs_lst{i}.version; |
7498 | 1073 pkg_desc_list{name_pos}.description = installed_pkgs_lst{i}.description; |
1074 pkg_desc_list{name_pos}.provides = parse_pkg_idx (installed_pkgs_lst{i}.dir); | |
7497 | 1075 |
1076 endif | |
1077 endfor | |
1078 | |
7498 | 1079 non_inst = find (strcmp (flag, "Not installed")); |
9220
70177bf9cc16
Fix bug when calling pkg describe to check whether a package is installed
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9153
diff
changeset
|
1080 if (! isempty (non_inst)) |
70177bf9cc16
Fix bug when calling pkg describe to check whether a package is installed
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9153
diff
changeset
|
1081 if (nargout < 2) |
70177bf9cc16
Fix bug when calling pkg describe to check whether a package is installed
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9153
diff
changeset
|
1082 non_inst_str = sprintf (" %s ", pkgnames{non_inst}); |
70177bf9cc16
Fix bug when calling pkg describe to check whether a package is installed
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9153
diff
changeset
|
1083 error ("some packages are not installed: %s", non_inst_str); |
70177bf9cc16
Fix bug when calling pkg describe to check whether a package is installed
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9153
diff
changeset
|
1084 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1085 pkg_desc_list{non_inst} = struct ("name", {}, "description", |
10549 | 1086 {}, "provides", {}); |
9220
70177bf9cc16
Fix bug when calling pkg describe to check whether a package is installed
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9153
diff
changeset
|
1087 endif |
7497 | 1088 endif |
1089 | |
1090 if (nargout == 0) | |
7498 | 1091 for i = 1:num_pkgnames |
9258
a653c61ee98c
let pkg describe return version information
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9220
diff
changeset
|
1092 print_package_description (pkg_desc_list{i}.name, |
10549 | 1093 pkg_desc_list{i}.version, |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1094 pkg_desc_list{i}.provides, |
10549 | 1095 pkg_desc_list{i}.description, |
1096 flag{i}, verbose); | |
7497 | 1097 endfor |
1098 endif | |
1099 | |
1100 endfunction | |
1101 | |
8506 | 1102 ## AUXILIARY FUNCTIONS |
6496 | 1103 |
8506 | 1104 ## Read an INDEX file. |
7498 | 1105 function [pkg_idx_struct] = parse_pkg_idx (packdir) |
7497 | 1106 |
7498 | 1107 index_file = fullfile (packdir, "packinfo", "INDEX"); |
1108 | |
1109 if (! exist (index_file, "file")) | |
1110 error ("could not find any INDEX file in directory %s, try 'pkg rebuild all' to generate missing INDEX files", packdir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1111 endif |
7497 | 1112 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1113 |
7498 | 1114 [fid, msg] = fopen (index_file, "r"); |
7497 | 1115 if (fid == -1) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1116 error ("the INDEX file %s could not be read: %s", |
10549 | 1117 index_file, msg); |
7497 | 1118 endif |
7498 | 1119 |
7497 | 1120 cat_num = 1; |
1121 pkg_idx_struct{1}.category = "Uncategorized"; | |
1122 pkg_idx_struct{1}.functions = {}; | |
1123 | |
7498 | 1124 line = fgetl (fid); |
1125 while (isempty (strfind (line, ">>")) && ! feof (fid)) | |
1126 line = fgetl (fid); | |
7497 | 1127 endwhile |
1128 | |
7498 | 1129 while (! feof (fid) || line != -1) |
1130 if (! any (! isspace (line)) || line(1) == "#" || any (line == "=")) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1131 ## Comments, blank lines or comments about unimplemented |
7497 | 1132 ## functions: do nothing |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8174
diff
changeset
|
1133 ## FIXME: probably comments and pointers to external functions |
7497 | 1134 ## could be treated better when printing to screen? |
7498 | 1135 elseif (! isempty (strfind (line, ">>"))) |
8506 | 1136 ## Skip package name and description as they are in DESCRIPTION |
1137 ## already. | |
7498 | 1138 elseif (! isspace (line(1))) |
8506 | 1139 ## Category. |
7498 | 1140 if (! isempty (pkg_idx_struct{cat_num}.functions)) |
10549 | 1141 pkg_idx_struct{++cat_num}.functions = {}; |
7497 | 1142 endif |
7498 | 1143 pkg_idx_struct{cat_num}.category = deblank (line); |
7497 | 1144 else |
8506 | 1145 ## Function names. |
7498 | 1146 while (any (! isspace (line))) |
10549 | 1147 [fun_name, line] = strtok (line); |
1148 pkg_idx_struct{cat_num}.functions{end+1} = deblank (fun_name); | |
7497 | 1149 endwhile |
1150 endif | |
7498 | 1151 line = fgetl (fid); |
7497 | 1152 endwhile |
1153 fclose (fid); | |
1154 endfunction | |
1155 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1156 function print_package_description (pkg_name, pkg_ver, pkg_idx_struct, |
10549 | 1157 pkg_desc, status, verbose) |
7497 | 1158 |
7498 | 1159 printf ("---\nPackage name:\n\t%s\n", pkg_name); |
9258
a653c61ee98c
let pkg describe return version information
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9220
diff
changeset
|
1160 printf ("Version:\n\t%s\n", pkg_ver); |
7498 | 1161 printf ("Short description:\n\t%s\n", pkg_desc); |
1162 printf ("Status:\n\t%s\n", status); | |
7497 | 1163 if (verbose) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1164 printf ("---\nProvides:\n"); |
7498 | 1165 for i = 1:length(pkg_idx_struct) |
1166 if (! isempty (pkg_idx_struct{i}.functions)) | |
10549 | 1167 printf ("%s\n", pkg_idx_struct{i}.category); |
1168 for j = 1:length(pkg_idx_struct{i}.functions) | |
1169 printf ("\t%s\n", pkg_idx_struct{i}.functions{j}); | |
1170 endfor | |
7497 | 1171 endif |
1172 endfor | |
1173 endif | |
1174 | |
1175 endfunction | |
1176 | |
1177 | |
6675 | 1178 function pth = absolute_pathname (pth) |
7498 | 1179 [status, msg, msgid] = fileattrib (pth); |
6729 | 1180 if (status != 1) |
1181 error ("could not find the file or path %s", pth); | |
1182 else | |
1183 pth = msg.Name; | |
1184 endif | |
6675 | 1185 endfunction |
1186 | |
1187 function repackage (builddir, buildlist) | |
1188 packages = installed_packages (buildlist, buildlist); | |
1189 | |
1190 wd = pwd(); | |
1191 for i = 1 : length(packages) | |
1192 pack = packages{i}; | |
1193 unwind_protect | |
1194 cd (builddir); | |
1195 mkdir (pack.name); | |
1196 mkdir (fullfile (pack.name, "inst")); | |
1197 copyfile (fullfile (pack.dir, "*"), fullfile (pack.name, "inst")); | |
1198 movefile (fullfile (pack.name, "inst","packinfo", "*"), pack.name); | |
1199 if (exist (fullfile (pack.name, "inst","packinfo", ".autoload"), "file")) | |
10549 | 1200 unlink (fullfile (pack.name, "inst","packinfo", ".autoload")); |
6675 | 1201 endif |
1202 rmdir (fullfile (pack.name, "inst", "packinfo")); | |
1203 if (exist (fullfile (pack.name, "inst", "doc"), "dir")) | |
10549 | 1204 movefile (fullfile (pack.name, "inst", "doc"), pack.name); |
6675 | 1205 endif |
1206 if (exist (fullfile (pack.name, "inst", "bin"), "dir")) | |
10549 | 1207 movefile (fullfile (pack.name, "inst", "bin"), pack.name); |
6675 | 1208 endif |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1209 archdir = fullfile (pack.archprefix, cstrcat (pack.name, "-", |
10549 | 1210 pack.version), getarch ()); |
6675 | 1211 if (exist (archdir, "dir")) |
10549 | 1212 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file")) |
1213 unlink (fullfile (pack.name, "inst", "PKG_ADD")); | |
1214 endif | |
1215 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file")) | |
1216 unlink (fullfile (pack.name, "inst", "PKG_DEL")); | |
1217 endif | |
1218 if (exist (fullfile (archdir, "PKG_ADD"), "file")) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1219 movefile (fullfile (archdir, "PKG_ADD"), |
10549 | 1220 fullfile (pack.name, "PKG_ADD")); |
1221 endif | |
1222 if (exist (fullfile (archdir, "PKG_DEL"), "file")) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1223 movefile (fullfile (archdir, "PKG_DEL"), |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1224 fullfile (pack.name, "PKG_DEL")); |
10549 | 1225 endif |
6675 | 1226 else |
10549 | 1227 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file")) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1228 movefile (fullfile (pack.name, "inst", "PKG_ADD"), |
10549 | 1229 fullfile (pack.name, "PKG_ADD")); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1230 endif |
10549 | 1231 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file")) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1232 movefile (fullfile (pack.name, "inst", "PKG_DEL"), |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1233 fullfile (pack.name, "PKG_DEL")); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1234 endif |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1235 endif |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1236 tfile = cstrcat (pack.name, "-", pack.version, ".tar"); |
6675 | 1237 tar (tfile, pack.name); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1238 try |
10549 | 1239 gzip (tfile); |
1240 unlink (tfile); | |
6925 | 1241 catch |
10549 | 1242 warning ("failed to compress %s", tfile); |
6925 | 1243 end_try_catch |
6675 | 1244 unwind_protect_cleanup |
1245 if (exist (pack.name, "dir")) | |
10549 | 1246 rm_rf (pack.name); |
6675 | 1247 endif |
1248 cd (wd); | |
1249 end_unwind_protect | |
1250 endfor | |
1251 endfunction | |
1252 | |
1253 function auto = isautoload (desc) | |
6695 | 1254 auto = false; |
1255 if (isfield (desc{1}, "autoload")) | |
1256 a = desc{1}.autoload; | |
1257 if ((isnumeric (a) && a > 0) | |
1258 || (ischar (a) && (strcmpi (a, "true") | |
10549 | 1259 || strcmpi (a, "on") |
1260 || strcmpi (a, "yes") | |
1261 || strcmpi (a, "1")))) | |
6695 | 1262 auto = true; |
1263 endif | |
6675 | 1264 endif |
1265 endfunction | |
1266 | |
6496 | 1267 function prepare_installation (desc, packdir) |
1268 ## Is there a pre_install to call? | |
1269 if (exist (fullfile (packdir, "pre_install.m"), "file")) | |
1270 wd = pwd (); | |
1271 try | |
1272 cd (packdir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1273 pre_install (desc); |
6496 | 1274 cd (wd); |
1275 catch | |
1276 cd (wd); | |
6695 | 1277 rethrow (lasterror ()); |
6496 | 1278 end_try_catch |
1279 endif | |
1280 | |
8506 | 1281 ## If the directory "inst" doesn't exist, we create it. |
6496 | 1282 inst_dir = fullfile (packdir, "inst"); |
1283 if (! exist (inst_dir, "dir")) | |
1284 [status, msg] = mkdir (inst_dir); | |
1285 if (status != 1) | |
1286 rm_rf (desc.dir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1287 error ("the 'inst' directory did not exist and could not be created: %s", |
10549 | 1288 msg); |
6258 | 1289 endif |
1290 endif | |
1291 endfunction | |
1292 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1293 function configure_make (desc, packdir, verbose) |
8506 | 1294 ## Perform ./configure, make, make install in "src". |
6496 | 1295 if (exist (fullfile (packdir, "src"), "dir")) |
1296 src = fullfile (packdir, "src"); | |
12167
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1297 octave_bindir = octave_config_info ("bindir"); |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1298 ver = version (); |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1299 mkoctfile = fullfile (octave_bindir, sprintf ("mkoctfile-%s", ver)); |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1300 octave_config = fullfile (octave_bindir, sprintf ("octave-config-%s", ver)); |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1301 octave_binary = fullfile (octave_bindir, sprintf ("octave-%s", ver)); |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1302 cenv = {"MKOCTFILE"; mkoctfile; |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1303 "OCTAVE_CONFIG"; octave_config; |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1304 "OCTAVE"; octave_binary; |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1305 "INSTALLDIR"; desc.dir}; |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1306 scenv = sprintf ("%s=\"%s\" ", cenv{:}); |
8506 | 1307 ## Configure. |
6496 | 1308 if (exist (fullfile (src, "configure"), "file")) |
7111 | 1309 flags = ""; |
1310 if (isempty (getenv ("CC"))) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1311 flags = cstrcat (flags, " CC=\"", octave_config_info ("CC"), "\""); |
7111 | 1312 endif |
1313 if (isempty (getenv ("CXX"))) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1314 flags = cstrcat (flags, " CXX=\"", octave_config_info ("CXX"), "\""); |
7111 | 1315 endif |
1316 if (isempty (getenv ("AR"))) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1317 flags = cstrcat (flags, " AR=\"", octave_config_info ("AR"), "\""); |
7111 | 1318 endif |
1319 if (isempty (getenv ("RANLIB"))) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1320 flags = cstrcat (flags, " RANLIB=\"", octave_config_info ("RANLIB"), "\""); |
7111 | 1321 endif |
12167
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1322 [status, output] = shell (cstrcat ("cd '", src, "'; ", scenv, |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1323 "./configure --prefix=\"", |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1324 desc.dir, "\"", flags)); |
6496 | 1325 if (status != 0) |
10549 | 1326 rm_rf (desc.dir); |
1327 error ("the configure script returned the following error: %s", output); | |
6675 | 1328 elseif (verbose) |
10549 | 1329 printf("%s", output); |
6496 | 1330 endif |
6675 | 1331 |
5801 | 1332 endif |
1333 | |
8506 | 1334 ## Make. |
6496 | 1335 if (exist (fullfile (src, "Makefile"), "file")) |
12167
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1336 [status, output] = shell (cstrcat (scenv, "make -C '", src, "'")); |
6496 | 1337 if (status != 0) |
10549 | 1338 rm_rf (desc.dir); |
1339 error ("'make' returned the following error: %s", output); | |
6675 | 1340 elseif (verbose) |
10549 | 1341 printf("%s", output); |
6496 | 1342 endif |
5801 | 1343 endif |
1344 | |
8506 | 1345 ## Copy files to "inst" and "inst/arch" (this is instead of 'make |
1346 ## install'). | |
6496 | 1347 files = fullfile (src, "FILES"); |
1348 instdir = fullfile (packdir, "inst"); | |
6614 | 1349 archdir = fullfile (packdir, "inst", getarch ()); |
6950 | 1350 |
8506 | 1351 ## Get file names. |
6496 | 1352 if (exist (files, "file")) |
1353 [fid, msg] = fopen (files, "r"); | |
1354 if (fid < 0) | |
10549 | 1355 error ("couldn't open %s: %s", files, msg); |
5971 | 1356 endif |
6496 | 1357 filenames = char (fread (fid))'; |
1358 fclose (fid); | |
1359 if (filenames(end) == "\n") | |
10549 | 1360 filenames(end) = []; |
6258 | 1361 endif |
6655 | 1362 filenames = split_by (filenames, "\n"); |
6496 | 1363 delete_idx = []; |
6655 | 1364 for i = 1:length (filenames) |
10549 | 1365 if (! all (isspace (filenames{i}))) |
1366 filenames{i} = fullfile (src, filenames{i}); | |
1367 else | |
1368 delete_idx(end+1) = i; | |
1369 endif | |
5971 | 1370 endfor |
6655 | 1371 filenames(delete_idx) = []; |
6496 | 1372 else |
1373 m = dir (fullfile (src, "*.m")); | |
1374 oct = dir (fullfile (src, "*.oct")); | |
1375 mex = dir (fullfile (src, "*.mex")); | |
8174
ea9b5f31bfac
pkg.m: better handling of filenames with spaces
John W. Eaton <jwe@octave.org>
parents:
8172
diff
changeset
|
1376 |
ea9b5f31bfac
pkg.m: better handling of filenames with spaces
John W. Eaton <jwe@octave.org>
parents:
8172
diff
changeset
|
1377 filenames = cellfun (@(x) fullfile (src, x), |
10549 | 1378 {m.name, oct.name, mex.name}, |
11191
01ddaedd6ad5
Reverse changeset b1f4bdc276b6. Use all lower case for "uniformoutput" option.
Rik <octave@nomad.inbox5.com>
parents:
11190
diff
changeset
|
1379 "uniformoutput", false); |
5971 | 1380 endif |
5801 | 1381 |
8506 | 1382 ## Split into architecture dependent and independent files. |
7024 | 1383 if (isempty (filenames)) |
1384 idx = []; | |
1385 else | |
8043
30d15ab0ce01
avoid problematic subfunction call in an anonymous function
Jaroslav Hajek <highegg@gmail.com>
parents:
7739
diff
changeset
|
1386 idx = cellfun (@is_architecture_dependent, filenames); |
7024 | 1387 endif |
6950 | 1388 archdependent = filenames (idx); |
1389 archindependent = filenames (!idx); | |
1390 | |
8506 | 1391 ## Copy the files. |
7548
9cbf1e2011a3
pkg.m: adapt to changes in isspace for cell arrays of strings.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7540
diff
changeset
|
1392 if (! all (isspace ([filenames{:}]))) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1393 if (! exist (instdir, "dir")) |
10549 | 1394 mkdir (instdir); |
1395 endif | |
1396 if (! all (isspace ([archindependent{:}]))) | |
1397 if (verbose) | |
1398 printf ("copyfile"); | |
1399 printf (" %s", archindependent{:}); | |
1400 printf ("%s\n", instdir); | |
1401 endif | |
1402 [status, output] = copyfile (archindependent, instdir); | |
1403 if (status != 1) | |
1404 rm_rf (desc.dir); | |
1405 error ("Couldn't copy files from 'src' to 'inst': %s", output); | |
1406 endif | |
6614 | 1407 endif |
10549 | 1408 if (! all (isspace ([archdependent{:}]))) |
1409 if (verbose) | |
1410 printf ("copyfile"); | |
1411 printf (" %s", archdependent{:}); | |
1412 printf (" %s\n", archdir); | |
1413 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1414 if (! exist (archdir, "dir")) |
10549 | 1415 mkdir (archdir); |
1416 endif | |
1417 [status, output] = copyfile (archdependent, archdir); | |
1418 if (status != 1) | |
1419 rm_rf (desc.dir); | |
1420 error ("Couldn't copy files from 'src' to 'inst': %s", output); | |
1421 endif | |
6614 | 1422 endif |
5801 | 1423 endif |
6496 | 1424 endif |
5801 | 1425 endfunction |
1426 | |
5971 | 1427 function pkg = extract_pkg (nm, pat) |
5955 | 1428 fid = fopen (nm, "rt"); |
5971 | 1429 pkg = ""; |
5955 | 1430 if (fid >= 0) |
6496 | 1431 while (! feof (fid)) |
5955 | 1432 ln = fgetl (fid); |
1433 if (ln > 0) | |
10549 | 1434 t = regexp (ln, pat, "tokens"); |
1435 if (! isempty (t)) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1436 pkg = cstrcat (pkg, "\n", t{1}{1}); |
10549 | 1437 endif |
5955 | 1438 endif |
1439 endwhile | |
6496 | 1440 if (! isempty (pkg)) |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1441 pkg = cstrcat (pkg, "\n"); |
5955 | 1442 endif |
1443 fclose (fid); | |
1444 endif | |
1445 endfunction | |
1446 | |
6925 | 1447 function create_pkgadddel (desc, packdir, nm, global_install) |
6675 | 1448 instpkg = fullfile (desc.dir, nm); |
1449 instfid = fopen (instpkg, "wt"); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1450 ## If it is exists, most of the PKG_* file should go into the |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1451 ## architecture dependent directory so that the autoload/mfilename |
6675 | 1452 ## commands work as expected. The only part that doesn't is the |
1453 ## part in the main directory. | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1454 archdir = fullfile (getarchprefix (desc), cstrcat (desc.name, "-", |
10549 | 1455 desc.version), getarch ()); |
6925 | 1456 if (exist (getarchdir (desc, global_install), "dir")) |
1457 archpkg = fullfile (getarchdir (desc, global_install), nm); | |
1458 archfid = fopen (archpkg, "at"); | |
6675 | 1459 else |
1460 archpkg = instpkg; | |
1461 archfid = instfid; | |
1462 endif | |
6634 | 1463 |
6675 | 1464 if (archfid >= 0 && instfid >= 0) |
8506 | 1465 ## Search all dot-m files for PKG commands. |
7498 | 1466 lst = dir (fullfile (packdir, "inst", "*.m")); |
6496 | 1467 for i = 1:length (lst) |
7498 | 1468 nam = fullfile (packdir, "inst", lst(i).name); |
6675 | 1469 fwrite (instfid, extract_pkg (nam, ['^[#%][#%]* *' nm ': *(.*)$'])); |
5955 | 1470 endfor |
1471 | |
8506 | 1472 ## Search all C++ source files for PKG commands. |
7498 | 1473 lst = dir (fullfile (packdir, "src", "*.cc")); |
6496 | 1474 for i = 1:length (lst) |
7498 | 1475 nam = fullfile (packdir, "src", lst(i).name); |
6675 | 1476 fwrite (archfid, extract_pkg (nam, ['^//* *' nm ': *(.*)$'])); |
1477 fwrite (archfid, extract_pkg (nam, ['^/\** *' nm ': *(.*) *\*/$'])); | |
5955 | 1478 endfor |
1479 | |
8506 | 1480 ## Add developer included PKG commands. |
6496 | 1481 packdirnm = fullfile (packdir, nm); |
1482 if (exist (packdirnm, "file")) | |
6675 | 1483 fid = fopen (packdirnm, "rt"); |
1484 if (fid >= 0) | |
1485 while (! feof (fid)) | |
1486 ln = fgets (fid); | |
5955 | 1487 if (ln > 0) |
6675 | 1488 fwrite (archfid, ln); |
5955 | 1489 endif |
1490 endwhile | |
6675 | 1491 fclose (fid); |
5955 | 1492 endif |
1493 endif | |
5971 | 1494 |
8506 | 1495 ## If the files is empty remove it. |
6675 | 1496 fclose (instfid); |
1497 t = dir (instpkg); | |
5971 | 1498 if (t.bytes <= 0) |
6675 | 1499 unlink (instpkg); |
1500 endif | |
1501 | |
1502 if (instfid != archfid) | |
1503 fclose (archfid); | |
1504 t = dir (archpkg); | |
1505 if (t.bytes <= 0) | |
1506 unlink (archpkg); | |
1507 endif | |
5971 | 1508 endif |
5955 | 1509 endif |
1510 endfunction | |
1511 | |
6925 | 1512 function copy_files (desc, packdir, global_install) |
8506 | 1513 ## Create the installation directory. |
6496 | 1514 if (! exist (desc.dir, "dir")) |
1515 [status, output] = mkdir (desc.dir); | |
1516 if (status != 1) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1517 error ("couldn't create installation directory %s : %s", |
6496 | 1518 desc.dir, output); |
6020 | 1519 endif |
6496 | 1520 endif |
6020 | 1521 |
6925 | 1522 octfiledir = getarchdir (desc); |
1523 | |
8506 | 1524 ## Copy the files from "inst" to installdir. |
6496 | 1525 instdir = fullfile (packdir, "inst"); |
1526 if (! dirempty (instdir)) | |
1527 [status, output] = copyfile (fullfile (instdir, "*"), desc.dir); | |
1528 if (status != 1) | |
1529 rm_rf (desc.dir); | |
1530 error ("couldn't copy files to the installation directory"); | |
5801 | 1531 endif |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
1532 if (exist (fullfile (desc.dir, getarch ()), "dir") |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
1533 && ! strcmp (fullfile (desc.dir, getarch ()), octfiledir)) |
6925 | 1534 if (! exist (octfiledir, "dir")) |
8506 | 1535 ## Can be required to create upto three levels of dirs. |
6925 | 1536 octm1 = fileparts (octfiledir); |
1537 if (! exist (octm1, "dir")) | |
1538 octm2 = fileparts (octm1); | |
1539 if (! exist (octm2, "dir")) | |
1540 octm3 = fileparts (octm2); | |
1541 if (! exist (octm3, "dir")) | |
1542 [status, output] = mkdir (octm3); | |
1543 if (status != 1) | |
1544 rm_rf (desc.dir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1545 error ("couldn't create installation directory %s : %s", |
6925 | 1546 octm3, output); |
1547 endif | |
1548 endif | |
1549 [status, output] = mkdir (octm2); | |
1550 if (status != 1) | |
1551 rm_rf (desc.dir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1552 error ("couldn't create installation directory %s : %s", |
6925 | 1553 octm2, output); |
1554 endif | |
1555 endif | |
1556 [status, output] = mkdir (octm1); | |
1557 if (status != 1) | |
1558 rm_rf (desc.dir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1559 error ("couldn't create installation directory %s : %s", |
6925 | 1560 octm1, output); |
1561 endif | |
1562 endif | |
1563 [status, output] = mkdir (octfiledir); | |
1564 if (status != 1) | |
1565 rm_rf (desc.dir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1566 error ("couldn't create installation directory %s : %s", |
6925 | 1567 octfiledir, output); |
1568 endif | |
1569 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1570 [status, output] = movefile (fullfile (desc.dir, getarch (), "*"), |
10549 | 1571 octfiledir); |
6925 | 1572 rm_rf (fullfile (desc.dir, getarch ())); |
1573 | |
1574 if (status != 1) | |
1575 rm_rf (desc.dir); | |
1576 rm_rf (octfiledir); | |
1577 error ("couldn't copy files to the installation directory"); | |
1578 endif | |
1579 endif | |
1580 | |
6496 | 1581 endif |
5801 | 1582 |
8506 | 1583 ## Create the "packinfo" directory. |
6496 | 1584 packinfo = fullfile (desc.dir, "packinfo"); |
1585 [status, msg] = mkdir (packinfo); | |
1586 if (status != 1) | |
1587 rm_rf (desc.dir); | |
6925 | 1588 rm_rf (octfiledir); |
6496 | 1589 error ("couldn't create packinfo directory: %s", msg); |
1590 endif | |
5801 | 1591 |
8506 | 1592 ## Copy DESCRIPTION. |
6496 | 1593 [status, output] = copyfile (fullfile (packdir, "DESCRIPTION"), packinfo); |
1594 if (status != 1) | |
6925 | 1595 rm_rf (desc.dir); |
1596 rm_rf (octfiledir); | |
1597 error ("couldn't copy DESCRIPTION: %s", output); | |
6496 | 1598 endif |
5801 | 1599 |
8506 | 1600 ## Copy COPYING. |
6496 | 1601 [status, output] = copyfile (fullfile (packdir, "COPYING"), packinfo); |
1602 if (status != 1) | |
6925 | 1603 rm_rf (desc.dir); |
1604 rm_rf (octfiledir); | |
1605 error ("couldn't copy COPYING: %s", output); | |
6496 | 1606 endif |
5993 | 1607 |
8506 | 1608 ## If the file ChangeLog exists, copy it. |
7498 | 1609 changelog_file = fullfile (packdir, "ChangeLog"); |
1610 if (exist (changelog_file, "file")) | |
1611 [status, output] = copyfile (changelog_file, packinfo); | |
6496 | 1612 if (status != 1) |
1613 rm_rf (desc.dir); | |
6925 | 1614 rm_rf (octfiledir); |
6496 | 1615 error ("couldn't copy ChangeLog file: %s", output); |
6254 | 1616 endif |
6496 | 1617 endif |
6254 | 1618 |
6496 | 1619 ## Is there an INDEX file to copy or should we generate one? |
7498 | 1620 index_file = fullfile (packdir, "INDEX"); |
1621 if (exist(index_file, "file")) | |
1622 [status, output] = copyfile (index_file, packinfo); | |
6496 | 1623 if (status != 1) |
1624 rm_rf (desc.dir); | |
6925 | 1625 rm_rf (octfiledir); |
6496 | 1626 error ("couldn't copy INDEX file: %s", output); |
5801 | 1627 endif |
6496 | 1628 else |
1629 try | |
7498 | 1630 write_index (desc, fullfile (packdir, "inst"), |
10549 | 1631 fullfile (packinfo, "INDEX"), global_install); |
6496 | 1632 catch |
1633 rm_rf (desc.dir); | |
6925 | 1634 rm_rf (octfiledir); |
6695 | 1635 rethrow (lasterror ()); |
6496 | 1636 end_try_catch |
1637 endif | |
5971 | 1638 |
6496 | 1639 ## Is there an 'on_uninstall.m' to install? |
7498 | 1640 fon_uninstall = fullfile (packdir, "on_uninstall.m"); |
6496 | 1641 if (exist (fon_uninstall, "file")) |
1642 [status, output] = copyfile (fon_uninstall, packinfo); | |
1643 if (status != 1) | |
1644 rm_rf (desc.dir); | |
6925 | 1645 rm_rf (octfiledir); |
6496 | 1646 error ("couldn't copy on_uninstall.m: %s", output); |
5971 | 1647 endif |
6496 | 1648 endif |
5971 | 1649 |
8506 | 1650 ## Is there a doc/ directory that needs to be installed? |
6496 | 1651 docdir = fullfile (packdir, "doc"); |
1652 if (exist (docdir, "dir") && ! dirempty (docdir)) | |
6925 | 1653 [status, output] = copyfile (docdir, desc.dir); |
6496 | 1654 endif |
1655 | |
8506 | 1656 ## Is there a bin/ directory that needs to be installed? |
6950 | 1657 ## FIXME: Need to treat architecture dependent files in bin/ |
6496 | 1658 bindir = fullfile (packdir, "bin"); |
1659 if (exist (bindir, "dir") && ! dirempty (bindir)) | |
6925 | 1660 [status, output] = copyfile (bindir, desc.dir); |
6496 | 1661 endif |
5801 | 1662 endfunction |
1663 | |
6925 | 1664 function finish_installation (desc, packdir, global_install) |
6496 | 1665 ## Is there a post-install to call? |
1666 if (exist (fullfile (packdir, "post_install.m"), "file")) | |
1667 wd = pwd (); | |
1668 try | |
1669 cd (packdir); | |
1670 post_install (desc); | |
1671 cd (wd); | |
1672 catch | |
1673 cd (wd); | |
1674 rm_rf (desc.dir); | |
6925 | 1675 rm_rf (getarchdir (desc), global_install); |
6695 | 1676 rethrow (lasterror ()); |
6496 | 1677 end_try_catch |
1678 endif | |
5801 | 1679 endfunction |
1680 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
1681 function generate_lookfor_cache (desc) |
8863
34a821854961
pkg.m (generate_lookfor_cache): generate a DOC file for each directory
Jason Riedy <jason@acm.org>
parents:
8746
diff
changeset
|
1682 dirs = split_by (genpath (desc.dir), pathsep ()); |
34a821854961
pkg.m (generate_lookfor_cache): generate a DOC file for each directory
Jason Riedy <jason@acm.org>
parents:
8746
diff
changeset
|
1683 for i = 1 : length (dirs) |
8942
c4383701e10d
use doc-cache instead of DOC for doc cache file name
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
1684 gen_doc_cache (fullfile (dirs{i}, "doc-cache"), dirs{i}); |
8863
34a821854961
pkg.m (generate_lookfor_cache): generate a DOC file for each directory
Jason Riedy <jason@acm.org>
parents:
8746
diff
changeset
|
1685 endfor |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
1686 endfunction |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
1687 |
7498 | 1688 ## Make sure the package contains the essential files. |
6496 | 1689 function verify_directory (dir) |
1690 needed_files = {"COPYING", "DESCRIPTION"}; | |
1691 for f = needed_files | |
1692 if (! exist (fullfile (dir, f{1}), "file")) | |
1693 error ("package is missing file: %s", f{1}); | |
1694 endif | |
1695 endfor | |
5801 | 1696 endfunction |
1697 | |
8506 | 1698 ## Parse the DESCRIPTION file. |
6496 | 1699 function desc = get_description (filename) |
1700 [fid, msg] = fopen (filename, "r"); | |
1701 if (fid == -1) | |
1702 error ("the DESCRIPTION file %s could not be read: %s", filename, msg); | |
1703 endif | |
1704 | |
1705 desc = struct (); | |
5801 | 1706 |
6496 | 1707 line = fgetl (fid); |
1708 while (line != -1) | |
1709 if (line(1) == "#") | |
8506 | 1710 ## Comments, do nothing. |
6496 | 1711 elseif (isspace(line(1))) |
1712 ## Continuation lines | |
1713 if (exist ("keyword", "var") && isfield (desc, keyword)) | |
10549 | 1714 desc.(keyword) = cstrcat (desc.(keyword), " ", rstrip(line)); |
6496 | 1715 endif |
5801 | 1716 else |
6496 | 1717 ## Keyword/value pair |
1718 colon = find (line == ":"); | |
1719 if (length (colon) == 0) | |
10549 | 1720 disp ("skipping line"); |
6496 | 1721 else |
10549 | 1722 colon = colon(1); |
1723 keyword = tolower (strip (line(1:colon-1))); | |
1724 value = strip (line (colon+1:end)); | |
1725 if (length (value) == 0) | |
1726 fclose (fid); | |
1727 error ("the keyword %s has an empty value", desc.keywords{end}); | |
1728 endif | |
1729 desc.(keyword) = value; | |
6496 | 1730 endif |
5801 | 1731 endif |
6496 | 1732 line = fgetl (fid); |
1733 endwhile | |
1734 fclose (fid); | |
1735 | |
8506 | 1736 ## Make sure all is okay. |
6496 | 1737 needed_fields = {"name", "version", "date", "title", ... |
10549 | 1738 "author", "maintainer", "description"}; |
6496 | 1739 for f = needed_fields |
1740 if (! isfield (desc, f{1})) | |
1741 error ("description is missing needed field %s", f{1}); | |
1742 endif | |
1743 endfor | |
1744 desc.version = fix_version (desc.version); | |
1745 if (isfield (desc, "depends")) | |
1746 desc.depends = fix_depends (desc.depends); | |
1747 else | |
1748 desc.depends = ""; | |
1749 endif | |
1750 desc.name = tolower (desc.name); | |
5801 | 1751 endfunction |
1752 | |
7498 | 1753 ## Make sure the version string v is a valid x.y.z version string |
8506 | 1754 ## Examples: "0.1" => "0.1.0", "monkey" => error(...). |
6496 | 1755 function out = fix_version (v) |
1756 dots = find (v == "."); | |
1757 if (length (dots) == 1) | |
1758 major = str2num (v(1:dots-1)); | |
1759 minor = str2num (v(dots+1:end)); | |
1760 if (length (major) != 0 && length (minor) != 0) | |
1761 out = sprintf ("%d.%d.0", major, minor); | |
1762 return; | |
5801 | 1763 endif |
6496 | 1764 elseif (length (dots) == 2) |
1765 major = str2num (v(1:dots(1)-1)); | |
1766 minor = str2num (v(dots(1)+1:dots(2)-1)); | |
7498 | 1767 rev = str2num (v(dots(2)+1:end)); |
6496 | 1768 if (length (major) != 0 && length (minor) != 0 && length (rev) != 0) |
1769 out = sprintf ("%d.%d.%d", major, minor, rev); | |
1770 return; | |
1771 endif | |
1772 endif | |
1773 error ("bad version string: %s", v); | |
5801 | 1774 endfunction |
1775 | |
7498 | 1776 ## Make sure the depends field is of the right format. |
5801 | 1777 ## This function returns a cell of structures with the following fields: |
1778 ## package, version, operator | |
6496 | 1779 function deps_cell = fix_depends (depends) |
1780 deps = split_by (tolower (depends), ","); | |
1781 deps_cell = cell (1, length (deps)); | |
1782 | |
8506 | 1783 ## For each dependency. |
6496 | 1784 for i = 1:length (deps) |
1785 dep = deps{i}; | |
1786 lpar = find (dep == "("); | |
1787 rpar = find (dep == ")"); | |
1788 ## Does the dependency specify a version | |
8506 | 1789 ## Example: package(>= version). |
6496 | 1790 if (length (lpar) == 1 && length (rpar) == 1) |
1791 package = tolower (strip (dep(1:lpar-1))); | |
1792 sub = dep(lpar(1)+1:rpar(1)-1); | |
8900
63ad1133d0ed
fix & simplify fix_depends pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
8877
diff
changeset
|
1793 parts = strsplit (sub, " ", true); |
63ad1133d0ed
fix & simplify fix_depends pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
8877
diff
changeset
|
1794 if (length (parts) != 2) |
10549 | 1795 error ("incorrect syntax for dependency `%s' in the DESCRIPTION file\n", |
1796 dep); | |
6496 | 1797 endif |
8900
63ad1133d0ed
fix & simplify fix_depends pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
8877
diff
changeset
|
1798 operator = parts{1}; |
6496 | 1799 if (! any (strcmp (operator, {">", ">=", "<=", "<", "=="}))) |
10549 | 1800 error ("unsupported operator: %s", operator); |
6496 | 1801 endif |
8900
63ad1133d0ed
fix & simplify fix_depends pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
8877
diff
changeset
|
1802 version = fix_version (parts{2}); |
6496 | 1803 |
1804 ## If no version is specified for the dependency | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1805 ## we say that the version should be greater than |
8506 | 1806 ## or equal to "0.0.0". |
6496 | 1807 else |
1808 package = tolower (strip (dep)); | |
1809 operator = ">="; | |
1810 version = "0.0.0"; | |
1811 endif | |
1812 deps_cell{i} = struct ("package", package, "operator", operator, | |
10549 | 1813 "version", version); |
6496 | 1814 endfor |
5801 | 1815 endfunction |
1816 | |
7498 | 1817 ## Strip the text of spaces from the right |
8506 | 1818 ## Example: " hello world " => " hello world" |
1819 ## FIXME -- is this the same as deblank? | |
6496 | 1820 function text = rstrip (text) |
1821 chars = find (! isspace (text)); | |
1822 if (length (chars) > 0) | |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8174
diff
changeset
|
1823 ## FIXME: shouldn't it be text = text(1:chars(end)); |
6496 | 1824 text = text (chars(1):end); |
1825 else | |
1826 text = ""; | |
1827 endif | |
5801 | 1828 endfunction |
1829 | |
8506 | 1830 ## Strip the text of spaces from the left and the right. |
5801 | 1831 ## Example: " hello world " => "hello world" |
6496 | 1832 function text = strip (text) |
1833 chars = find (! isspace (text)); | |
1834 if (length (chars) > 0) | |
1835 text = text(chars(1):chars(end)); | |
1836 else | |
1837 text = ""; | |
1838 endif | |
5801 | 1839 endfunction |
1840 | |
8506 | 1841 ## Split the text into a cell array of strings by sep. |
5801 | 1842 ## Example: "A, B" => {"A", "B"} (with sep = ",") |
6496 | 1843 function out = split_by (text, sep) |
8877
2c8b2399247b
implement strsplit; deprecate split
Jaroslav Hajek <highegg@gmail.com>
parents:
8863
diff
changeset
|
1844 out = strtrim (strsplit (text, sep)); |
5801 | 1845 endfunction |
1846 | |
7498 | 1847 ## Create an INDEX file for a package that doesn't provide one. |
5801 | 1848 ## 'desc' describes the package. |
7498 | 1849 ## 'dir' is the 'inst' directory in temporary directory. |
1850 ## 'index_file' is the name (including path) of resulting INDEX file. | |
1851 function write_index (desc, dir, index_file, global_install) | |
6496 | 1852 ## Get names of functions in dir |
1853 [files, err, msg] = readdir (dir); | |
1854 if (err) | |
1855 error ("couldn't read directory %s: %s", dir, msg); | |
1856 endif | |
1857 | |
10401
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1858 ## Get classes in dir |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1859 class_idx = strmatch ("@", files); |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1860 for k = 1:length (class_idx) |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1861 class_name = files {class_idx (k)}; |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1862 class_dir = fullfile (dir, class_name); |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1863 if (exist (class_dir, "dir")) |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1864 [files2, err, msg] = readdir (class_dir); |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1865 if (err) |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1866 error ("couldn't read directory %s: %s", class_dir, msg); |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1867 endif |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1868 files2 = strcat (class_name, filesep (), files2); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1869 files = [files; files2]; |
10401
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1870 endif |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1871 endfor |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1872 |
8506 | 1873 ## Check for architecture dependent files. |
6925 | 1874 tmpdir = getarchdir (desc); |
6634 | 1875 if (exist (tmpdir, "dir")) |
1876 [files2, err, msg] = readdir (tmpdir); | |
1877 if (err) | |
1878 error ("couldn't read directory %s: %s", tmpdir, msg); | |
1879 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1880 files = [files; files2]; |
6634 | 1881 endif |
1882 | |
6496 | 1883 functions = {}; |
1884 for i = 1:length (files) | |
1885 file = files{i}; | |
1886 lf = length (file); | |
1887 if (lf > 2 && strcmp (file(end-1:end), ".m")) | |
1888 functions{end+1} = file(1:end-2); | |
1889 elseif (lf > 4 && strcmp (file(end-3:end), ".oct")) | |
1890 functions{end+1} = file(1:end-4); | |
5801 | 1891 endif |
6496 | 1892 endfor |
1893 | |
1894 ## Does desc have a categories field? | |
1895 if (! isfield (desc, "categories")) | |
1896 error ("the DESCRIPTION file must have a Categories field, when no INDEX file is given"); | |
1897 endif | |
1898 categories = split_by (desc.categories, ","); | |
1899 if (length (categories) < 1) | |
1900 error ("the Category field is empty"); | |
1901 endif | |
1902 | |
8506 | 1903 ## Write INDEX. |
7498 | 1904 fid = fopen (index_file, "w"); |
6496 | 1905 if (fid == -1) |
11588
d5bd2766c640
style fixes for warning and error messages in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
1906 error ("couldn't open %s for writing", index_file); |
6496 | 1907 endif |
1908 fprintf (fid, "%s >> %s\n", desc.name, desc.title); | |
1909 fprintf (fid, "%s\n", categories{1}); | |
1910 fprintf (fid, " %s\n", functions{:}); | |
1911 fclose (fid); | |
5801 | 1912 endfunction |
1913 | |
6820 | 1914 function bad_deps = get_unsatisfied_deps (desc, installed_pkgs_lst) |
6496 | 1915 bad_deps = {}; |
5801 | 1916 |
8506 | 1917 ## For each dependency. |
6496 | 1918 for i = 1:length (desc.depends) |
1919 dep = desc.depends{i}; | |
5801 | 1920 |
6496 | 1921 ## Is the current dependency Octave? |
1922 if (strcmp (dep.package, "octave")) | |
1923 if (! compare_versions (OCTAVE_VERSION, dep.version, dep.operator)) | |
1924 bad_deps{end+1} = dep; | |
6258 | 1925 endif |
8506 | 1926 ## Is the current dependency not Octave? |
6496 | 1927 else |
1928 ok = false; | |
6820 | 1929 for i = 1:length (installed_pkgs_lst) |
10549 | 1930 cur_name = installed_pkgs_lst{i}.name; |
1931 cur_version = installed_pkgs_lst{i}.version; | |
1932 if (strcmp (dep.package, cur_name) | |
1933 && compare_versions (cur_version, dep.version, dep.operator)) | |
1934 ok = true; | |
1935 break; | |
1936 endif | |
6258 | 1937 endfor |
6496 | 1938 if (! ok) |
1939 bad_deps{end+1} = dep; | |
1940 endif | |
5801 | 1941 endif |
6496 | 1942 endfor |
1943 endfunction | |
1944 | |
1945 function [out1, out2] = installed_packages (local_list, global_list) | |
8506 | 1946 ## Get the list of installed packages. |
6496 | 1947 try |
1948 local_packages = load (local_list).local_packages; | |
1949 catch | |
1950 local_packages = {}; | |
1951 end_try_catch | |
1952 try | |
6675 | 1953 global_packages = load (global_list).global_packages; |
6496 | 1954 catch |
1955 global_packages = {}; | |
1956 end_try_catch | |
6820 | 1957 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 1958 |
1959 ## Eliminate duplicates in the installed package list. | |
8506 | 1960 ## Locally installed packages take precedence. |
6496 | 1961 dup = []; |
6820 | 1962 for i = 1:length (installed_pkgs_lst) |
6496 | 1963 if (find (dup, i)) |
1964 continue; | |
5801 | 1965 endif |
6820 | 1966 for j = (i+1):length (installed_pkgs_lst) |
6496 | 1967 if (find (dup, j)) |
10549 | 1968 continue; |
6496 | 1969 endif |
6820 | 1970 if (strcmp (installed_pkgs_lst{i}.name, installed_pkgs_lst{j}.name)) |
10549 | 1971 dup = [dup, j]; |
6496 | 1972 endif |
5987 | 1973 endfor |
6496 | 1974 endfor |
1975 if (! isempty(dup)) | |
6820 | 1976 installed_pkgs_lst(dup) = []; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1977 endif |
6496 | 1978 |
8506 | 1979 ## Now check if the package is loaded. |
6645 | 1980 tmppath = strrep (path(), "\\", "/"); |
6820 | 1981 for i = 1:length (installed_pkgs_lst) |
1982 if (findstr (tmppath, strrep (installed_pkgs_lst{i}.dir, "\\", "/"))) | |
1983 installed_pkgs_lst{i}.loaded = true; | |
6616 | 1984 else |
6820 | 1985 installed_pkgs_lst{i}.loaded = false; |
6616 | 1986 endif |
1987 endfor | |
6675 | 1988 for i = 1:length (local_packages) |
6776 | 1989 if (findstr (tmppath, strrep (local_packages{i}.dir, "\\", "/"))) |
6675 | 1990 local_packages{i}.loaded = true; |
1991 else | |
1992 local_packages{i}.loaded = false; | |
1993 endif | |
1994 endfor | |
1995 for i = 1:length (global_packages) | |
6776 | 1996 if (findstr (tmppath, strrep (global_packages{i}.dir, "\\", "/"))) |
6675 | 1997 global_packages{i}.loaded = true; |
1998 else | |
1999 global_packages{i}.loaded = false; | |
2000 endif | |
2001 endfor | |
6616 | 2002 |
6496 | 2003 ## Should we return something? |
2004 if (nargout == 2) | |
2005 out1 = local_packages; | |
2006 out2 = global_packages; | |
2007 return; | |
2008 elseif (nargout == 1) | |
6820 | 2009 out1 = installed_pkgs_lst; |
6496 | 2010 return; |
2011 endif | |
2012 | |
8506 | 2013 ## We shouldn't return something, so we'll print something. |
6820 | 2014 num_packages = length (installed_pkgs_lst); |
6496 | 2015 if (num_packages == 0) |
2016 printf ("no packages installed.\n"); | |
2017 return; | |
2018 endif | |
2019 | |
8506 | 2020 ## Compute the maximal lengths of name, version, and dir. |
6496 | 2021 h1 = "Package Name"; |
2022 h2 = "Version"; | |
2023 h3 = "Installation directory"; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2024 max_name_length = length (h1); |
6496 | 2025 max_version_length = length (h2); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2026 names = cell (num_packages, 1); |
6496 | 2027 for i = 1:num_packages |
2028 max_name_length = max (max_name_length, | |
10549 | 2029 length (installed_pkgs_lst{i}.name)); |
6496 | 2030 max_version_length = max (max_version_length, |
10549 | 2031 length (installed_pkgs_lst{i}.version)); |
6820 | 2032 names{i} = installed_pkgs_lst{i}.name; |
6496 | 2033 endfor |
6698 | 2034 max_dir_length = terminal_size()(2) - max_name_length - ... |
10549 | 2035 max_version_length - 7; |
6698 | 2036 if (max_dir_length < 20) |
2037 max_dir_length = Inf; | |
2038 endif | |
2039 | |
6616 | 2040 h1 = postpad (h1, max_name_length + 1, " "); |
6496 | 2041 h2 = postpad (h2, max_version_length, " ");; |
2042 | |
8506 | 2043 ## Print a header. |
6496 | 2044 header = sprintf("%s | %s | %s\n", h1, h2, h3); |
2045 printf (header); | |
2046 tmp = sprintf (repmat ("-", 1, length(header)-1)); | |
2047 tmp(length(h1)+2) = "+"; | |
2048 tmp(length(h1)+length(h2)+5) = "+"; | |
2049 printf ("%s\n", tmp); | |
2050 | |
8506 | 2051 ## Print the packages. |
6616 | 2052 format = sprintf ("%%%ds %%1s| %%%ds | %%s\n", max_name_length, |
10549 | 2053 max_version_length); |
6496 | 2054 [dummy, idx] = sort (names); |
2055 for i = 1:num_packages | |
6820 | 2056 cur_name = installed_pkgs_lst{idx(i)}.name; |
2057 cur_version = installed_pkgs_lst{idx(i)}.version; | |
2058 cur_dir = installed_pkgs_lst{idx(i)}.dir; | |
6698 | 2059 if (length (cur_dir) > max_dir_length) |
2060 first_char = length (cur_dir) - max_dir_length + 4; | |
2061 first_filesep = strfind (cur_dir(first_char:end), filesep()); | |
2062 if (! isempty (first_filesep)) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2063 cur_dir = cstrcat ("...", |
10549 | 2064 cur_dir((first_char + first_filesep(1) - 1):end)); |
6698 | 2065 else |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
2066 cur_dir = cstrcat ("...", cur_dir(first_char:end)); |
6698 | 2067 endif |
2068 endif | |
6820 | 2069 if (installed_pkgs_lst{idx(i)}.loaded) |
6616 | 2070 cur_loaded = "*"; |
2071 else | |
2072 cur_loaded = " "; | |
2073 endif | |
2074 printf (format, cur_name, cur_loaded, cur_version, cur_dir); | |
6496 | 2075 endfor |
5801 | 2076 endfunction |
2077 | |
6496 | 2078 function load_packages (files, handle_deps, local_list, global_list) |
6820 | 2079 installed_pkgs_lst = installed_packages (local_list, global_list); |
2080 num_packages = length (installed_pkgs_lst); | |
6496 | 2081 |
8506 | 2082 ## Read package names and installdirs into a more convenient format. |
6496 | 2083 pnames = pdirs = cell (1, num_packages); |
2084 for i = 1:num_packages | |
6820 | 2085 pnames{i} = installed_pkgs_lst{i}.name; |
2086 pdirs{i} = installed_pkgs_lst{i}.dir; | |
6496 | 2087 endfor |
2088 | |
8506 | 2089 ## Load all. |
6496 | 2090 if (length (files) == 1 && strcmp (files{1}, "all")) |
6820 | 2091 idx = [1:length(installed_pkgs_lst)]; |
8506 | 2092 ## Load auto. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2093 elseif (length (files) == 1 && strcmp (files{1}, "auto")) |
6695 | 2094 idx = []; |
6820 | 2095 for i = 1:length (installed_pkgs_lst) |
6496 | 2096 if (exist (fullfile (pdirs{i}, "packinfo", ".autoload"), "file")) |
10549 | 2097 idx (end + 1) = i; |
6496 | 2098 endif |
6037 | 2099 endfor |
8506 | 2100 ## Load package_name1 ... |
6496 | 2101 else |
6695 | 2102 idx = []; |
6496 | 2103 for i = 1:length (files) |
6695 | 2104 idx2 = find (strcmp (pnames, files{i})); |
2105 if (! any (idx2)) | |
10549 | 2106 error ("package %s is not installed", files{i}); |
6496 | 2107 endif |
6695 | 2108 idx (end + 1) = idx2; |
6496 | 2109 endfor |
2110 endif | |
6037 | 2111 |
8506 | 2112 ## Load the packages, but take care of the ordering of dependencies. |
6925 | 2113 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, true); |
5801 | 2114 endfunction |
5928 | 2115 |
6496 | 2116 function unload_packages (files, handle_deps, local_list, global_list) |
6820 | 2117 installed_pkgs_lst = installed_packages (local_list, global_list); |
2118 num_packages = length (installed_pkgs_lst); | |
6496 | 2119 |
8506 | 2120 ## Read package names and installdirs into a more convenient format. |
6496 | 2121 pnames = pdirs = cell (1, num_packages); |
2122 for i = 1:num_packages | |
6820 | 2123 pnames{i} = installed_pkgs_lst{i}.name; |
2124 pdirs{i} = installed_pkgs_lst{i}.dir; | |
2125 pdeps{i} = installed_pkgs_lst{i}.depends; | |
6496 | 2126 endfor |
2127 | |
8506 | 2128 ## Get the current octave path. |
6496 | 2129 p = split_by (path(), pathsep ()); |
6203 | 2130 |
6496 | 2131 if (length (files) == 1 && strcmp (files{1}, "all")) |
8506 | 2132 ## Unload all. |
2133 dirs = pdirs; | |
2134 desc = installed_pkgs_lst; | |
6496 | 2135 else |
8506 | 2136 ## Unload package_name1 ... |
6496 | 2137 dirs = {}; |
6925 | 2138 desc = {}; |
6496 | 2139 for i = 1:length (files) |
7208 | 2140 idx = strcmp (pnames, files{i}); |
6496 | 2141 if (! any (idx)) |
10549 | 2142 error ("package %s is not installed", files{i}); |
6496 | 2143 endif |
10549 | 2144 dirs{end+1} = pdirs{idx}; |
7208 | 2145 desc{end+1} = installed_pkgs_lst{idx}; |
6496 | 2146 endfor |
2147 endif | |
2148 | |
8506 | 2149 ## Check for architecture dependent directories. |
6614 | 2150 archdirs = {}; |
2151 for i = 1:length (dirs) | |
7208 | 2152 tmpdir = getarchdir (desc{i}); |
6614 | 2153 if (exist (tmpdir, "dir")) |
7208 | 2154 archdirs{end+1} = dirs{i}; |
2155 archdirs{end+1} = tmpdir; | |
6925 | 2156 else |
7208 | 2157 archdirs{end+1} = dirs{i}; |
6614 | 2158 endif |
2159 endfor | |
2160 | |
8506 | 2161 ## Unload the packages. |
6925 | 2162 for i = 1:length (archdirs) |
2163 d = archdirs{i}; | |
6496 | 2164 idx = strcmp (p, d); |
2165 if (any (idx)) | |
2166 rmpath (d); | |
8506 | 2167 ## FIXME: We should also check if we need to remove items from |
2168 ## EXEC_PATH. | |
6203 | 2169 endif |
6496 | 2170 endfor |
6203 | 2171 endfunction |
2172 | |
5928 | 2173 function [status_out, msg_out] = rm_rf (dir) |
6925 | 2174 if (exist (dir)) |
2175 crr = confirm_recursive_rmdir (); | |
2176 unwind_protect | |
2177 confirm_recursive_rmdir (false); | |
2178 [status, msg] = rmdir (dir, "s"); | |
2179 unwind_protect_cleanup | |
2180 confirm_recursive_rmdir (crr); | |
2181 end_unwind_protect | |
2182 else | |
2183 status = 1; | |
2184 msg = ""; | |
2185 endif | |
5928 | 2186 if (nargout > 0) |
2187 status_out = status; | |
2188 endif | |
2189 if (nargout > 1) | |
2190 msg_out = msg; | |
2191 endif | |
2192 endfunction | |
5971 | 2193 |
2194 function emp = dirempty (nm, ign) | |
6925 | 2195 if (exist (nm, "dir")) |
2196 if (nargin < 2) | |
2197 ign = {".", ".."}; | |
2198 else | |
2199 ign = [{".", ".."}, ign]; | |
2200 endif | |
2201 l = dir (nm); | |
2202 for i = 1:length (l) | |
2203 found = false; | |
2204 for j = 1:length (ign) | |
2205 if (strcmp (l(i).name, ign{j})) | |
2206 found = true; | |
2207 break; | |
2208 endif | |
2209 endfor | |
2210 if (! found) | |
2211 emp = false; | |
2212 return | |
5971 | 2213 endif |
2214 endfor | |
6925 | 2215 emp = true; |
2216 else | |
2217 emp = true; | |
2218 endif | |
5971 | 2219 endfunction |
6614 | 2220 |
2221 function arch = getarch () | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
2222 persistent _arch = cstrcat (octave_config_info("canonical_host_type"), ... |
10549 | 2223 "-", octave_config_info("api_version")); |
6614 | 2224 arch = _arch; |
2225 endfunction | |
6645 | 2226 |
6925 | 2227 function archprefix = getarchprefix (desc, global_install) |
2228 if ((nargin == 2 && global_install) || (nargin < 2 && issuperuser ())) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2229 archprefix = fullfile (octave_config_info ("libexecdir"), "octave", |
10549 | 2230 "packages", cstrcat(desc.name, "-", desc.version)); |
6925 | 2231 else |
2232 archprefix = desc.dir; | |
2233 endif | |
2234 endfunction | |
2235 | |
2236 function archdir = getarchdir (desc) | |
2237 archdir = fullfile (desc.archprefix, getarch()); | |
2238 endfunction | |
2239 | |
2240 function s = issuperuser () | |
2241 if ((ispc () && ! isunix ()) || (geteuid() == 0)) | |
2242 s = true; | |
2243 else | |
2244 s = false; | |
2245 endif | |
2246 endfunction | |
2247 | |
6645 | 2248 function [status, output] = shell (cmd) |
2249 persistent have_sh; | |
2250 | |
2251 cmd = strrep (cmd, "\\", "/"); | |
2252 if (ispc () && ! isunix ()) | |
2253 if (isempty(have_sh)) | |
2254 if (system("sh.exe -c \"exit\"")) | |
2255 have_sh = false; | |
2256 else | |
2257 have_sh = true; | |
2258 endif | |
2259 endif | |
2260 if (have_sh) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
2261 [status, output] = system (cstrcat ("sh.exe -c \"", cmd, "\"")); |
6645 | 2262 else |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11588
diff
changeset
|
2263 error ("Can not find the command shell"); |
6645 | 2264 endif |
2265 else | |
2266 [status, output] = system (cmd); | |
2267 endif | |
2268 endfunction | |
6695 | 2269 |
2270 function newdesc = save_order (desc) | |
2271 newdesc = {}; | |
2272 for i = 1 : length(desc) | |
2273 deps = desc{i}.depends; | |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2274 if (isempty (deps) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2275 || (length (deps) == 1 && strcmp(deps{1}.package, "octave"))) |
6695 | 2276 newdesc {end + 1} = desc{i}; |
2277 else | |
2278 tmpdesc = {}; | |
2279 for k = 1 : length (deps) | |
2280 for j = 1 : length (desc) | |
2281 if (strcmp (desc{j}.name, deps{k}.package)) | |
7208 | 2282 tmpdesc{end+1} = desc{j}; |
10549 | 2283 break; |
6695 | 2284 endif |
2285 endfor | |
2286 endfor | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2287 if (! isempty (tmpdesc)) |
6695 | 2288 newdesc = {newdesc{:}, save_order(tmpdesc){:}, desc{i}}; |
2289 else | |
7208 | 2290 newdesc{end+1} = desc{i}; |
6695 | 2291 endif |
2292 endif | |
2293 endfor | |
8506 | 2294 ## Eliminate the duplicates. |
6695 | 2295 idx = []; |
2296 for i = 1 : length (newdesc) | |
2297 for j = (i + 1) : length (newdesc) | |
2298 if (strcmp (newdesc{i}.name, newdesc{j}.name)) | |
2299 idx (end + 1) = j; | |
2300 endif | |
2301 endfor | |
2302 endfor | |
2303 newdesc(idx) = []; | |
2304 endfunction | |
2305 | |
6925 | 2306 function load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, |
10549 | 2307 global_install) |
6820 | 2308 idx = load_package_dirs (idx, [], handle_deps, installed_pkgs_lst); |
6695 | 2309 dirs = {}; |
2310 execpath = EXEC_PATH (); | |
2311 for i = idx; | |
6820 | 2312 ndir = installed_pkgs_lst{i}.dir; |
7208 | 2313 dirs{end+1} = ndir; |
6695 | 2314 if (exist (fullfile (dirs{end}, "bin"), "dir")) |
11300
4ecc7bc5bc83
search PATH from environment for programs, not EXEC_PATH
John W. Eaton <jwe@octave.org>
parents:
11191
diff
changeset
|
2315 execpath = cstrcat (execpath, pathsep (), fullfile (dirs{end}, "bin")); |
6695 | 2316 endif |
7208 | 2317 tmpdir = getarchdir (installed_pkgs_lst{i}); |
6695 | 2318 if (exist (tmpdir, "dir")) |
2319 dirs{end + 1} = tmpdir; | |
6950 | 2320 if (exist (fullfile (dirs{end}, "bin"), "dir")) |
11300
4ecc7bc5bc83
search PATH from environment for programs, not EXEC_PATH
John W. Eaton <jwe@octave.org>
parents:
11191
diff
changeset
|
2321 execpath = cstrcat (execpath, pathsep (), fullfile (dirs{end}, "bin")); |
6950 | 2322 endif |
6695 | 2323 endif |
2324 endfor | |
2325 | |
8506 | 2326 ## Load the packages. |
6695 | 2327 if (length (dirs) > 0) |
2328 addpath (dirs{:}); | |
2329 endif | |
2330 | |
8506 | 2331 ## Add the binaries to exec_path. |
6695 | 2332 if (! strcmp (EXEC_PATH, execpath)) |
2333 EXEC_PATH (execpath); | |
2334 endif | |
2335 endfunction | |
2336 | |
6820 | 2337 function idx = load_package_dirs (lidx, idx, handle_deps, installed_pkgs_lst) |
6695 | 2338 for i = lidx |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2339 if (isfield (installed_pkgs_lst{i}, "loaded") |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2340 && installed_pkgs_lst{i}.loaded) |
6695 | 2341 continue; |
2342 else | |
2343 if (handle_deps) | |
6820 | 2344 deps = installed_pkgs_lst{i}.depends; |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2345 if ((length (deps) > 1) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2346 || (length (deps) == 1 && ! strcmp(deps{1}.package, "octave"))) |
6695 | 2347 tmplidx = []; |
2348 for k = 1 : length (deps) | |
6820 | 2349 for j = 1 : length (installed_pkgs_lst) |
2350 if (strcmp (installed_pkgs_lst{j}.name, deps{k}.package)) | |
6695 | 2351 tmplidx (end + 1) = j; |
10549 | 2352 break; |
6695 | 2353 endif |
2354 endfor | |
2355 endfor | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2356 idx = load_package_dirs (tmplidx, idx, handle_deps, |
10549 | 2357 installed_pkgs_lst); |
6695 | 2358 endif |
2359 endif | |
2360 if (isempty (find(idx == i))) | |
2361 idx (end + 1) = i; | |
2362 endif | |
2363 endif | |
2364 endfor | |
2365 endfunction | |
6950 | 2366 |
2367 function dep = is_architecture_dependent (nm) | |
7329 | 2368 persistent archdepsuffix = {".oct",".mex",".a",".lib",".so",".so.*",".dll","dylib"}; |
6950 | 2369 |
2370 dep = false; | |
2371 for i = 1 : length (archdepsuffix) | |
7208 | 2372 ext = archdepsuffix{i}; |
6950 | 2373 if (ext(end) == "*") |
2374 isglob = true; | |
2375 ext(end) = []; | |
2376 else | |
2377 isglob = false; | |
2378 endif | |
2379 pos = findstr (nm, ext); | |
2380 if (pos) | |
7208 | 2381 if (! isglob && (length(nm) - pos(end) != length(ext) - 1)) |
10549 | 2382 continue; |
6950 | 2383 endif |
2384 dep = true; | |
2385 break; | |
2386 endif | |
2387 endfor | |
2388 endfunction | |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
2389 |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
2390 function [url, local_file] = get_forge_download (name) |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
2391 [ver, url] = get_forge_pkg (name); |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
2392 local_file = [name, "-", ver, ".tar.gz"]; |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
2393 endfunction |
10685
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2394 |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2395 function list = list_forge_packages () |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2396 [list, succ] = urlread ("http://octave.sourceforge.net/list_packages.php"); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2397 if (succ) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2398 list = strsplit (list, " \n\t", true); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2399 else |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2400 error ("pkg: could not read URL, please verify internet connection"); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2401 endif |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2402 if (nargout == 0) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2403 page_screen_output (false, "local"); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2404 puts ("OctaveForge provides these packages:\n"); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2405 for i = 1:length (list) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2406 try |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2407 ver = get_forge_pkg (list{i}); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2408 catch |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2409 ver = "unknown"; |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2410 end_try_catch |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2411 printf (" %s %s\n", list{i}, ver); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2412 endfor |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2413 endif |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2414 endfunction |