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