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