Mercurial > hg > octave-lyh
annotate scripts/pkg/pkg.m @ 8664:e07e93c04080
style fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 04 Feb 2009 10:56:23 -0500 |
parents | f134925a1cfa |
children | 5dd06f19e9be |
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); | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
746 finish_installation (desc, pdir, global_install); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
747 generate_lookfor_cache (desc); |
6496 | 748 endfor |
749 catch | |
8506 | 750 ## Something went wrong, delete tmpdirs. |
6496 | 751 for i = 1:length (tmpdirs) |
752 rm_rf (tmpdirs{i}); | |
753 endfor | |
754 for i = 1:length (descriptions) | |
755 rm_rf (descriptions{i}.dir); | |
6925 | 756 rm_rf (getarchdir (descriptions{i})); |
6496 | 757 endfor |
6655 | 758 rethrow (lasterror ()); |
6496 | 759 end_try_catch |
760 | |
761 ## Check if the installed directory is empty. If it is remove it | |
8506 | 762 ## from the list. |
6496 | 763 for i = length (descriptions):-1:1 |
6925 | 764 if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) && |
765 dirempty (getarchdir (descriptions{i}))) | |
6655 | 766 warning ("package %s is empty\n", descriptions{i}.name); |
6496 | 767 rm_rf (descriptions{i}.dir); |
6925 | 768 rm_rf (getarchdir (descriptions{i})); |
6496 | 769 descriptions(i) = []; |
770 endif | |
771 endfor | |
772 | |
773 ## If the package requested that it is autoloaded, or the installer | |
774 ## requested that it is, then mark the package as autoloaded. | |
775 for i = length (descriptions):-1:1 | |
776 if (autoload > 0 || (autoload == 0 && isautoload (descriptions(i)))) | |
777 fclose (fopen (fullfile (descriptions{i}.dir, "packinfo", | |
778 ".autoload"), "wt")); | |
6695 | 779 descriptions{i}.autoload = 1; |
6496 | 780 endif |
781 endfor | |
782 | |
8506 | 783 ## Add the packages to the package list. |
6496 | 784 try |
785 if (global_install) | |
786 idx = complement (packages_to_uninstall, 1:length(global_packages)); | |
6695 | 787 global_packages = save_order ({global_packages{idx}, descriptions{:}}); |
6496 | 788 save (global_list, "global_packages"); |
6820 | 789 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 790 else |
791 idx = complement (packages_to_uninstall, 1:length(local_packages)); | |
6695 | 792 local_packages = save_order ({local_packages{idx}, descriptions{:}}); |
6496 | 793 save (local_list, "local_packages"); |
6820 | 794 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 795 endif |
796 catch | |
8506 | 797 ## Something went wrong, delete tmpdirs. |
6496 | 798 for i = 1:length (tmpdirs) |
799 rm_rf (tmpdirs{i}); | |
800 endfor | |
801 for i = 1:length (descriptions) | |
802 rm_rf (descriptions{i}.dir); | |
803 endfor | |
804 if (global_install) | |
6695 | 805 printf ("error: couldn't append to %s\n", global_list); |
6496 | 806 else |
6695 | 807 printf ("error: couldn't append to %s\n", local_list); |
6496 | 808 endif |
6695 | 809 rethrow (lasterror ()); |
6496 | 810 end_try_catch |
811 | |
8506 | 812 ## All is well, let's clean up. |
6496 | 813 for i = 1:length (tmpdirs) |
814 [status, msg] = rm_rf (tmpdirs{i}); | |
815 if (status != 1) | |
816 warning ("couldn't clean up after my self: %s\n", msg); | |
817 endif | |
818 endfor | |
819 | |
820 ## Add the newly installed packages to the path, so the user | |
8506 | 821 ## can begin using them. Only load them if they are marked autoload. |
6496 | 822 if (length (descriptions) > 0) |
6695 | 823 idx = []; |
6496 | 824 for i = 1:length (descriptions) |
6695 | 825 if (isautoload (descriptions(i))) |
7192 | 826 nm = descriptions{i}.name; |
827 for j = 1:length (installed_pkgs_lst) | |
828 if (strcmp (nm, installed_pkgs_lst{j}.name)) | |
829 idx (end + 1) = j; | |
830 break; | |
831 endif | |
832 endfor | |
6614 | 833 endif |
6496 | 834 endfor |
6925 | 835 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, |
836 global_install); | |
6496 | 837 endif |
838 endfunction | |
839 | |
6645 | 840 function uninstall (pkgnames, handle_deps, verbose, local_list, |
841 global_list, global_install) | |
8506 | 842 ## Get the list of installed packages. |
6496 | 843 [local_packages, global_packages] = installed_packages(local_list, |
844 global_list); | |
6645 | 845 if (global_install) |
6820 | 846 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 847 else |
6820 | 848 installed_pkgs_lst = local_packages; |
6496 | 849 endif |
850 | |
6820 | 851 num_packages = length (installed_pkgs_lst); |
6496 | 852 delete_idx = []; |
853 for i = 1:num_packages | |
6820 | 854 cur_name = installed_pkgs_lst{i}.name; |
6496 | 855 if (any (strcmp (cur_name, pkgnames))) |
856 delete_idx(end+1) = i; | |
857 endif | |
858 endfor | |
859 | |
860 ## Are all the packages that should be uninstalled already installed? | |
861 if (length (delete_idx) != length (pkgnames)) | |
6645 | 862 if (global_install) |
8506 | 863 ## Try again for a locally installed package. |
6820 | 864 installed_pkgs_lst = local_packages; |
6496 | 865 |
6820 | 866 num_packages = length (installed_pkgs_lst); |
6496 | 867 delete_idx = []; |
868 for i = 1:num_packages | |
6820 | 869 cur_name = installed_pkgs_lst{i}.name; |
6496 | 870 if (any (strcmp (cur_name, pkgnames))) |
871 delete_idx(end+1) = i; | |
872 endif | |
873 endfor | |
874 if (length (delete_idx) != length (pkgnames)) | |
8506 | 875 ## FIXME: We should have a better error message. |
6655 | 876 warning ("some of the packages you want to uninstall are not installed"); |
6496 | 877 endif |
878 else | |
8506 | 879 ## FIXME: We should have a better error message. |
8664 | 880 warning ("some of the packages you want to uninstall are not installed"); |
6496 | 881 endif |
882 endif | |
883 | |
8506 | 884 ## Compute the packages that will remain installed. |
6496 | 885 idx = complement (delete_idx, 1:num_packages); |
6820 | 886 remaining_packages = {installed_pkgs_lst{idx}}; |
6496 | 887 |
8506 | 888 ## Check dependencies. |
6496 | 889 if (handle_deps) |
890 error_text = ""; | |
891 for i = 1:length (remaining_packages) | |
892 desc = remaining_packages{i}; | |
893 bad_deps = get_unsatisfied_deps (desc, remaining_packages); | |
894 | |
895 ## Will the uninstallation break any dependencies? | |
896 if (! isempty (bad_deps)) | |
897 for i = 1:length (bad_deps) | |
898 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
|
899 error_text = cstrcat (error_text, " ", desc.name, " needs ", |
6496 | 900 dep.package, " ", dep.operator, " ", |
901 dep.version, "\n"); | |
902 endfor | |
903 endif | |
904 endfor | |
905 | |
906 if (! isempty (error_text)) | |
907 error ("the following dependencies where unsatisfied:\n %s", error_text); | |
908 endif | |
909 endif | |
910 | |
8506 | 911 ## Delete the directories containing the packages. |
6496 | 912 for i = delete_idx |
6820 | 913 desc = installed_pkgs_lst{i}; |
6496 | 914 ## If an 'on_uninstall.m' exist, call it! |
915 if (exist (fullfile (desc.dir, "packinfo", "on_uninstall.m"), "file")) | |
6614 | 916 wd = pwd (); |
7498 | 917 cd (fullfile (desc.dir, "packinfo")); |
6614 | 918 on_uninstall (desc); |
919 cd (wd); | |
6496 | 920 endif |
8506 | 921 ## Do the actual deletion. |
6675 | 922 if (desc.loaded) |
923 rmpath (desc.dir); | |
6925 | 924 if (exist (getarchdir (desc))) |
925 rmpath (getarchdir (desc)); | |
6675 | 926 endif |
6614 | 927 endif |
6496 | 928 if (exist (desc.dir, "dir")) |
929 [status, msg] = rm_rf (desc.dir); | |
930 if (status != 1) | |
931 error ("couldn't delete directory %s: %s", desc.dir, msg); | |
932 endif | |
6925 | 933 [status, msg] = rm_rf (getarchdir (desc)); |
934 if (status != 1) | |
935 error ("couldn't delete directory %s: %s", getarchdir (desc), msg); | |
936 endif | |
937 if (dirempty (desc.archprefix)) | |
938 rm_rf (desc.archprefix); | |
939 endif | |
6496 | 940 else |
941 warning ("directory %s previously lost", desc.dir); | |
942 endif | |
943 endfor | |
944 | |
8506 | 945 ## Write a new ~/.octave_packages. |
6645 | 946 if (global_install) |
6496 | 947 if (length (remaining_packages) == 0) |
948 unlink (global_list); | |
949 else | |
6695 | 950 global_packages = save_order (remaining_packages); |
6496 | 951 save (global_list, "global_packages"); |
952 endif | |
953 else | |
954 if (length (remaining_packages) == 0) | |
955 unlink (local_list); | |
956 else | |
6695 | 957 local_packages = save_order (remaining_packages); |
6496 | 958 save (local_list, "local_packages"); |
959 endif | |
960 endif | |
961 | |
962 endfunction | |
963 | |
7497 | 964 function [pkg_desc_list, flag] = describe (pkgnames, verbose, |
965 local_list, global_list) | |
966 | |
8506 | 967 ## Get the list of installed packages. |
7497 | 968 installed_pkgs_lst = installed_packages(local_list, global_list); |
7498 | 969 num_packages = length (installed_pkgs_lst); |
7497 | 970 |
971 | |
7498 | 972 describe_all = false; |
973 if (any (strcmp ("all", pkgnames))) | |
974 describe_all = true; | |
8455
fd11a08a9b31
disallow invalid {}-indexed assigments
Jaroslav Hajek <highegg@gmail.com>
parents:
8202
diff
changeset
|
975 flag(1:num_packages) = {"Not Loaded"}; |
7498 | 976 num_pkgnames = num_packages; |
7497 | 977 else |
7498 | 978 num_pkgnames = length (pkgnames); |
8455
fd11a08a9b31
disallow invalid {}-indexed assigments
Jaroslav Hajek <highegg@gmail.com>
parents:
8202
diff
changeset
|
979 flag(1:num_pkgnames) = {"Not installed"}; |
7498 | 980 endif |
7497 | 981 |
982 for i = 1:num_packages | |
8507 | 983 curr_name = installed_pkgs_lst{i}.name; |
7497 | 984 if (describe_all) |
985 name_pos = i; | |
986 else | |
987 name_pos = find(strcmp (curr_name, pkgnames)); | |
7498 | 988 endif |
989 | |
990 if (! isempty (name_pos)) | |
7497 | 991 if (installed_pkgs_lst{i}.loaded) |
992 flag{name_pos} = "Loaded"; | |
993 else | |
994 flag{name_pos} = "Not loaded"; | |
995 endif | |
996 | |
7498 | 997 pkg_desc_list{name_pos}.name = installed_pkgs_lst{i}.name; |
998 pkg_desc_list{name_pos}.description = installed_pkgs_lst{i}.description; | |
999 pkg_desc_list{name_pos}.provides = parse_pkg_idx (installed_pkgs_lst{i}.dir); | |
7497 | 1000 |
1001 endif | |
1002 endfor | |
1003 | |
7498 | 1004 non_inst = find (strcmp (flag, "Not installed")); |
1005 if (! isempty (non_inst) && nargout < 2) | |
1006 non_inst_str = sprintf (" %s ", pkgnames{non_inst}); | |
1007 error ("some packages are not installed: %s", non_inst_str); | |
7497 | 1008 endif |
1009 | |
1010 if (nargout == 0) | |
7498 | 1011 for i = 1:num_pkgnames |
7497 | 1012 print_package_description (pkg_desc_list{i}.name, |
1013 pkg_desc_list{i}.provides, | |
1014 pkg_desc_list{i}.description, | |
1015 flag{i}, verbose); | |
1016 endfor | |
1017 endif | |
1018 | |
1019 endfunction | |
1020 | |
8506 | 1021 ## AUXILIARY FUNCTIONS |
6496 | 1022 |
8506 | 1023 ## Read an INDEX file. |
7498 | 1024 function [pkg_idx_struct] = parse_pkg_idx (packdir) |
7497 | 1025 |
7498 | 1026 index_file = fullfile (packdir, "packinfo", "INDEX"); |
1027 | |
1028 if (! exist (index_file, "file")) | |
1029 error ("could not find any INDEX file in directory %s, try 'pkg rebuild all' to generate missing INDEX files", packdir); | |
7497 | 1030 endif |
1031 | |
1032 | |
7498 | 1033 [fid, msg] = fopen (index_file, "r"); |
7497 | 1034 if (fid == -1) |
7498 | 1035 error ("the INDEX file %s could not be read: %s", |
1036 index_file, msg); | |
7497 | 1037 endif |
7498 | 1038 |
7497 | 1039 cat_num = 1; |
1040 pkg_idx_struct{1}.category = "Uncategorized"; | |
1041 pkg_idx_struct{1}.functions = {}; | |
1042 | |
7498 | 1043 line = fgetl (fid); |
1044 while (isempty (strfind (line, ">>")) && ! feof (fid)) | |
1045 line = fgetl (fid); | |
7497 | 1046 endwhile |
1047 | |
7498 | 1048 while (! feof (fid) || line != -1) |
1049 if (! any (! isspace (line)) || line(1) == "#" || any (line == "=")) | |
7497 | 1050 ## Comments, blank lines or comments about unimplemented |
1051 ## functions: do nothing | |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8174
diff
changeset
|
1052 ## FIXME: probably comments and pointers to external functions |
7497 | 1053 ## could be treated better when printing to screen? |
7498 | 1054 elseif (! isempty (strfind (line, ">>"))) |
8506 | 1055 ## Skip package name and description as they are in DESCRIPTION |
1056 ## already. | |
7498 | 1057 elseif (! isspace (line(1))) |
8506 | 1058 ## Category. |
7498 | 1059 if (! isempty (pkg_idx_struct{cat_num}.functions)) |
1060 pkg_idx_struct{++cat_num}.functions = {}; | |
7497 | 1061 endif |
7498 | 1062 pkg_idx_struct{cat_num}.category = deblank (line); |
7497 | 1063 else |
8506 | 1064 ## Function names. |
7498 | 1065 while (any (! isspace (line))) |
1066 [fun_name, line] = strtok (line); | |
1067 pkg_idx_struct{cat_num}.functions{end+1} = deblank (fun_name); | |
7497 | 1068 endwhile |
1069 endif | |
7498 | 1070 line = fgetl (fid); |
7497 | 1071 endwhile |
1072 fclose (fid); | |
1073 endfunction | |
1074 | |
1075 function print_package_description (pkg_name, pkg_idx_struct, | |
1076 pkg_desc, status, verbose) | |
1077 | |
7498 | 1078 printf ("---\nPackage name:\n\t%s\n", pkg_name); |
1079 printf ("Short description:\n\t%s\n", pkg_desc); | |
1080 printf ("Status:\n\t%s\n", status); | |
7497 | 1081 if (verbose) |
7498 | 1082 printf ("---\nProvides:\n"); |
1083 for i = 1:length(pkg_idx_struct) | |
1084 if (! isempty (pkg_idx_struct{i}.functions)) | |
1085 printf ("%s\n", pkg_idx_struct{i}.category); | |
1086 for j = 1:length(pkg_idx_struct{i}.functions) | |
1087 printf ("\t%s\n", pkg_idx_struct{i}.functions{j}); | |
7497 | 1088 endfor |
1089 endif | |
1090 endfor | |
1091 endif | |
1092 | |
1093 endfunction | |
1094 | |
1095 | |
6675 | 1096 function pth = absolute_pathname (pth) |
7498 | 1097 [status, msg, msgid] = fileattrib (pth); |
6729 | 1098 if (status != 1) |
1099 error ("could not find the file or path %s", pth); | |
1100 else | |
1101 pth = msg.Name; | |
1102 endif | |
6675 | 1103 endfunction |
1104 | |
1105 function repackage (builddir, buildlist) | |
1106 packages = installed_packages (buildlist, buildlist); | |
1107 | |
1108 wd = pwd(); | |
1109 for i = 1 : length(packages) | |
1110 pack = packages{i}; | |
1111 unwind_protect | |
1112 cd (builddir); | |
1113 mkdir (pack.name); | |
1114 mkdir (fullfile (pack.name, "inst")); | |
1115 copyfile (fullfile (pack.dir, "*"), fullfile (pack.name, "inst")); | |
1116 movefile (fullfile (pack.name, "inst","packinfo", "*"), pack.name); | |
1117 if (exist (fullfile (pack.name, "inst","packinfo", ".autoload"), "file")) | |
1118 unlink (fullfile (pack.name, "inst","packinfo", ".autoload")); | |
1119 endif | |
1120 rmdir (fullfile (pack.name, "inst", "packinfo")); | |
1121 if (exist (fullfile (pack.name, "inst", "doc"), "dir")) | |
1122 movefile (fullfile (pack.name, "inst", "doc"), pack.name); | |
1123 endif | |
1124 if (exist (fullfile (pack.name, "inst", "bin"), "dir")) | |
1125 movefile (fullfile (pack.name, "inst", "bin"), pack.name); | |
1126 endif | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1127 archdir = fullfile (pack.archprefix, cstrcat (pack.name, "-", |
6925 | 1128 pack.version), getarch ()); |
6675 | 1129 if (exist (archdir, "dir")) |
1130 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file")) | |
1131 unlink (fullfile (pack.name, "inst", "PKG_ADD")); | |
1132 endif | |
1133 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file")) | |
1134 unlink (fullfile (pack.name, "inst", "PKG_DEL")); | |
1135 endif | |
1136 if (exist (fullfile (archdir, "PKG_ADD"), "file")) | |
1137 movefile (fullfile (archdir, "PKG_ADD"), | |
1138 fullfile (pack.name, "PKG_ADD")); | |
1139 endif | |
1140 if (exist (fullfile (archdir, "PKG_DEL"), "file")) | |
1141 movefile (fullfile (archdir, "PKG_DEL"), | |
1142 fullfile (pack.name, "PKG_DEL")); | |
1143 endif | |
1144 else | |
1145 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file")) | |
1146 movefile (fullfile (pack.name, "inst", "PKG_ADD"), | |
1147 fullfile (pack.name, "PKG_ADD")); | |
1148 endif | |
1149 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file")) | |
1150 movefile (fullfile (pack.name, "inst", "PKG_DEL"), | |
1151 fullfile (pack.name, "PKG_DEL")); | |
1152 endif | |
1153 endif | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1154 tfile = cstrcat (pack.name, "-", pack.version, ".tar"); |
6675 | 1155 tar (tfile, pack.name); |
6925 | 1156 try |
1157 gzip (tfile); | |
1158 unlink (tfile); | |
1159 catch | |
1160 warning ("failed to compress %s", tfile); | |
1161 end_try_catch | |
6675 | 1162 unwind_protect_cleanup |
1163 if (exist (pack.name, "dir")) | |
1164 rm_rf (pack.name); | |
1165 endif | |
1166 cd (wd); | |
1167 end_unwind_protect | |
1168 endfor | |
1169 endfunction | |
1170 | |
1171 function auto = isautoload (desc) | |
6695 | 1172 auto = false; |
1173 if (isfield (desc{1}, "autoload")) | |
1174 a = desc{1}.autoload; | |
1175 if ((isnumeric (a) && a > 0) | |
1176 || (ischar (a) && (strcmpi (a, "true") | |
6675 | 1177 || strcmpi (a, "on") |
1178 || strcmpi (a, "yes") | |
1179 || strcmpi (a, "1")))) | |
6695 | 1180 auto = true; |
1181 endif | |
6675 | 1182 endif |
1183 endfunction | |
1184 | |
6496 | 1185 function prepare_installation (desc, packdir) |
1186 ## Is there a pre_install to call? | |
1187 if (exist (fullfile (packdir, "pre_install.m"), "file")) | |
1188 wd = pwd (); | |
1189 try | |
1190 cd (packdir); | |
1191 pre_install (desc); | |
1192 cd (wd); | |
1193 catch | |
1194 cd (wd); | |
6695 | 1195 rethrow (lasterror ()); |
6496 | 1196 end_try_catch |
1197 endif | |
1198 | |
8506 | 1199 ## If the directory "inst" doesn't exist, we create it. |
6496 | 1200 inst_dir = fullfile (packdir, "inst"); |
1201 if (! exist (inst_dir, "dir")) | |
1202 [status, msg] = mkdir (inst_dir); | |
1203 if (status != 1) | |
1204 rm_rf (desc.dir); | |
1205 error ("the 'inst' directory did not exist and could not be created: %s", | |
1206 msg); | |
6258 | 1207 endif |
1208 endif | |
1209 endfunction | |
1210 | |
6614 | 1211 function configure_make (desc, packdir, verbose) |
8506 | 1212 ## Perform ./configure, make, make install in "src". |
6496 | 1213 if (exist (fullfile (packdir, "src"), "dir")) |
1214 src = fullfile (packdir, "src"); | |
8506 | 1215 ## Configure. |
6496 | 1216 if (exist (fullfile (src, "configure"), "file")) |
7111 | 1217 flags = ""; |
1218 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
|
1219 flags = cstrcat (flags, " CC=\"", octave_config_info ("CC"), "\""); |
7111 | 1220 endif |
1221 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
|
1222 flags = cstrcat (flags, " CXX=\"", octave_config_info ("CXX"), "\""); |
7111 | 1223 endif |
1224 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
|
1225 flags = cstrcat (flags, " AR=\"", octave_config_info ("AR"), "\""); |
7111 | 1226 endif |
1227 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
|
1228 flags = cstrcat (flags, " RANLIB=\"", octave_config_info ("RANLIB"), "\""); |
7111 | 1229 endif |
8172
9ba45b125ee8
enclose building direcries in quotes in pkg.m
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8043
diff
changeset
|
1230 [status, output] = shell (strcat ("cd '", src, "'; ./configure --prefix=\"", |
7111 | 1231 desc.dir, "\"", flags)); |
6496 | 1232 if (status != 0) |
1233 rm_rf (desc.dir); | |
1234 error ("the configure script returned the following error: %s", output); | |
6675 | 1235 elseif (verbose) |
1236 printf("%s", output); | |
6496 | 1237 endif |
6675 | 1238 |
5801 | 1239 endif |
1240 | |
8506 | 1241 ## Make. |
6496 | 1242 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
|
1243 [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
|
1244 "\"; make -C '", src, "'")); |
6496 | 1245 if (status != 0) |
1246 rm_rf (desc.dir); | |
1247 error ("'make' returned the following error: %s", output); | |
6675 | 1248 elseif (verbose) |
1249 printf("%s", output); | |
6496 | 1250 endif |
5801 | 1251 endif |
1252 | |
8506 | 1253 ## Copy files to "inst" and "inst/arch" (this is instead of 'make |
1254 ## install'). | |
6496 | 1255 files = fullfile (src, "FILES"); |
1256 instdir = fullfile (packdir, "inst"); | |
6614 | 1257 archdir = fullfile (packdir, "inst", getarch ()); |
6950 | 1258 |
8506 | 1259 ## Get file names. |
6496 | 1260 if (exist (files, "file")) |
1261 [fid, msg] = fopen (files, "r"); | |
1262 if (fid < 0) | |
1263 error ("couldn't open %s: %s", files, msg); | |
5971 | 1264 endif |
6496 | 1265 filenames = char (fread (fid))'; |
1266 fclose (fid); | |
1267 if (filenames(end) == "\n") | |
1268 filenames(end) = []; | |
6258 | 1269 endif |
6655 | 1270 filenames = split_by (filenames, "\n"); |
6496 | 1271 delete_idx = []; |
6655 | 1272 for i = 1:length (filenames) |
1273 if (! all (isspace (filenames{i}))) | |
1274 filenames{i} = fullfile (src, filenames{i}); | |
6496 | 1275 else |
1276 delete_idx(end+1) = i; | |
1277 endif | |
5971 | 1278 endfor |
6655 | 1279 filenames(delete_idx) = []; |
6496 | 1280 else |
1281 m = dir (fullfile (src, "*.m")); | |
1282 oct = dir (fullfile (src, "*.oct")); | |
1283 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
|
1284 |
ea9b5f31bfac
pkg.m: better handling of filenames with spaces
John W. Eaton <jwe@octave.org>
parents:
8172
diff
changeset
|
1285 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
|
1286 {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
|
1287 "UniformOutput", false); |
5971 | 1288 endif |
5801 | 1289 |
8506 | 1290 ## Split into architecture dependent and independent files. |
7024 | 1291 if (isempty (filenames)) |
1292 idx = []; | |
1293 else | |
8043
30d15ab0ce01
avoid problematic subfunction call in an anonymous function
Jaroslav Hajek <highegg@gmail.com>
parents:
7739
diff
changeset
|
1294 idx = cellfun (@is_architecture_dependent, filenames); |
7024 | 1295 endif |
6950 | 1296 archdependent = filenames (idx); |
1297 archindependent = filenames (!idx); | |
1298 | |
8506 | 1299 ## 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
|
1300 if (! all (isspace ([filenames{:}]))) |
6655 | 1301 if (! exist (instdir, "dir")) |
1302 mkdir (instdir); | |
1303 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
|
1304 if (! all (isspace ([archindependent{:}]))) |
6634 | 1305 if (verbose) |
1306 printf ("copyfile"); | |
1307 printf (" %s", archindependent{:}); | |
1308 printf ("%s\n", instdir); | |
1309 endif | |
6614 | 1310 [status, output] = copyfile (archindependent, instdir); |
1311 if (status != 1) | |
6496 | 1312 rm_rf (desc.dir); |
1313 error ("Couldn't copy files from 'src' to 'inst': %s", output); | |
6614 | 1314 endif |
1315 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
|
1316 if (! all (isspace ([archdependent{:}]))) |
6634 | 1317 if (verbose) |
1318 printf ("copyfile"); | |
1319 printf (" %s", archdependent{:}); | |
1320 printf (" %s\n", archdir); | |
1321 endif | |
6655 | 1322 if (! exist (archdir, "dir")) |
1323 mkdir (archdir); | |
1324 endif | |
6614 | 1325 [status, output] = copyfile (archdependent, archdir); |
1326 if (status != 1) | |
1327 rm_rf (desc.dir); | |
1328 error ("Couldn't copy files from 'src' to 'inst': %s", output); | |
1329 endif | |
1330 endif | |
5801 | 1331 endif |
6496 | 1332 endif |
5801 | 1333 endfunction |
1334 | |
5971 | 1335 function pkg = extract_pkg (nm, pat) |
5955 | 1336 fid = fopen (nm, "rt"); |
5971 | 1337 pkg = ""; |
5955 | 1338 if (fid >= 0) |
6496 | 1339 while (! feof (fid)) |
5955 | 1340 ln = fgetl (fid); |
1341 if (ln > 0) | |
6496 | 1342 t = regexp (ln, pat, "tokens"); |
1343 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
|
1344 pkg = cstrcat (pkg, "\n", t{1}{1}); |
5955 | 1345 endif |
1346 endif | |
1347 endwhile | |
6496 | 1348 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
|
1349 pkg = cstrcat (pkg, "\n"); |
5955 | 1350 endif |
1351 fclose (fid); | |
1352 endif | |
1353 endfunction | |
1354 | |
6925 | 1355 function create_pkgadddel (desc, packdir, nm, global_install) |
6675 | 1356 instpkg = fullfile (desc.dir, nm); |
1357 instfid = fopen (instpkg, "wt"); | |
1358 ## If it is exists, most of the PKG_* file should go into the | |
1359 ## architecture dependent directory so that the autoload/mfilename | |
1360 ## commands work as expected. The only part that doesn't is the | |
1361 ## 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
|
1362 archdir = fullfile (getarchprefix (desc), cstrcat (desc.name, "-", |
6925 | 1363 desc.version), getarch ()); |
1364 if (exist (getarchdir (desc, global_install), "dir")) | |
1365 archpkg = fullfile (getarchdir (desc, global_install), nm); | |
1366 archfid = fopen (archpkg, "at"); | |
6675 | 1367 else |
1368 archpkg = instpkg; | |
1369 archfid = instfid; | |
1370 endif | |
6634 | 1371 |
6675 | 1372 if (archfid >= 0 && instfid >= 0) |
8506 | 1373 ## Search all dot-m files for PKG commands. |
7498 | 1374 lst = dir (fullfile (packdir, "inst", "*.m")); |
6496 | 1375 for i = 1:length (lst) |
7498 | 1376 nam = fullfile (packdir, "inst", lst(i).name); |
6675 | 1377 fwrite (instfid, extract_pkg (nam, ['^[#%][#%]* *' nm ': *(.*)$'])); |
5955 | 1378 endfor |
1379 | |
8506 | 1380 ## Search all C++ source files for PKG commands. |
7498 | 1381 lst = dir (fullfile (packdir, "src", "*.cc")); |
6496 | 1382 for i = 1:length (lst) |
7498 | 1383 nam = fullfile (packdir, "src", lst(i).name); |
6675 | 1384 fwrite (archfid, extract_pkg (nam, ['^//* *' nm ': *(.*)$'])); |
1385 fwrite (archfid, extract_pkg (nam, ['^/\** *' nm ': *(.*) *\*/$'])); | |
5955 | 1386 endfor |
1387 | |
8506 | 1388 ## Add developer included PKG commands. |
6496 | 1389 packdirnm = fullfile (packdir, nm); |
1390 if (exist (packdirnm, "file")) | |
6675 | 1391 fid = fopen (packdirnm, "rt"); |
1392 if (fid >= 0) | |
1393 while (! feof (fid)) | |
1394 ln = fgets (fid); | |
5955 | 1395 if (ln > 0) |
6675 | 1396 fwrite (archfid, ln); |
5955 | 1397 endif |
1398 endwhile | |
6675 | 1399 fclose (fid); |
5955 | 1400 endif |
1401 endif | |
5971 | 1402 |
8506 | 1403 ## If the files is empty remove it. |
6675 | 1404 fclose (instfid); |
1405 t = dir (instpkg); | |
5971 | 1406 if (t.bytes <= 0) |
6675 | 1407 unlink (instpkg); |
1408 endif | |
1409 | |
1410 if (instfid != archfid) | |
1411 fclose (archfid); | |
1412 t = dir (archpkg); | |
1413 if (t.bytes <= 0) | |
1414 unlink (archpkg); | |
1415 endif | |
5971 | 1416 endif |
5955 | 1417 endif |
1418 endfunction | |
1419 | |
6925 | 1420 function copy_files (desc, packdir, global_install) |
8506 | 1421 ## Create the installation directory. |
6496 | 1422 if (! exist (desc.dir, "dir")) |
1423 [status, output] = mkdir (desc.dir); | |
1424 if (status != 1) | |
1425 error ("couldn't create installation directory %s : %s", | |
1426 desc.dir, output); | |
6020 | 1427 endif |
6496 | 1428 endif |
6020 | 1429 |
6925 | 1430 octfiledir = getarchdir (desc); |
1431 | |
8506 | 1432 ## Copy the files from "inst" to installdir. |
6496 | 1433 instdir = fullfile (packdir, "inst"); |
1434 if (! dirempty (instdir)) | |
1435 [status, output] = copyfile (fullfile (instdir, "*"), desc.dir); | |
1436 if (status != 1) | |
1437 rm_rf (desc.dir); | |
1438 error ("couldn't copy files to the installation directory"); | |
5801 | 1439 endif |
6925 | 1440 if (exist (fullfile (desc.dir, getarch ()), "dir") && |
1441 ! strcmp (fullfile (desc.dir, getarch ()), octfiledir)) | |
1442 if (! exist (octfiledir, "dir")) | |
8506 | 1443 ## Can be required to create upto three levels of dirs. |
6925 | 1444 octm1 = fileparts (octfiledir); |
1445 if (! exist (octm1, "dir")) | |
1446 octm2 = fileparts (octm1); | |
1447 if (! exist (octm2, "dir")) | |
1448 octm3 = fileparts (octm2); | |
1449 if (! exist (octm3, "dir")) | |
1450 [status, output] = mkdir (octm3); | |
1451 if (status != 1) | |
1452 rm_rf (desc.dir); | |
1453 error ("couldn't create installation directory %s : %s", | |
1454 octm3, output); | |
1455 endif | |
1456 endif | |
1457 [status, output] = mkdir (octm2); | |
1458 if (status != 1) | |
1459 rm_rf (desc.dir); | |
1460 error ("couldn't create installation directory %s : %s", | |
1461 octm2, output); | |
1462 endif | |
1463 endif | |
1464 [status, output] = mkdir (octm1); | |
1465 if (status != 1) | |
1466 rm_rf (desc.dir); | |
1467 error ("couldn't create installation directory %s : %s", | |
1468 octm1, output); | |
1469 endif | |
1470 endif | |
1471 [status, output] = mkdir (octfiledir); | |
1472 if (status != 1) | |
1473 rm_rf (desc.dir); | |
1474 error ("couldn't create installation directory %s : %s", | |
1475 octfiledir, output); | |
1476 endif | |
1477 endif | |
1478 [status, output] = movefile (fullfile (desc.dir, getarch (), "*"), | |
1479 octfiledir); | |
1480 rm_rf (fullfile (desc.dir, getarch ())); | |
1481 | |
1482 if (status != 1) | |
1483 rm_rf (desc.dir); | |
1484 rm_rf (octfiledir); | |
1485 error ("couldn't copy files to the installation directory"); | |
1486 endif | |
1487 endif | |
1488 | |
6496 | 1489 endif |
5801 | 1490 |
8506 | 1491 ## Create the "packinfo" directory. |
6496 | 1492 packinfo = fullfile (desc.dir, "packinfo"); |
1493 [status, msg] = mkdir (packinfo); | |
1494 if (status != 1) | |
1495 rm_rf (desc.dir); | |
6925 | 1496 rm_rf (octfiledir); |
6496 | 1497 error ("couldn't create packinfo directory: %s", msg); |
1498 endif | |
5801 | 1499 |
8506 | 1500 ## Copy DESCRIPTION. |
6496 | 1501 [status, output] = copyfile (fullfile (packdir, "DESCRIPTION"), packinfo); |
1502 if (status != 1) | |
6925 | 1503 rm_rf (desc.dir); |
1504 rm_rf (octfiledir); | |
1505 error ("couldn't copy DESCRIPTION: %s", output); | |
6496 | 1506 endif |
5801 | 1507 |
8506 | 1508 ## Copy COPYING. |
6496 | 1509 [status, output] = copyfile (fullfile (packdir, "COPYING"), packinfo); |
1510 if (status != 1) | |
6925 | 1511 rm_rf (desc.dir); |
1512 rm_rf (octfiledir); | |
1513 error ("couldn't copy COPYING: %s", output); | |
6496 | 1514 endif |
5993 | 1515 |
8506 | 1516 ## If the file ChangeLog exists, copy it. |
7498 | 1517 changelog_file = fullfile (packdir, "ChangeLog"); |
1518 if (exist (changelog_file, "file")) | |
1519 [status, output] = copyfile (changelog_file, packinfo); | |
6496 | 1520 if (status != 1) |
1521 rm_rf (desc.dir); | |
6925 | 1522 rm_rf (octfiledir); |
6496 | 1523 error ("couldn't copy ChangeLog file: %s", output); |
6254 | 1524 endif |
6496 | 1525 endif |
6254 | 1526 |
6496 | 1527 ## Is there an INDEX file to copy or should we generate one? |
7498 | 1528 index_file = fullfile (packdir, "INDEX"); |
1529 if (exist(index_file, "file")) | |
1530 [status, output] = copyfile (index_file, packinfo); | |
6496 | 1531 if (status != 1) |
1532 rm_rf (desc.dir); | |
6925 | 1533 rm_rf (octfiledir); |
6496 | 1534 error ("couldn't copy INDEX file: %s", output); |
5801 | 1535 endif |
6496 | 1536 else |
1537 try | |
7498 | 1538 write_index (desc, fullfile (packdir, "inst"), |
6925 | 1539 fullfile (packinfo, "INDEX"), global_install); |
6496 | 1540 catch |
1541 rm_rf (desc.dir); | |
6925 | 1542 rm_rf (octfiledir); |
6695 | 1543 rethrow (lasterror ()); |
6496 | 1544 end_try_catch |
1545 endif | |
5971 | 1546 |
6496 | 1547 ## Is there an 'on_uninstall.m' to install? |
7498 | 1548 fon_uninstall = fullfile (packdir, "on_uninstall.m"); |
6496 | 1549 if (exist (fon_uninstall, "file")) |
1550 [status, output] = copyfile (fon_uninstall, packinfo); | |
1551 if (status != 1) | |
1552 rm_rf (desc.dir); | |
6925 | 1553 rm_rf (octfiledir); |
6496 | 1554 error ("couldn't copy on_uninstall.m: %s", output); |
5971 | 1555 endif |
6496 | 1556 endif |
5971 | 1557 |
8506 | 1558 ## Is there a doc/ directory that needs to be installed? |
6496 | 1559 docdir = fullfile (packdir, "doc"); |
1560 if (exist (docdir, "dir") && ! dirempty (docdir)) | |
6925 | 1561 [status, output] = copyfile (docdir, desc.dir); |
6496 | 1562 endif |
1563 | |
8506 | 1564 ## Is there a bin/ directory that needs to be installed? |
6950 | 1565 ## FIXME: Need to treat architecture dependent files in bin/ |
6496 | 1566 bindir = fullfile (packdir, "bin"); |
1567 if (exist (bindir, "dir") && ! dirempty (bindir)) | |
6925 | 1568 [status, output] = copyfile (bindir, desc.dir); |
6496 | 1569 endif |
5801 | 1570 endfunction |
1571 | |
6925 | 1572 function finish_installation (desc, packdir, global_install) |
6496 | 1573 ## Is there a post-install to call? |
1574 if (exist (fullfile (packdir, "post_install.m"), "file")) | |
1575 wd = pwd (); | |
1576 try | |
1577 cd (packdir); | |
1578 post_install (desc); | |
1579 cd (wd); | |
1580 catch | |
1581 cd (wd); | |
1582 rm_rf (desc.dir); | |
6925 | 1583 rm_rf (getarchdir (desc), global_install); |
6695 | 1584 rethrow (lasterror ()); |
6496 | 1585 end_try_catch |
1586 endif | |
5801 | 1587 endfunction |
1588 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
1589 function generate_lookfor_cache (desc) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
1590 gen_doc_cache (genpath (desc.dir)); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
1591 endfunction |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
1592 |
7498 | 1593 ## Make sure the package contains the essential files. |
6496 | 1594 function verify_directory (dir) |
1595 needed_files = {"COPYING", "DESCRIPTION"}; | |
1596 for f = needed_files | |
1597 if (! exist (fullfile (dir, f{1}), "file")) | |
1598 error ("package is missing file: %s", f{1}); | |
1599 endif | |
1600 endfor | |
5801 | 1601 endfunction |
1602 | |
8506 | 1603 ## Parse the DESCRIPTION file. |
6496 | 1604 function desc = get_description (filename) |
1605 [fid, msg] = fopen (filename, "r"); | |
1606 if (fid == -1) | |
1607 error ("the DESCRIPTION file %s could not be read: %s", filename, msg); | |
1608 endif | |
1609 | |
1610 desc = struct (); | |
5801 | 1611 |
6496 | 1612 line = fgetl (fid); |
1613 while (line != -1) | |
1614 if (line(1) == "#") | |
8506 | 1615 ## Comments, do nothing. |
6496 | 1616 elseif (isspace(line(1))) |
1617 ## Continuation lines | |
1618 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
|
1619 desc.(keyword) = cstrcat (desc.(keyword), " ", rstrip(line)); |
6496 | 1620 endif |
5801 | 1621 else |
6496 | 1622 ## Keyword/value pair |
1623 colon = find (line == ":"); | |
1624 if (length (colon) == 0) | |
1625 disp ("skipping line"); | |
1626 else | |
1627 colon = colon(1); | |
1628 keyword = tolower (strip (line(1:colon-1))); | |
7498 | 1629 value = strip (line (colon+1:end)); |
6496 | 1630 if (length (value) == 0) |
1631 fclose (fid); | |
1632 error ("the keyword %s has an empty value", desc.keywords{end}); | |
1633 endif | |
1634 desc.(keyword) = value; | |
1635 endif | |
5801 | 1636 endif |
6496 | 1637 line = fgetl (fid); |
1638 endwhile | |
1639 fclose (fid); | |
1640 | |
8506 | 1641 ## Make sure all is okay. |
6496 | 1642 needed_fields = {"name", "version", "date", "title", ... |
1643 "author", "maintainer", "description"}; | |
1644 for f = needed_fields | |
1645 if (! isfield (desc, f{1})) | |
1646 error ("description is missing needed field %s", f{1}); | |
1647 endif | |
1648 endfor | |
1649 desc.version = fix_version (desc.version); | |
1650 if (isfield (desc, "depends")) | |
1651 desc.depends = fix_depends (desc.depends); | |
1652 else | |
1653 desc.depends = ""; | |
1654 endif | |
1655 desc.name = tolower (desc.name); | |
5801 | 1656 endfunction |
1657 | |
7498 | 1658 ## Make sure the version string v is a valid x.y.z version string |
8506 | 1659 ## Examples: "0.1" => "0.1.0", "monkey" => error(...). |
6496 | 1660 function out = fix_version (v) |
1661 dots = find (v == "."); | |
1662 if (length (dots) == 1) | |
1663 major = str2num (v(1:dots-1)); | |
1664 minor = str2num (v(dots+1:end)); | |
1665 if (length (major) != 0 && length (minor) != 0) | |
1666 out = sprintf ("%d.%d.0", major, minor); | |
1667 return; | |
5801 | 1668 endif |
6496 | 1669 elseif (length (dots) == 2) |
1670 major = str2num (v(1:dots(1)-1)); | |
1671 minor = str2num (v(dots(1)+1:dots(2)-1)); | |
7498 | 1672 rev = str2num (v(dots(2)+1:end)); |
6496 | 1673 if (length (major) != 0 && length (minor) != 0 && length (rev) != 0) |
1674 out = sprintf ("%d.%d.%d", major, minor, rev); | |
1675 return; | |
1676 endif | |
1677 endif | |
1678 error ("bad version string: %s", v); | |
5801 | 1679 endfunction |
1680 | |
7498 | 1681 ## Make sure the depends field is of the right format. |
5801 | 1682 ## This function returns a cell of structures with the following fields: |
1683 ## package, version, operator | |
6496 | 1684 function deps_cell = fix_depends (depends) |
1685 deps = split_by (tolower (depends), ","); | |
1686 deps_cell = cell (1, length (deps)); | |
1687 | |
8506 | 1688 ## For each dependency. |
6496 | 1689 for i = 1:length (deps) |
1690 dep = deps{i}; | |
1691 lpar = find (dep == "("); | |
1692 rpar = find (dep == ")"); | |
1693 ## Does the dependency specify a version | |
8506 | 1694 ## Example: package(>= version). |
6496 | 1695 if (length (lpar) == 1 && length (rpar) == 1) |
1696 package = tolower (strip (dep(1:lpar-1))); | |
1697 sub = dep(lpar(1)+1:rpar(1)-1); | |
1698 parts = split_by (sub, " "); | |
1699 idx = []; | |
1700 for r = 1:size (parts, 1) | |
1701 if (length (parts{r}) > 0) | |
1702 idx(end+1) = r; | |
1703 endif | |
1704 endfor | |
1705 | |
1706 if (length (idx) != 2) | |
1707 error ("incorrect syntax for dependency `%s' in the DESCRIPTION file\n", | |
1708 dep); | |
1709 endif | |
1710 operator = parts{idx(1)}; | |
1711 if (! any (strcmp (operator, {">", ">=", "<=", "<", "=="}))) | |
1712 error ("unsupported operator: %s", operator); | |
1713 endif | |
1714 version = fix_version (parts{idx(2)}); | |
1715 | |
1716 ## If no version is specified for the dependency | |
1717 ## we say that the version should be greater than | |
8506 | 1718 ## or equal to "0.0.0". |
6496 | 1719 else |
1720 package = tolower (strip (dep)); | |
1721 operator = ">="; | |
1722 version = "0.0.0"; | |
1723 endif | |
1724 deps_cell{i} = struct ("package", package, "operator", operator, | |
1725 "version", version); | |
1726 endfor | |
5801 | 1727 endfunction |
1728 | |
7498 | 1729 ## Strip the text of spaces from the right |
8506 | 1730 ## Example: " hello world " => " hello world" |
1731 ## FIXME -- is this the same as deblank? | |
6496 | 1732 function text = rstrip (text) |
1733 chars = find (! isspace (text)); | |
1734 if (length (chars) > 0) | |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8174
diff
changeset
|
1735 ## FIXME: shouldn't it be text = text(1:chars(end)); |
6496 | 1736 text = text (chars(1):end); |
1737 else | |
1738 text = ""; | |
1739 endif | |
5801 | 1740 endfunction |
1741 | |
8506 | 1742 ## Strip the text of spaces from the left and the right. |
5801 | 1743 ## Example: " hello world " => "hello world" |
6496 | 1744 function text = strip (text) |
1745 chars = find (! isspace (text)); | |
1746 if (length (chars) > 0) | |
1747 text = text(chars(1):chars(end)); | |
1748 else | |
1749 text = ""; | |
1750 endif | |
5801 | 1751 endfunction |
1752 | |
8506 | 1753 ## Split the text into a cell array of strings by sep. |
5801 | 1754 ## Example: "A, B" => {"A", "B"} (with sep = ",") |
6496 | 1755 function out = split_by (text, sep) |
1756 text_matrix = split (text, sep); | |
1757 num_words = size (text_matrix, 1); | |
1758 out = cell (num_words, 1); | |
1759 for i = 1:num_words | |
1760 out{i} = strip (text_matrix(i, :)); | |
1761 endfor | |
5801 | 1762 endfunction |
1763 | |
7498 | 1764 ## Create an INDEX file for a package that doesn't provide one. |
5801 | 1765 ## 'desc' describes the package. |
7498 | 1766 ## 'dir' is the 'inst' directory in temporary directory. |
1767 ## 'index_file' is the name (including path) of resulting INDEX file. | |
1768 function write_index (desc, dir, index_file, global_install) | |
6496 | 1769 ## Get names of functions in dir |
1770 [files, err, msg] = readdir (dir); | |
1771 if (err) | |
1772 error ("couldn't read directory %s: %s", dir, msg); | |
1773 endif | |
1774 | |
8506 | 1775 ## Check for architecture dependent files. |
6925 | 1776 tmpdir = getarchdir (desc); |
6634 | 1777 if (exist (tmpdir, "dir")) |
1778 [files2, err, msg] = readdir (tmpdir); | |
1779 if (err) | |
1780 error ("couldn't read directory %s: %s", tmpdir, msg); | |
1781 endif | |
1782 files = [files; files2]; | |
1783 endif | |
1784 | |
6496 | 1785 functions = {}; |
1786 for i = 1:length (files) | |
1787 file = files{i}; | |
1788 lf = length (file); | |
1789 if (lf > 2 && strcmp (file(end-1:end), ".m")) | |
1790 functions{end+1} = file(1:end-2); | |
1791 elseif (lf > 4 && strcmp (file(end-3:end), ".oct")) | |
1792 functions{end+1} = file(1:end-4); | |
5801 | 1793 endif |
6496 | 1794 endfor |
1795 | |
1796 ## Does desc have a categories field? | |
1797 if (! isfield (desc, "categories")) | |
1798 error ("the DESCRIPTION file must have a Categories field, when no INDEX file is given"); | |
1799 endif | |
1800 categories = split_by (desc.categories, ","); | |
1801 if (length (categories) < 1) | |
1802 error ("the Category field is empty"); | |
1803 endif | |
1804 | |
8506 | 1805 ## Write INDEX. |
7498 | 1806 fid = fopen (index_file, "w"); |
6496 | 1807 if (fid == -1) |
7498 | 1808 error ("couldn't open %s for writing.", index_file); |
6496 | 1809 endif |
1810 fprintf (fid, "%s >> %s\n", desc.name, desc.title); | |
1811 fprintf (fid, "%s\n", categories{1}); | |
1812 fprintf (fid, " %s\n", functions{:}); | |
1813 fclose (fid); | |
5801 | 1814 endfunction |
1815 | |
6820 | 1816 function bad_deps = get_unsatisfied_deps (desc, installed_pkgs_lst) |
6496 | 1817 bad_deps = {}; |
5801 | 1818 |
8506 | 1819 ## For each dependency. |
6496 | 1820 for i = 1:length (desc.depends) |
1821 dep = desc.depends{i}; | |
5801 | 1822 |
6496 | 1823 ## Is the current dependency Octave? |
1824 if (strcmp (dep.package, "octave")) | |
1825 if (! compare_versions (OCTAVE_VERSION, dep.version, dep.operator)) | |
1826 bad_deps{end+1} = dep; | |
6258 | 1827 endif |
8506 | 1828 ## Is the current dependency not Octave? |
6496 | 1829 else |
1830 ok = false; | |
6820 | 1831 for i = 1:length (installed_pkgs_lst) |
1832 cur_name = installed_pkgs_lst{i}.name; | |
1833 cur_version = installed_pkgs_lst{i}.version; | |
6496 | 1834 if (strcmp (dep.package, cur_name) |
1835 && compare_versions (cur_version, dep.version, dep.operator)) | |
1836 ok = true; | |
1837 break; | |
6258 | 1838 endif |
1839 endfor | |
6496 | 1840 if (! ok) |
1841 bad_deps{end+1} = dep; | |
1842 endif | |
5801 | 1843 endif |
6496 | 1844 endfor |
1845 endfunction | |
1846 | |
1847 function [out1, out2] = installed_packages (local_list, global_list) | |
8506 | 1848 ## Get the list of installed packages. |
6496 | 1849 try |
1850 local_packages = load (local_list).local_packages; | |
1851 catch | |
1852 local_packages = {}; | |
1853 end_try_catch | |
1854 try | |
6675 | 1855 global_packages = load (global_list).global_packages; |
6496 | 1856 catch |
1857 global_packages = {}; | |
1858 end_try_catch | |
6820 | 1859 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 1860 |
1861 ## Eliminate duplicates in the installed package list. | |
8506 | 1862 ## Locally installed packages take precedence. |
6496 | 1863 dup = []; |
6820 | 1864 for i = 1:length (installed_pkgs_lst) |
6496 | 1865 if (find (dup, i)) |
1866 continue; | |
5801 | 1867 endif |
6820 | 1868 for j = (i+1):length (installed_pkgs_lst) |
6496 | 1869 if (find (dup, j)) |
1870 continue; | |
1871 endif | |
6820 | 1872 if (strcmp (installed_pkgs_lst{i}.name, installed_pkgs_lst{j}.name)) |
6496 | 1873 dup = [dup, j]; |
1874 endif | |
5987 | 1875 endfor |
6496 | 1876 endfor |
1877 if (! isempty(dup)) | |
6820 | 1878 installed_pkgs_lst(dup) = []; |
6496 | 1879 endif |
1880 | |
8506 | 1881 ## Now check if the package is loaded. |
6645 | 1882 tmppath = strrep (path(), "\\", "/"); |
6820 | 1883 for i = 1:length (installed_pkgs_lst) |
1884 if (findstr (tmppath, strrep (installed_pkgs_lst{i}.dir, "\\", "/"))) | |
1885 installed_pkgs_lst{i}.loaded = true; | |
6616 | 1886 else |
6820 | 1887 installed_pkgs_lst{i}.loaded = false; |
6616 | 1888 endif |
1889 endfor | |
6675 | 1890 for i = 1:length (local_packages) |
6776 | 1891 if (findstr (tmppath, strrep (local_packages{i}.dir, "\\", "/"))) |
6675 | 1892 local_packages{i}.loaded = true; |
1893 else | |
1894 local_packages{i}.loaded = false; | |
1895 endif | |
1896 endfor | |
1897 for i = 1:length (global_packages) | |
6776 | 1898 if (findstr (tmppath, strrep (global_packages{i}.dir, "\\", "/"))) |
6675 | 1899 global_packages{i}.loaded = true; |
1900 else | |
1901 global_packages{i}.loaded = false; | |
1902 endif | |
1903 endfor | |
6616 | 1904 |
6496 | 1905 ## Should we return something? |
1906 if (nargout == 2) | |
1907 out1 = local_packages; | |
1908 out2 = global_packages; | |
1909 return; | |
1910 elseif (nargout == 1) | |
6820 | 1911 out1 = installed_pkgs_lst; |
6496 | 1912 return; |
1913 endif | |
1914 | |
8506 | 1915 ## We shouldn't return something, so we'll print something. |
6820 | 1916 num_packages = length (installed_pkgs_lst); |
6496 | 1917 if (num_packages == 0) |
1918 printf ("no packages installed.\n"); | |
1919 return; | |
1920 endif | |
1921 | |
8506 | 1922 ## Compute the maximal lengths of name, version, and dir. |
6496 | 1923 h1 = "Package Name"; |
1924 h2 = "Version"; | |
1925 h3 = "Installation directory"; | |
1926 max_name_length = length (h1); | |
1927 max_version_length = length (h2); | |
1928 names = cell (num_packages, 1); | |
1929 for i = 1:num_packages | |
1930 max_name_length = max (max_name_length, | |
6820 | 1931 length (installed_pkgs_lst{i}.name)); |
6496 | 1932 max_version_length = max (max_version_length, |
6820 | 1933 length (installed_pkgs_lst{i}.version)); |
1934 names{i} = installed_pkgs_lst{i}.name; | |
6496 | 1935 endfor |
6698 | 1936 max_dir_length = terminal_size()(2) - max_name_length - ... |
1937 max_version_length - 7; | |
1938 if (max_dir_length < 20) | |
1939 max_dir_length = Inf; | |
1940 endif | |
1941 | |
6616 | 1942 h1 = postpad (h1, max_name_length + 1, " "); |
6496 | 1943 h2 = postpad (h2, max_version_length, " ");; |
1944 | |
8506 | 1945 ## Print a header. |
6496 | 1946 header = sprintf("%s | %s | %s\n", h1, h2, h3); |
1947 printf (header); | |
1948 tmp = sprintf (repmat ("-", 1, length(header)-1)); | |
1949 tmp(length(h1)+2) = "+"; | |
1950 tmp(length(h1)+length(h2)+5) = "+"; | |
1951 printf ("%s\n", tmp); | |
1952 | |
8506 | 1953 ## Print the packages. |
6616 | 1954 format = sprintf ("%%%ds %%1s| %%%ds | %%s\n", max_name_length, |
6496 | 1955 max_version_length); |
1956 [dummy, idx] = sort (names); | |
1957 for i = 1:num_packages | |
6820 | 1958 cur_name = installed_pkgs_lst{idx(i)}.name; |
1959 cur_version = installed_pkgs_lst{idx(i)}.version; | |
1960 cur_dir = installed_pkgs_lst{idx(i)}.dir; | |
6698 | 1961 if (length (cur_dir) > max_dir_length) |
1962 first_char = length (cur_dir) - max_dir_length + 4; | |
1963 first_filesep = strfind (cur_dir(first_char:end), filesep()); | |
1964 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
|
1965 cur_dir = cstrcat ("...", |
6698 | 1966 cur_dir((first_char + first_filesep(1) - 1):end)); |
1967 else | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1968 cur_dir = cstrcat ("...", cur_dir(first_char:end)); |
6698 | 1969 endif |
1970 endif | |
6820 | 1971 if (installed_pkgs_lst{idx(i)}.loaded) |
6616 | 1972 cur_loaded = "*"; |
1973 else | |
1974 cur_loaded = " "; | |
1975 endif | |
1976 printf (format, cur_name, cur_loaded, cur_version, cur_dir); | |
6496 | 1977 endfor |
5801 | 1978 endfunction |
1979 | |
6496 | 1980 function load_packages (files, handle_deps, local_list, global_list) |
6820 | 1981 installed_pkgs_lst = installed_packages (local_list, global_list); |
1982 num_packages = length (installed_pkgs_lst); | |
6496 | 1983 |
8506 | 1984 ## Read package names and installdirs into a more convenient format. |
6496 | 1985 pnames = pdirs = cell (1, num_packages); |
1986 for i = 1:num_packages | |
6820 | 1987 pnames{i} = installed_pkgs_lst{i}.name; |
1988 pdirs{i} = installed_pkgs_lst{i}.dir; | |
6496 | 1989 endfor |
1990 | |
8506 | 1991 ## Load all. |
6496 | 1992 if (length (files) == 1 && strcmp (files{1}, "all")) |
6820 | 1993 idx = [1:length(installed_pkgs_lst)]; |
8506 | 1994 ## Load auto. |
6695 | 1995 elseif (length (files) == 1 && strcmp (files{1}, "auto")) |
1996 idx = []; | |
6820 | 1997 for i = 1:length (installed_pkgs_lst) |
6496 | 1998 if (exist (fullfile (pdirs{i}, "packinfo", ".autoload"), "file")) |
6695 | 1999 idx (end + 1) = i; |
6496 | 2000 endif |
6037 | 2001 endfor |
8506 | 2002 ## Load package_name1 ... |
6496 | 2003 else |
6695 | 2004 idx = []; |
6496 | 2005 for i = 1:length (files) |
6695 | 2006 idx2 = find (strcmp (pnames, files{i})); |
2007 if (! any (idx2)) | |
6496 | 2008 error ("package %s is not installed", files{i}); |
2009 endif | |
6695 | 2010 idx (end + 1) = idx2; |
6496 | 2011 endfor |
2012 endif | |
6037 | 2013 |
8506 | 2014 ## Load the packages, but take care of the ordering of dependencies. |
6925 | 2015 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, true); |
5801 | 2016 endfunction |
5928 | 2017 |
6496 | 2018 function unload_packages (files, handle_deps, local_list, global_list) |
6820 | 2019 installed_pkgs_lst = installed_packages (local_list, global_list); |
2020 num_packages = length (installed_pkgs_lst); | |
6496 | 2021 |
8506 | 2022 ## Read package names and installdirs into a more convenient format. |
6496 | 2023 pnames = pdirs = cell (1, num_packages); |
2024 for i = 1:num_packages | |
6820 | 2025 pnames{i} = installed_pkgs_lst{i}.name; |
2026 pdirs{i} = installed_pkgs_lst{i}.dir; | |
2027 pdeps{i} = installed_pkgs_lst{i}.depends; | |
6496 | 2028 endfor |
2029 | |
8506 | 2030 ## Get the current octave path. |
6496 | 2031 p = split_by (path(), pathsep ()); |
6203 | 2032 |
6496 | 2033 if (length (files) == 1 && strcmp (files{1}, "all")) |
8506 | 2034 ## Unload all. |
2035 dirs = pdirs; | |
2036 desc = installed_pkgs_lst; | |
6496 | 2037 else |
8506 | 2038 ## Unload package_name1 ... |
6496 | 2039 dirs = {}; |
6925 | 2040 desc = {}; |
6496 | 2041 for i = 1:length (files) |
7208 | 2042 idx = strcmp (pnames, files{i}); |
6496 | 2043 if (! any (idx)) |
2044 error ("package %s is not installed", files{i}); | |
2045 endif | |
7208 | 2046 dirs{end+1} = pdirs{idx}; |
2047 desc{end+1} = installed_pkgs_lst{idx}; | |
6496 | 2048 endfor |
2049 endif | |
2050 | |
8506 | 2051 ## Check for architecture dependent directories. |
6614 | 2052 archdirs = {}; |
2053 for i = 1:length (dirs) | |
7208 | 2054 tmpdir = getarchdir (desc{i}); |
6614 | 2055 if (exist (tmpdir, "dir")) |
7208 | 2056 archdirs{end+1} = dirs{i}; |
2057 archdirs{end+1} = tmpdir; | |
6925 | 2058 else |
7208 | 2059 archdirs{end+1} = dirs{i}; |
6614 | 2060 endif |
2061 endfor | |
2062 | |
8506 | 2063 ## Unload the packages. |
6925 | 2064 for i = 1:length (archdirs) |
2065 d = archdirs{i}; | |
6496 | 2066 idx = strcmp (p, d); |
2067 if (any (idx)) | |
2068 rmpath (d); | |
8506 | 2069 ## FIXME: We should also check if we need to remove items from |
2070 ## EXEC_PATH. | |
6203 | 2071 endif |
6496 | 2072 endfor |
6203 | 2073 endfunction |
2074 | |
5928 | 2075 function [status_out, msg_out] = rm_rf (dir) |
6925 | 2076 if (exist (dir)) |
2077 crr = confirm_recursive_rmdir (); | |
2078 unwind_protect | |
2079 confirm_recursive_rmdir (false); | |
2080 [status, msg] = rmdir (dir, "s"); | |
2081 unwind_protect_cleanup | |
2082 confirm_recursive_rmdir (crr); | |
2083 end_unwind_protect | |
2084 else | |
2085 status = 1; | |
2086 msg = ""; | |
2087 endif | |
5928 | 2088 if (nargout > 0) |
2089 status_out = status; | |
2090 endif | |
2091 if (nargout > 1) | |
2092 msg_out = msg; | |
2093 endif | |
2094 endfunction | |
5971 | 2095 |
2096 function emp = dirempty (nm, ign) | |
6925 | 2097 if (exist (nm, "dir")) |
2098 if (nargin < 2) | |
2099 ign = {".", ".."}; | |
2100 else | |
2101 ign = [{".", ".."}, ign]; | |
2102 endif | |
2103 l = dir (nm); | |
2104 for i = 1:length (l) | |
2105 found = false; | |
2106 for j = 1:length (ign) | |
2107 if (strcmp (l(i).name, ign{j})) | |
2108 found = true; | |
2109 break; | |
2110 endif | |
2111 endfor | |
2112 if (! found) | |
2113 emp = false; | |
2114 return | |
5971 | 2115 endif |
2116 endfor | |
6925 | 2117 emp = true; |
2118 else | |
2119 emp = true; | |
2120 endif | |
5971 | 2121 endfunction |
6614 | 2122 |
2123 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
|
2124 persistent _arch = cstrcat (octave_config_info("canonical_host_type"), ... |
6675 | 2125 "-", octave_config_info("api_version")); |
6614 | 2126 arch = _arch; |
2127 endfunction | |
6645 | 2128 |
6925 | 2129 function archprefix = getarchprefix (desc, global_install) |
2130 if ((nargin == 2 && global_install) || (nargin < 2 && issuperuser ())) | |
2131 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
|
2132 "packages", cstrcat(desc.name, "-", desc.version)); |
6925 | 2133 else |
2134 archprefix = desc.dir; | |
2135 endif | |
2136 endfunction | |
2137 | |
2138 function archdir = getarchdir (desc) | |
2139 archdir = fullfile (desc.archprefix, getarch()); | |
2140 endfunction | |
2141 | |
2142 function s = issuperuser () | |
2143 if ((ispc () && ! isunix ()) || (geteuid() == 0)) | |
2144 s = true; | |
2145 else | |
2146 s = false; | |
2147 endif | |
2148 endfunction | |
2149 | |
6645 | 2150 function [status, output] = shell (cmd) |
2151 persistent have_sh; | |
2152 | |
2153 cmd = strrep (cmd, "\\", "/"); | |
2154 if (ispc () && ! isunix ()) | |
2155 if (isempty(have_sh)) | |
2156 if (system("sh.exe -c \"exit\"")) | |
2157 have_sh = false; | |
2158 else | |
2159 have_sh = true; | |
2160 endif | |
2161 endif | |
2162 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
|
2163 [status, output] = system (cstrcat ("sh.exe -c \"", cmd, "\"")); |
6645 | 2164 else |
2165 error ("Can not find the command shell") | |
2166 endif | |
2167 else | |
2168 [status, output] = system (cmd); | |
2169 endif | |
2170 endfunction | |
6695 | 2171 |
2172 function newdesc = save_order (desc) | |
2173 newdesc = {}; | |
2174 for i = 1 : length(desc) | |
2175 deps = desc{i}.depends; | |
2176 if (isempty (deps) || (length (deps) == 1 && | |
2177 strcmp(deps{1}.package, "octave"))) | |
2178 newdesc {end + 1} = desc{i}; | |
2179 else | |
2180 tmpdesc = {}; | |
2181 for k = 1 : length (deps) | |
2182 for j = 1 : length (desc) | |
2183 if (strcmp (desc{j}.name, deps{k}.package)) | |
7208 | 2184 tmpdesc{end+1} = desc{j}; |
6695 | 2185 break; |
2186 endif | |
2187 endfor | |
2188 endfor | |
2189 if (! isempty (tmpdesc)) | |
2190 newdesc = {newdesc{:}, save_order(tmpdesc){:}, desc{i}}; | |
2191 else | |
7208 | 2192 newdesc{end+1} = desc{i}; |
6695 | 2193 endif |
2194 endif | |
2195 endfor | |
8506 | 2196 ## Eliminate the duplicates. |
6695 | 2197 idx = []; |
2198 for i = 1 : length (newdesc) | |
2199 for j = (i + 1) : length (newdesc) | |
2200 if (strcmp (newdesc{i}.name, newdesc{j}.name)) | |
2201 idx (end + 1) = j; | |
2202 endif | |
2203 endfor | |
2204 endfor | |
2205 newdesc(idx) = []; | |
2206 endfunction | |
2207 | |
6925 | 2208 function load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, |
2209 global_install) | |
6820 | 2210 idx = load_package_dirs (idx, [], handle_deps, installed_pkgs_lst); |
6695 | 2211 dirs = {}; |
2212 execpath = EXEC_PATH (); | |
2213 for i = idx; | |
6820 | 2214 ndir = installed_pkgs_lst{i}.dir; |
7208 | 2215 dirs{end+1} = ndir; |
6695 | 2216 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
|
2217 execpath = cstrcat (fullfile (dirs{end}, "bin"), ":", execpath); |
6695 | 2218 endif |
7208 | 2219 tmpdir = getarchdir (installed_pkgs_lst{i}); |
6695 | 2220 if (exist (tmpdir, "dir")) |
2221 dirs{end + 1} = tmpdir; | |
6950 | 2222 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
|
2223 execpath = cstrcat (fullfile (dirs{end}, "bin"), ":", execpath); |
6950 | 2224 endif |
6695 | 2225 endif |
2226 endfor | |
2227 | |
8506 | 2228 ## Load the packages. |
6695 | 2229 if (length (dirs) > 0) |
2230 addpath (dirs{:}); | |
2231 endif | |
2232 | |
8506 | 2233 ## Add the binaries to exec_path. |
6695 | 2234 if (! strcmp (EXEC_PATH, execpath)) |
2235 EXEC_PATH (execpath); | |
2236 endif | |
2237 endfunction | |
2238 | |
6820 | 2239 function idx = load_package_dirs (lidx, idx, handle_deps, installed_pkgs_lst) |
6695 | 2240 for i = lidx |
6820 | 2241 if (isfield (installed_pkgs_lst{i}, "loaded") && |
2242 installed_pkgs_lst{i}.loaded) | |
6695 | 2243 continue; |
2244 else | |
2245 if (handle_deps) | |
6820 | 2246 deps = installed_pkgs_lst{i}.depends; |
6695 | 2247 if ((length (deps) > 1) || (length (deps) == 1 && |
2248 ! strcmp(deps{1}.package, "octave"))) | |
2249 tmplidx = []; | |
2250 for k = 1 : length (deps) | |
6820 | 2251 for j = 1 : length (installed_pkgs_lst) |
2252 if (strcmp (installed_pkgs_lst{j}.name, deps{k}.package)) | |
6695 | 2253 tmplidx (end + 1) = j; |
2254 break; | |
2255 endif | |
2256 endfor | |
2257 endfor | |
2258 idx = load_package_dirs (tmplidx, idx, handle_deps, | |
6820 | 2259 installed_pkgs_lst); |
6695 | 2260 endif |
2261 endif | |
2262 if (isempty (find(idx == i))) | |
2263 idx (end + 1) = i; | |
2264 endif | |
2265 endif | |
2266 endfor | |
2267 endfunction | |
6950 | 2268 |
2269 function dep = is_architecture_dependent (nm) | |
7329 | 2270 persistent archdepsuffix = {".oct",".mex",".a",".lib",".so",".so.*",".dll","dylib"}; |
6950 | 2271 |
2272 dep = false; | |
2273 for i = 1 : length (archdepsuffix) | |
7208 | 2274 ext = archdepsuffix{i}; |
6950 | 2275 if (ext(end) == "*") |
2276 isglob = true; | |
2277 ext(end) = []; | |
2278 else | |
2279 isglob = false; | |
2280 endif | |
2281 pos = findstr (nm, ext); | |
2282 if (pos) | |
7208 | 2283 if (! isglob && (length(nm) - pos(end) != length(ext) - 1)) |
6950 | 2284 continue; |
2285 endif | |
2286 dep = true; | |
2287 break; | |
2288 endif | |
2289 endfor | |
2290 endfunction |