comparison scripts/pkg/pkg.m @ 10549:95c3e38098bf

Untabify .m scripts
author Rik <code@nomad.inbox5.com>
date Fri, 23 Apr 2010 11:28:50 -0700
parents 6d1e49abf95f
children 76aba4305f1f
comparison
equal deleted inserted replaced
10548:479536c5bb10 10549:95c3e38098bf
200 persistent user_prefix = false; 200 persistent user_prefix = false;
201 persistent prefix = -1; 201 persistent prefix = -1;
202 persistent archprefix = -1; 202 persistent archprefix = -1;
203 persistent local_list = tilde_expand (fullfile ("~", ".octave_packages")); 203 persistent local_list = tilde_expand (fullfile ("~", ".octave_packages"));
204 persistent global_list = fullfile (OCTAVE_HOME (), "share", "octave", 204 persistent global_list = fullfile (OCTAVE_HOME (), "share", "octave",
205 "octave_packages"); 205 "octave_packages");
206 mlock (); 206 mlock ();
207 207
208 global_install = issuperuser (); 208 global_install = issuperuser ();
209 209
210 if (prefix == -1) 210 if (prefix == -1)
211 if (global_install) 211 if (global_install)
212 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); 212 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages");
213 archprefix = fullfile (octave_config_info ("libexecdir"), 213 archprefix = fullfile (octave_config_info ("libexecdir"),
214 "octave", "packages"); 214 "octave", "packages");
215 else 215 else
216 prefix = fullfile ("~", "octave"); 216 prefix = fullfile ("~", "octave");
217 archprefix = prefix; 217 archprefix = prefix;
218 endif 218 endif
219 prefix = tilde_expand (prefix); 219 prefix = tilde_expand (prefix);
220 archprefix = tilde_expand (archprefix); 220 archprefix = tilde_expand (archprefix);
221 endif 221 endif
222 222
223 available_actions = {"list", "install", "uninstall", "load", ... 223 available_actions = {"list", "install", "uninstall", "load", ...
224 "unload", "prefix", "local_list", ... 224 "unload", "prefix", "local_list", ...
225 "global_list", "rebuild", "build","describe"}; 225 "global_list", "rebuild", "build","describe"};
226 ## Handle input 226 ## Handle input
227 if (length (varargin) == 0 || ! iscellstr (varargin)) 227 if (length (varargin) == 0 || ! iscellstr (varargin))
228 print_usage (); 228 print_usage ();
229 endif 229 endif
230 files = {}; 230 files = {};
233 action = "none"; 233 action = "none";
234 verbose = false; 234 verbose = false;
235 for i = 1:length (varargin) 235 for i = 1:length (varargin)
236 switch (varargin{i}) 236 switch (varargin{i})
237 case "-nodeps" 237 case "-nodeps"
238 deps = false; 238 deps = false;
239 case "-noauto" 239 case "-noauto"
240 auto = -1; 240 auto = -1;
241 case "-auto" 241 case "-auto"
242 auto = 1; 242 auto = 1;
243 case "-verbose" 243 case "-verbose"
244 verbose = true; 244 verbose = true;
245 case "-local" 245 case "-local"
246 global_install = false; 246 global_install = false;
247 if (! user_prefix) 247 if (! user_prefix)
248 prefix = tilde_expand (fullfile ("~", "octave")); 248 prefix = tilde_expand (fullfile ("~", "octave"));
249 archprefix = prefix; 249 archprefix = prefix;
250 endif 250 endif
251 case "-global" 251 case "-global"
252 global_install = true; 252 global_install = true;
253 if (! user_prefix) 253 if (! user_prefix)
254 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); 254 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages");
255 archprefix = fullfile (octave_config_info ("libexecdir"), 255 archprefix = fullfile (octave_config_info ("libexecdir"),
256 "octave", "packages"); 256 "octave", "packages");
257 endif 257 endif
258 case available_actions 258 case available_actions
259 if (strcmp (action, "none")) 259 if (strcmp (action, "none"))
260 action = varargin{i}; 260 action = varargin{i};
261 else 261 else
262 error ("more than one action specified"); 262 error ("more than one action specified");
263 endif 263 endif
264 otherwise 264 otherwise
265 files{end+1} = varargin{i}; 265 files{end+1} = varargin{i};
266 endswitch 266 endswitch
267 endfor 267 endfor
268 268
269 ## Take action 269 ## Take action
270 switch (action) 270 switch (action)
271 case "list" 271 case "list"
272 if (nargout == 0) 272 if (nargout == 0)
273 installed_packages (local_list, global_list); 273 installed_packages (local_list, global_list);
274 elseif (nargout == 1) 274 elseif (nargout == 1)
275 local_packages = installed_packages (local_list, global_list); 275 local_packages = installed_packages (local_list, global_list);
276 elseif (nargout == 2) 276 elseif (nargout == 2)
277 [local_packages, global_packages] = installed_packages (local_list, 277 [local_packages, global_packages] = installed_packages (local_list,
278 global_list); 278 global_list);
279 else 279 else
280 error ("too many output arguments requested"); 280 error ("too many output arguments requested");
281 endif 281 endif
282 282
283 case "install" 283 case "install"
284 if (length (files) == 0) 284 if (length (files) == 0)
285 error ("you must specify at least one filename when calling 'pkg install'"); 285 error ("you must specify at least one filename when calling 'pkg install'");
286 endif 286 endif
287 install (files, deps, auto, prefix, archprefix, verbose, local_list, 287 install (files, deps, auto, prefix, archprefix, verbose, local_list,
288 global_list, global_install); 288 global_list, global_install);
289 289
290 case "uninstall" 290 case "uninstall"
291 if (length (files) == 0) 291 if (length (files) == 0)
292 error ("you must specify at least one package when calling 'pkg uninstall'"); 292 error ("you must specify at least one package when calling 'pkg uninstall'");
293 endif 293 endif
294 uninstall (files, deps, verbose, local_list, 294 uninstall (files, deps, verbose, local_list,
295 global_list, global_install); 295 global_list, global_install);
296 296
297 case "load" 297 case "load"
298 if (length (files) == 0) 298 if (length (files) == 0)
299 error ("you must specify at least one package, 'all' or 'auto' when calling 'pkg load'"); 299 error ("you must specify at least one package, 'all' or 'auto' when calling 'pkg load'");
300 endif 300 endif
301 load_packages (files, deps, local_list, global_list); 301 load_packages (files, deps, local_list, global_list);
302 302
303 case "unload" 303 case "unload"
304 if (length (files) == 0) 304 if (length (files) == 0)
305 error ("you must specify at least one package or 'all' when calling 'pkg unload'"); 305 error ("you must specify at least one package or 'all' when calling 'pkg unload'");
306 endif 306 endif
307 unload_packages (files, deps, local_list, global_list); 307 unload_packages (files, deps, local_list, global_list);
308 308
309 case "prefix" 309 case "prefix"
310 if (length (files) == 0 && nargout == 0) 310 if (length (files) == 0 && nargout == 0)
311 printf ("Installation prefix: %s\n", prefix); 311 printf ("Installation prefix: %s\n", prefix);
312 printf ("Architecture dependent prefix: %s\n", archprefix); 312 printf ("Architecture dependent prefix: %s\n", archprefix);
313 elseif (length (files) == 0 && nargout >= 1) 313 elseif (length (files) == 0 && nargout >= 1)
314 local_packages = prefix; 314 local_packages = prefix;
315 global_packages = archprefix; 315 global_packages = archprefix;
316 elseif (length (files) >= 1 && nargout <= 2 && ischar (files{1})) 316 elseif (length (files) >= 1 && nargout <= 2 && ischar (files{1}))
317 prefix = files{1}; 317 prefix = files{1};
318 prefix = absolute_pathname (prefix); 318 prefix = absolute_pathname (prefix);
319 local_packages = prefix; 319 local_packages = prefix;
320 user_prefix = true; 320 user_prefix = true;
321 if (length (files) >= 2 && ischar (files{2})) 321 if (length (files) >= 2 && ischar (files{2}))
322 archprefix = files{2}; 322 archprefix = files{2};
323 try 323 try
324 archprefix = absolute_pathname (archprefix); 324 archprefix = absolute_pathname (archprefix);
325 catch 325 catch
326 mkdir (archprefix); 326 mkdir (archprefix);
327 warning ("creating the directory %s\n", archprefix); 327 warning ("creating the directory %s\n", archprefix);
328 archprefix = absolute_pathname (archprefix); 328 archprefix = absolute_pathname (archprefix);
329 end_try_catch 329 end_try_catch
330 global_packages = archprefix; 330 global_packages = archprefix;
331 endif 331 endif
332 else 332 else
333 error ("you must specify a prefix directory, or request an output argument"); 333 error ("you must specify a prefix directory, or request an output argument");
334 endif 334 endif
335 335
336 case "local_list" 336 case "local_list"
337 if (length (files) == 0 && nargout == 0) 337 if (length (files) == 0 && nargout == 0)
338 disp (local_list); 338 disp (local_list);
339 elseif (length (files) == 0 && nargout == 1) 339 elseif (length (files) == 0 && nargout == 1)
340 local_packages = local_list; 340 local_packages = local_list;
341 elseif (length (files) == 1 && nargout == 0 && ischar (files{1})) 341 elseif (length (files) == 1 && nargout == 0 && ischar (files{1}))
342 try 342 try
343 local_list = absolute_pathname (files{1}); 343 local_list = absolute_pathname (files{1});
344 catch 344 catch
345 ## Force file to be created 345 ## Force file to be created
346 fclose (fopen (files{1}, "wt")); 346 fclose (fopen (files{1}, "wt"));
347 local_list = absolute_pathname (files{1}); 347 local_list = absolute_pathname (files{1});
348 end_try_catch 348 end_try_catch
349 else 349 else
350 error ("you must specify a local_list file, or request an output argument"); 350 error ("you must specify a local_list file, or request an output argument");
351 endif 351 endif
352 352
353 case "global_list" 353 case "global_list"
354 if (length (files) == 0 && nargout == 0) 354 if (length (files) == 0 && nargout == 0)
355 disp(global_list); 355 disp(global_list);
356 elseif (length (files) == 0 && nargout == 1) 356 elseif (length (files) == 0 && nargout == 1)
357 local_packages = global_list; 357 local_packages = global_list;
358 elseif (length (files) == 1 && nargout == 0 && ischar (files{1})) 358 elseif (length (files) == 1 && nargout == 0 && ischar (files{1}))
359 try 359 try
360 global_list = absolute_pathname (files{1}); 360 global_list = absolute_pathname (files{1});
361 catch 361 catch
362 ## Force file to be created 362 ## Force file to be created
363 fclose (fopen (files{1}, "wt")); 363 fclose (fopen (files{1}, "wt"));
364 global_list = absolute_pathname (files{1}); 364 global_list = absolute_pathname (files{1});
365 end_try_catch 365 end_try_catch
366 else 366 else
367 error ("you must specify a global_list file, or request an output argument"); 367 error ("you must specify a global_list file, or request an output argument");
368 endif 368 endif
369 369
370 case "rebuild" 370 case "rebuild"
371 if (global_install) 371 if (global_install)
372 global_packages = rebuild (prefix, archprefix, global_list, files, 372 global_packages = rebuild (prefix, archprefix, global_list, files,
373 auto, verbose); 373 auto, verbose);
374 global_packages = save_order (global_packages); 374 global_packages = save_order (global_packages);
375 save (global_list, "global_packages"); 375 save (global_list, "global_packages");
376 if (nargout > 0) 376 if (nargout > 0)
377 local_packages = global_packages; 377 local_packages = global_packages;
378 endif 378 endif
379 else 379 else
380 local_packages = rebuild (prefix, archprefix, local_list, files, auto, 380 local_packages = rebuild (prefix, archprefix, local_list, files, auto,
381 verbose); 381 verbose);
382 local_packages = save_order (local_packages); 382 local_packages = save_order (local_packages);
383 save (local_list, "local_packages"); 383 save (local_list, "local_packages");
384 if (nargout == 0) 384 if (nargout == 0)
385 clear ("local_packages"); 385 clear ("local_packages");
386 endif 386 endif
387 endif 387 endif
388 388
389 case "build" 389 case "build"
390 if (length (files) < 2) 390 if (length (files) < 2)
391 error ("you must specify at least the build directory and one filename\nwhen calling 'pkg build'"); 391 error ("you must specify at least the build directory and one filename\nwhen calling 'pkg build'");
392 endif 392 endif
393 build (files, deps, auto, verbose); 393 build (files, deps, auto, verbose);
394 394
395 case "describe" 395 case "describe"
396 if (length (files) == 0) 396 if (length (files) == 0)
397 error ("you must specify at least one package or 'all' when calling 'pkg describe'"); 397 error ("you must specify at least one package or 'all' when calling 'pkg describe'");
398 endif 398 endif
399 ## FIXME: the name of the output variables is inconsistent 399 ## FIXME: the name of the output variables is inconsistent
400 ## with their content 400 ## with their content
401 switch (nargout) 401 switch (nargout)
402 case 0 402 case 0
403 describe (files, verbose, local_list, global_list); 403 describe (files, verbose, local_list, global_list);
404 case 1 404 case 1
405 pkg_desc_list = describe (files, verbose, local_list, ... 405 pkg_desc_list = describe (files, verbose, local_list, ...
406 global_list); 406 global_list);
407 local_packages = pkg_desc_list; 407 local_packages = pkg_desc_list;
408 case 2 408 case 2
409 [pkg_desc_list, flag] = describe (files, verbose, local_list, ... 409 [pkg_desc_list, flag] = describe (files, verbose, local_list, ...
410 global_list); 410 global_list);
411 local_packages = pkg_desc_list; 411 local_packages = pkg_desc_list;
412 global_packages = flag; 412 global_packages = flag;
413 otherwise 413 otherwise
414 error ("you can request at most two outputs when calling 'pkg describe'"); 414 error ("you can request at most two outputs when calling 'pkg describe'");
415 endswitch 415 endswitch
416 416
417 otherwise 417 otherwise
418 error ("you must specify a valid action for 'pkg'. See 'help pkg' for details"); 418 error ("you must specify a valid action for 'pkg'. See 'help pkg' for details");
419 endswitch 419 endswitch
420 endfunction 420 endfunction
421 421
445 endif 445 endif
446 if (exist (descfile, "file")) 446 if (exist (descfile, "file"))
447 desc = get_description (descfile); 447 desc = get_description (descfile);
448 desc.dir = fullfile (prefix, dirlist{k}); 448 desc.dir = fullfile (prefix, dirlist{k});
449 desc.archprefix = fullfile (archprefix, cstrcat (desc.name, "-", 449 desc.archprefix = fullfile (archprefix, cstrcat (desc.name, "-",
450 desc.version)); 450 desc.version));
451 if (auto != 0) 451 if (auto != 0)
452 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file")) 452 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file"))
453 unlink (fullfile (desc.dir, "packinfo", ".autoload")); 453 unlink (fullfile (desc.dir, "packinfo", ".autoload"));
454 endif 454 endif
455 if (auto < 0) 455 if (auto < 0)
456 desc.autoload = 0; 456 desc.autoload = 0;
457 elseif (auto > 0) 457 elseif (auto > 0)
458 desc.autoload = 1; 458 desc.autoload = 1;
459 fclose (fopen (fullfile (desc.dir, "packinfo", ".autoload"), "wt")); 459 fclose (fopen (fullfile (desc.dir, "packinfo", ".autoload"), "wt"));
460 endif 460 endif
461 else 461 else
462 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file")) 462 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file"))
463 desc.autoload = 1; 463 desc.autoload = 1;
464 else 464 else
465 desc.autoload = 0; 465 desc.autoload = 0;
466 endif 466 endif
467 endif 467 endif
468 descriptions{end + 1} = desc; 468 descriptions{end + 1} = desc;
469 elseif (verbose) 469 elseif (verbose)
470 warning ("directory %s is not a valid package", dirlist{k}); 470 warning ("directory %s is not a valid package", dirlist{k});
471 endif 471 endif
477 descriptions = {descriptions{:}, old_descriptions{:}}; 477 descriptions = {descriptions{:}, old_descriptions{:}};
478 478
479 dup = []; 479 dup = [];
480 for i = 1:length (descriptions) 480 for i = 1:length (descriptions)
481 if (find (dup, i)) 481 if (find (dup, i))
482 continue; 482 continue;
483 endif 483 endif
484 for j = (i+1):length (descriptions) 484 for j = (i+1):length (descriptions)
485 if (find (dup, j)) 485 if (find (dup, j))
486 continue; 486 continue;
487 endif 487 endif
488 if (strcmp (descriptions{i}.name, descriptions{j}.name)) 488 if (strcmp (descriptions{i}.name, descriptions{j}.name))
489 dup = [dup, j]; 489 dup = [dup, j];
490 endif 490 endif
491 endfor 491 endfor
492 endfor 492 endfor
493 if (! isempty (dup)) 493 if (! isempty (dup))
494 descriptions (dup) = []; 494 descriptions (dup) = [];
495 endif 495 endif
517 endif 517 endif
518 endif 518 endif
519 files(1) = []; 519 files(1) = [];
520 buildlist = fullfile (builddir, "octave_packages"); 520 buildlist = fullfile (builddir, "octave_packages");
521 install (files, handle_deps, autoload, installdir, installdir, verbose, 521 install (files, handle_deps, autoload, installdir, installdir, verbose,
522 buildlist, "", false); 522 buildlist, "", false);
523 unwind_protect 523 unwind_protect
524 repackage (builddir, buildlist); 524 repackage (builddir, buildlist);
525 unwind_protect_cleanup 525 unwind_protect_cleanup
526 unload_packages ({"all"}, handle_deps, buildlist, ""); 526 unload_packages ({"all"}, handle_deps, buildlist, "");
527 if (exist (installdir, "dir")) 527 if (exist (installdir, "dir"))
532 endif 532 endif
533 end_unwind_protect 533 end_unwind_protect
534 endfunction 534 endfunction
535 535
536 function install (files, handle_deps, autoload, prefix, archprefix, verbose, 536 function install (files, handle_deps, autoload, prefix, archprefix, verbose,
537 local_list, global_list, global_install) 537 local_list, global_list, global_install)
538 538
539 ## Check that the directory in prefix exist. If it doesn't: create it! 539 ## Check that the directory in prefix exist. If it doesn't: create it!
540 if (! exist (prefix, "dir")) 540 if (! exist (prefix, "dir"))
541 warning ("creating installation directory %s", prefix); 541 warning ("creating installation directory %s", prefix);
542 [status, msg] = mkdir (prefix); 542 [status, msg] = mkdir (prefix);
545 endif 545 endif
546 endif 546 endif
547 547
548 ## Get the list of installed packages. 548 ## Get the list of installed packages.
549 [local_packages, global_packages] = installed_packages (local_list, 549 [local_packages, global_packages] = installed_packages (local_list,
550 global_list); 550 global_list);
551 551
552 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; 552 installed_pkgs_lst = {local_packages{:}, global_packages{:}};
553 553
554 if (global_install) 554 if (global_install)
555 packages = global_packages; 555 packages = global_packages;
561 tmpdirs = packdirs = descriptions = {}; 561 tmpdirs = packdirs = descriptions = {};
562 try 562 try
563 ## Warn about non existent files. 563 ## Warn about non existent files.
564 for i = 1:length (files) 564 for i = 1:length (files)
565 if (isempty (glob(files{i}))) 565 if (isempty (glob(files{i})))
566 warning ("file %s does not exist", files{i}); 566 warning ("file %s does not exist", files{i});
567 endif 567 endif
568 endfor 568 endfor
569 569
570 ## Unpack the package files and read the DESCRIPTION files. 570 ## Unpack the package files and read the DESCRIPTION files.
571 files = glob (files); 571 files = glob (files);
572 packages_to_uninstall = []; 572 packages_to_uninstall = [];
573 for i = 1:length (files) 573 for i = 1:length (files)
574 tgz = files{i}; 574 tgz = files{i};
575 575
576 if (exist (tgz, "file")) 576 if (exist (tgz, "file"))
577 ## Create a temporary directory. 577 ## Create a temporary directory.
578 tmpdir = tmpnam (); 578 tmpdir = tmpnam ();
579 tmpdirs{end+1} = tmpdir; 579 tmpdirs{end+1} = tmpdir;
580 if (verbose) 580 if (verbose)
581 printf ("mkdir (%s)\n", tmpdir); 581 printf ("mkdir (%s)\n", tmpdir);
582 endif 582 endif
583 [status, msg] = mkdir (tmpdir); 583 [status, msg] = mkdir (tmpdir);
584 if (status != 1) 584 if (status != 1)
585 error ("couldn't create temporary directory: %s", msg); 585 error ("couldn't create temporary directory: %s", msg);
586 endif 586 endif
587 587
588 ## Uncompress the package. 588 ## Uncompress the package.
589 if (verbose) 589 if (verbose)
590 printf ("untar (%s, %s)\n", tgz, tmpdir); 590 printf ("untar (%s, %s)\n", tgz, tmpdir);
591 endif 591 endif
592 untar (tgz, tmpdir); 592 untar (tgz, tmpdir);
593 593
594 ## Get the name of the directories produced by tar. 594 ## Get the name of the directories produced by tar.
595 [dirlist, err, msg] = readdir (tmpdir); 595 [dirlist, err, msg] = readdir (tmpdir);
596 if (err) 596 if (err)
597 error ("couldn't read directory produced by tar: %s", msg); 597 error ("couldn't read directory produced by tar: %s", msg);
598 endif 598 endif
599 599
600 if (length (dirlist) > 3) 600 if (length (dirlist) > 3)
601 error ("bundles of packages are not allowed") 601 error ("bundles of packages are not allowed")
602 endif 602 endif
603 endif 603 endif
604 604
605 ## The filename pointed to an uncompressed package to begin with. 605 ## The filename pointed to an uncompressed package to begin with.
606 if (exist (tgz, "dir")) 606 if (exist (tgz, "dir"))
607 dirlist = {".", "..", tgz}; 607 dirlist = {".", "..", tgz};
608 endif 608 endif
609 609
610 if (exist (tgz, "file") || exist (tgz, "dir")) 610 if (exist (tgz, "file") || exist (tgz, "dir"))
611 ## The two first entries of dirlist are "." and "..". 611 ## The two first entries of dirlist are "." and "..".
612 if (exist (tgz, "file")) 612 if (exist (tgz, "file"))
613 packdir = fullfile (tmpdir, dirlist{3}); 613 packdir = fullfile (tmpdir, dirlist{3});
614 else 614 else
615 packdir = fullfile (pwd(), dirlist{3}); 615 packdir = fullfile (pwd(), dirlist{3});
616 endif 616 endif
617 packdirs{end+1} = packdir; 617 packdirs{end+1} = packdir;
618 618
619 ## Make sure the package contains necessary files. 619 ## Make sure the package contains necessary files.
620 verify_directory (packdir); 620 verify_directory (packdir);
621 621
622 ## Read the DESCRIPTION file. 622 ## Read the DESCRIPTION file.
623 filename = fullfile (packdir, "DESCRIPTION"); 623 filename = fullfile (packdir, "DESCRIPTION");
624 desc = get_description (filename); 624 desc = get_description (filename);
625 625
626 ## Verify that package name corresponds with filename. 626 ## Verify that package name corresponds with filename.
627 [dummy, nm] = fileparts (tgz); 627 [dummy, nm] = fileparts (tgz);
628 if ((length (nm) >= length (desc.name)) 628 if ((length (nm) >= length (desc.name))
629 && ! strcmp (desc.name, nm(1:length(desc.name)))) 629 && ! strcmp (desc.name, nm(1:length(desc.name))))
630 error ("package name '%s' doesn't correspond to its filename '%s'", 630 error ("package name '%s' doesn't correspond to its filename '%s'",
631 desc.name, nm); 631 desc.name, nm);
632 endif 632 endif
633 633
634 ## Set default installation directory. 634 ## Set default installation directory.
635 desc.dir = fullfile (prefix, cstrcat (desc.name, "-", desc.version)); 635 desc.dir = fullfile (prefix, cstrcat (desc.name, "-", desc.version));
636 636
637 ## Set default architectire dependent installation directory. 637 ## Set default architectire dependent installation directory.
638 desc.archprefix = fullfile (archprefix, cstrcat (desc.name, "-", 638 desc.archprefix = fullfile (archprefix, cstrcat (desc.name, "-",
639 desc.version)); 639 desc.version));
640 640
641 ## Save desc. 641 ## Save desc.
642 descriptions{end+1} = desc; 642 descriptions{end+1} = desc;
643 643
644 ## Are any of the new packages already installed? 644 ## Are any of the new packages already installed?
645 ## If so we'll remove the old version. 645 ## If so we'll remove the old version.
646 for j = 1:length (packages) 646 for j = 1:length (packages)
647 if (strcmp (packages{j}.name, desc.name)) 647 if (strcmp (packages{j}.name, desc.name))
648 packages_to_uninstall(end+1) = j; 648 packages_to_uninstall(end+1) = j;
649 endif 649 endif
650 endfor 650 endfor
651 endif 651 endif
652 endfor 652 endfor
653 catch 653 catch
654 ## Something went wrong, delete tmpdirs. 654 ## Something went wrong, delete tmpdirs.
655 for i = 1:length (tmpdirs) 655 for i = 1:length (tmpdirs)
664 error_text = ""; 664 error_text = "";
665 for i = 1:length (descriptions) 665 for i = 1:length (descriptions)
666 desc = descriptions{i}; 666 desc = descriptions{i};
667 idx2 = setdiff (1:length(descriptions), i); 667 idx2 = setdiff (1:length(descriptions), i);
668 if (global_install) 668 if (global_install)
669 ## Global installation is not allowed to have dependencies on locally 669 ## Global installation is not allowed to have dependencies on locally
670 ## installed packages. 670 ## installed packages.
671 idx1 = setdiff (1:length(global_packages), packages_to_uninstall); 671 idx1 = setdiff (1:length(global_packages), packages_to_uninstall);
672 pseudo_installed_packages = {global_packages{idx1}, ... 672 pseudo_installed_packages = {global_packages{idx1}, ...
673 descriptions{idx2}}; 673 descriptions{idx2}};
674 else 674 else
675 idx1 = setdiff (1:length(local_packages), packages_to_uninstall); 675 idx1 = setdiff (1:length(local_packages), packages_to_uninstall);
676 pseudo_installed_packages = {local_packages{idx1}, ... 676 pseudo_installed_packages = {local_packages{idx1}, ...
677 global_packages{:}, ... 677 global_packages{:}, ...
678 descriptions{idx2}}; 678 descriptions{idx2}};
679 endif 679 endif
680 bad_deps = get_unsatisfied_deps (desc, pseudo_installed_packages); 680 bad_deps = get_unsatisfied_deps (desc, pseudo_installed_packages);
681 ## Are there any unsatisfied dependencies? 681 ## Are there any unsatisfied dependencies?
682 if (! isempty (bad_deps)) 682 if (! isempty (bad_deps))
683 ok = false; 683 ok = false;
684 for i = 1:length (bad_deps) 684 for i = 1:length (bad_deps)
685 dep = bad_deps{i}; 685 dep = bad_deps{i};
686 error_text = cstrcat (error_text, " ", desc.name, " needs ", 686 error_text = cstrcat (error_text, " ", desc.name, " needs ",
687 dep.package, " ", dep.operator, " ", 687 dep.package, " ", dep.operator, " ",
688 dep.version, "\n"); 688 dep.version, "\n");
689 endfor 689 endfor
690 endif 690 endif
691 endfor 691 endfor
692 692
693 ## Did we find any unsatisfied dependencies? 693 ## Did we find any unsatisfied dependencies?
694 if (! ok) 694 if (! ok)
714 714
715 ## Uninstall the packages that will be replaced. 715 ## Uninstall the packages that will be replaced.
716 try 716 try
717 for i = packages_to_uninstall 717 for i = packages_to_uninstall
718 if (global_install) 718 if (global_install)
719 uninstall ({global_packages{i}.name}, false, verbose, local_list, 719 uninstall ({global_packages{i}.name}, false, verbose, local_list,
720 global_list, global_install); 720 global_list, global_install);
721 else 721 else
722 uninstall ({local_packages{i}.name}, false, verbose, local_list, 722 uninstall ({local_packages{i}.name}, false, verbose, local_list,
723 global_list, global_install); 723 global_list, global_install);
724 endif 724 endif
725 endfor 725 endfor
726 catch 726 catch
727 ## Something went wrong, delete tmpdirs. 727 ## Something went wrong, delete tmpdirs.
728 for i = 1:length (tmpdirs) 728 for i = 1:length (tmpdirs)
756 756
757 ## Check if the installed directory is empty. If it is remove it 757 ## Check if the installed directory is empty. If it is remove it
758 ## from the list. 758 ## from the list.
759 for i = length (descriptions):-1:1 759 for i = length (descriptions):-1:1
760 if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) && 760 if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) &&
761 dirempty (getarchdir (descriptions{i}))) 761 dirempty (getarchdir (descriptions{i})))
762 warning ("package %s is empty\n", descriptions{i}.name); 762 warning ("package %s is empty\n", descriptions{i}.name);
763 rm_rf (descriptions{i}.dir); 763 rm_rf (descriptions{i}.dir);
764 rm_rf (getarchdir (descriptions{i})); 764 rm_rf (getarchdir (descriptions{i}));
765 descriptions(i) = []; 765 descriptions(i) = [];
766 endif 766 endif
769 ## If the package requested that it is autoloaded, or the installer 769 ## If the package requested that it is autoloaded, or the installer
770 ## requested that it is, then mark the package as autoloaded. 770 ## requested that it is, then mark the package as autoloaded.
771 for i = length (descriptions):-1:1 771 for i = length (descriptions):-1:1
772 if (autoload > 0 || (autoload == 0 && isautoload (descriptions(i)))) 772 if (autoload > 0 || (autoload == 0 && isautoload (descriptions(i))))
773 fclose (fopen (fullfile (descriptions{i}.dir, "packinfo", 773 fclose (fopen (fullfile (descriptions{i}.dir, "packinfo",
774 ".autoload"), "wt")); 774 ".autoload"), "wt"));
775 descriptions{i}.autoload = 1; 775 descriptions{i}.autoload = 1;
776 endif 776 endif
777 endfor 777 endfor
778 778
779 ## Add the packages to the package list. 779 ## Add the packages to the package list.
817 ## can begin using them. Only load them if they are marked autoload. 817 ## can begin using them. Only load them if they are marked autoload.
818 if (length (descriptions) > 0) 818 if (length (descriptions) > 0)
819 idx = []; 819 idx = [];
820 for i = 1:length (descriptions) 820 for i = 1:length (descriptions)
821 if (isautoload (descriptions(i))) 821 if (isautoload (descriptions(i)))
822 nm = descriptions{i}.name; 822 nm = descriptions{i}.name;
823 for j = 1:length (installed_pkgs_lst) 823 for j = 1:length (installed_pkgs_lst)
824 if (strcmp (nm, installed_pkgs_lst{j}.name)) 824 if (strcmp (nm, installed_pkgs_lst{j}.name))
825 idx (end + 1) = j; 825 idx (end + 1) = j;
826 break; 826 break;
827 endif 827 endif
828 endfor 828 endfor
829 endif 829 endif
830 endfor 830 endfor
831 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, 831 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst,
832 global_install); 832 global_install);
833 endif 833 endif
834 endfunction 834 endfunction
835 835
836 function uninstall (pkgnames, handle_deps, verbose, local_list, 836 function uninstall (pkgnames, handle_deps, verbose, local_list,
837 global_list, global_install) 837 global_list, global_install)
838 ## Get the list of installed packages. 838 ## Get the list of installed packages.
839 [local_packages, global_packages] = installed_packages(local_list, 839 [local_packages, global_packages] = installed_packages(local_list,
840 global_list); 840 global_list);
841 if (global_install) 841 if (global_install)
842 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; 842 installed_pkgs_lst = {local_packages{:}, global_packages{:}};
843 else 843 else
844 installed_pkgs_lst = local_packages; 844 installed_pkgs_lst = local_packages;
845 endif 845 endif
860 installed_pkgs_lst = local_packages; 860 installed_pkgs_lst = local_packages;
861 861
862 num_packages = length (installed_pkgs_lst); 862 num_packages = length (installed_pkgs_lst);
863 delete_idx = []; 863 delete_idx = [];
864 for i = 1:num_packages 864 for i = 1:num_packages
865 cur_name = installed_pkgs_lst{i}.name; 865 cur_name = installed_pkgs_lst{i}.name;
866 if (any (strcmp (cur_name, pkgnames))) 866 if (any (strcmp (cur_name, pkgnames)))
867 delete_idx(end+1) = i; 867 delete_idx(end+1) = i;
868 endif 868 endif
869 endfor 869 endfor
870 if (length (delete_idx) != length (pkgnames)) 870 if (length (delete_idx) != length (pkgnames))
871 ## FIXME: We should have a better error message. 871 ## FIXME: We should have a better error message.
872 warning ("some of the packages you want to uninstall are not installed"); 872 warning ("some of the packages you want to uninstall are not installed");
873 endif 873 endif
874 else 874 else
875 ## FIXME: We should have a better error message. 875 ## FIXME: We should have a better error message.
876 warning ("some of the packages you want to uninstall are not installed"); 876 warning ("some of the packages you want to uninstall are not installed");
877 endif 877 endif
888 desc = remaining_packages{i}; 888 desc = remaining_packages{i};
889 bad_deps = get_unsatisfied_deps (desc, remaining_packages); 889 bad_deps = get_unsatisfied_deps (desc, remaining_packages);
890 890
891 ## Will the uninstallation break any dependencies? 891 ## Will the uninstallation break any dependencies?
892 if (! isempty (bad_deps)) 892 if (! isempty (bad_deps))
893 for i = 1:length (bad_deps) 893 for i = 1:length (bad_deps)
894 dep = bad_deps{i}; 894 dep = bad_deps{i};
895 error_text = cstrcat (error_text, " ", desc.name, " needs ", 895 error_text = cstrcat (error_text, " ", desc.name, " needs ",
896 dep.package, " ", dep.operator, " ", 896 dep.package, " ", dep.operator, " ",
897 dep.version, "\n"); 897 dep.version, "\n");
898 endfor 898 endfor
899 endif 899 endif
900 endfor 900 endfor
901 901
902 if (! isempty (error_text)) 902 if (! isempty (error_text))
903 error ("the following dependencies where unsatisfied:\n %s", error_text); 903 error ("the following dependencies where unsatisfied:\n %s", error_text);
916 endif 916 endif
917 ## Do the actual deletion. 917 ## Do the actual deletion.
918 if (desc.loaded) 918 if (desc.loaded)
919 rmpath (desc.dir); 919 rmpath (desc.dir);
920 if (exist (getarchdir (desc))) 920 if (exist (getarchdir (desc)))
921 rmpath (getarchdir (desc)); 921 rmpath (getarchdir (desc));
922 endif 922 endif
923 endif 923 endif
924 if (exist (desc.dir, "dir")) 924 if (exist (desc.dir, "dir"))
925 [status, msg] = rm_rf (desc.dir); 925 [status, msg] = rm_rf (desc.dir);
926 if (status != 1) 926 if (status != 1)
927 error ("couldn't delete directory %s: %s", desc.dir, msg); 927 error ("couldn't delete directory %s: %s", desc.dir, msg);
928 endif 928 endif
929 [status, msg] = rm_rf (getarchdir (desc)); 929 [status, msg] = rm_rf (getarchdir (desc));
930 if (status != 1) 930 if (status != 1)
931 error ("couldn't delete directory %s: %s", getarchdir (desc), msg); 931 error ("couldn't delete directory %s: %s", getarchdir (desc), msg);
932 endif 932 endif
933 if (dirempty (desc.archprefix)) 933 if (dirempty (desc.archprefix))
934 rm_rf (desc.archprefix); 934 rm_rf (desc.archprefix);
935 endif 935 endif
936 else 936 else
937 warning ("directory %s previously lost", desc.dir); 937 warning ("directory %s previously lost", desc.dir);
938 endif 938 endif
939 endfor 939 endfor
956 endif 956 endif
957 957
958 endfunction 958 endfunction
959 959
960 function [pkg_desc_list, flag] = describe (pkgnames, verbose, 960 function [pkg_desc_list, flag] = describe (pkgnames, verbose,
961 local_list, global_list) 961 local_list, global_list)
962 962
963 ## Get the list of installed packages. 963 ## Get the list of installed packages.
964 installed_pkgs_lst = installed_packages(local_list, global_list); 964 installed_pkgs_lst = installed_packages(local_list, global_list);
965 num_packages = length (installed_pkgs_lst); 965 num_packages = length (installed_pkgs_lst);
966 966
983 name_pos = find(strcmp (curr_name, pkgnames)); 983 name_pos = find(strcmp (curr_name, pkgnames));
984 endif 984 endif
985 985
986 if (! isempty (name_pos)) 986 if (! isempty (name_pos))
987 if (installed_pkgs_lst{i}.loaded) 987 if (installed_pkgs_lst{i}.loaded)
988 flag{name_pos} = "Loaded"; 988 flag{name_pos} = "Loaded";
989 else 989 else
990 flag{name_pos} = "Not loaded"; 990 flag{name_pos} = "Not loaded";
991 endif 991 endif
992 992
993 pkg_desc_list{name_pos}.name = installed_pkgs_lst{i}.name; 993 pkg_desc_list{name_pos}.name = installed_pkgs_lst{i}.name;
994 pkg_desc_list{name_pos}.version = installed_pkgs_lst{i}.version; 994 pkg_desc_list{name_pos}.version = installed_pkgs_lst{i}.version;
995 pkg_desc_list{name_pos}.description = installed_pkgs_lst{i}.description; 995 pkg_desc_list{name_pos}.description = installed_pkgs_lst{i}.description;
1003 if (nargout < 2) 1003 if (nargout < 2)
1004 non_inst_str = sprintf (" %s ", pkgnames{non_inst}); 1004 non_inst_str = sprintf (" %s ", pkgnames{non_inst});
1005 error ("some packages are not installed: %s", non_inst_str); 1005 error ("some packages are not installed: %s", non_inst_str);
1006 else 1006 else
1007 pkg_desc_list{non_inst} = struct ("name", {}, "description", 1007 pkg_desc_list{non_inst} = struct ("name", {}, "description",
1008 {}, "provides", {}); 1008 {}, "provides", {});
1009 endif 1009 endif
1010 endif 1010 endif
1011 1011
1012 if (nargout == 0) 1012 if (nargout == 0)
1013 for i = 1:num_pkgnames 1013 for i = 1:num_pkgnames
1014 print_package_description (pkg_desc_list{i}.name, 1014 print_package_description (pkg_desc_list{i}.name,
1015 pkg_desc_list{i}.version, 1015 pkg_desc_list{i}.version,
1016 pkg_desc_list{i}.provides, 1016 pkg_desc_list{i}.provides,
1017 pkg_desc_list{i}.description, 1017 pkg_desc_list{i}.description,
1018 flag{i}, verbose); 1018 flag{i}, verbose);
1019 endfor 1019 endfor
1020 endif 1020 endif
1021 1021
1022 endfunction 1022 endfunction
1023 1023
1034 1034
1035 1035
1036 [fid, msg] = fopen (index_file, "r"); 1036 [fid, msg] = fopen (index_file, "r");
1037 if (fid == -1) 1037 if (fid == -1)
1038 error ("the INDEX file %s could not be read: %s", 1038 error ("the INDEX file %s could not be read: %s",
1039 index_file, msg); 1039 index_file, msg);
1040 endif 1040 endif
1041 1041
1042 cat_num = 1; 1042 cat_num = 1;
1043 pkg_idx_struct{1}.category = "Uncategorized"; 1043 pkg_idx_struct{1}.category = "Uncategorized";
1044 pkg_idx_struct{1}.functions = {}; 1044 pkg_idx_struct{1}.functions = {};
1058 ## Skip package name and description as they are in DESCRIPTION 1058 ## Skip package name and description as they are in DESCRIPTION
1059 ## already. 1059 ## already.
1060 elseif (! isspace (line(1))) 1060 elseif (! isspace (line(1)))
1061 ## Category. 1061 ## Category.
1062 if (! isempty (pkg_idx_struct{cat_num}.functions)) 1062 if (! isempty (pkg_idx_struct{cat_num}.functions))
1063 pkg_idx_struct{++cat_num}.functions = {}; 1063 pkg_idx_struct{++cat_num}.functions = {};
1064 endif 1064 endif
1065 pkg_idx_struct{cat_num}.category = deblank (line); 1065 pkg_idx_struct{cat_num}.category = deblank (line);
1066 else 1066 else
1067 ## Function names. 1067 ## Function names.
1068 while (any (! isspace (line))) 1068 while (any (! isspace (line)))
1069 [fun_name, line] = strtok (line); 1069 [fun_name, line] = strtok (line);
1070 pkg_idx_struct{cat_num}.functions{end+1} = deblank (fun_name); 1070 pkg_idx_struct{cat_num}.functions{end+1} = deblank (fun_name);
1071 endwhile 1071 endwhile
1072 endif 1072 endif
1073 line = fgetl (fid); 1073 line = fgetl (fid);
1074 endwhile 1074 endwhile
1075 fclose (fid); 1075 fclose (fid);
1076 endfunction 1076 endfunction
1077 1077
1078 function print_package_description (pkg_name, pkg_ver, pkg_idx_struct, 1078 function print_package_description (pkg_name, pkg_ver, pkg_idx_struct,
1079 pkg_desc, status, verbose) 1079 pkg_desc, status, verbose)
1080 1080
1081 printf ("---\nPackage name:\n\t%s\n", pkg_name); 1081 printf ("---\nPackage name:\n\t%s\n", pkg_name);
1082 printf ("Version:\n\t%s\n", pkg_ver); 1082 printf ("Version:\n\t%s\n", pkg_ver);
1083 printf ("Short description:\n\t%s\n", pkg_desc); 1083 printf ("Short description:\n\t%s\n", pkg_desc);
1084 printf ("Status:\n\t%s\n", status); 1084 printf ("Status:\n\t%s\n", status);
1085 if (verbose) 1085 if (verbose)
1086 printf ("---\nProvides:\n"); 1086 printf ("---\nProvides:\n");
1087 for i = 1:length(pkg_idx_struct) 1087 for i = 1:length(pkg_idx_struct)
1088 if (! isempty (pkg_idx_struct{i}.functions)) 1088 if (! isempty (pkg_idx_struct{i}.functions))
1089 printf ("%s\n", pkg_idx_struct{i}.category); 1089 printf ("%s\n", pkg_idx_struct{i}.category);
1090 for j = 1:length(pkg_idx_struct{i}.functions) 1090 for j = 1:length(pkg_idx_struct{i}.functions)
1091 printf ("\t%s\n", pkg_idx_struct{i}.functions{j}); 1091 printf ("\t%s\n", pkg_idx_struct{i}.functions{j});
1092 endfor 1092 endfor
1093 endif 1093 endif
1094 endfor 1094 endfor
1095 endif 1095 endif
1096 1096
1097 endfunction 1097 endfunction
1117 mkdir (pack.name); 1117 mkdir (pack.name);
1118 mkdir (fullfile (pack.name, "inst")); 1118 mkdir (fullfile (pack.name, "inst"));
1119 copyfile (fullfile (pack.dir, "*"), fullfile (pack.name, "inst")); 1119 copyfile (fullfile (pack.dir, "*"), fullfile (pack.name, "inst"));
1120 movefile (fullfile (pack.name, "inst","packinfo", "*"), pack.name); 1120 movefile (fullfile (pack.name, "inst","packinfo", "*"), pack.name);
1121 if (exist (fullfile (pack.name, "inst","packinfo", ".autoload"), "file")) 1121 if (exist (fullfile (pack.name, "inst","packinfo", ".autoload"), "file"))
1122 unlink (fullfile (pack.name, "inst","packinfo", ".autoload")); 1122 unlink (fullfile (pack.name, "inst","packinfo", ".autoload"));
1123 endif 1123 endif
1124 rmdir (fullfile (pack.name, "inst", "packinfo")); 1124 rmdir (fullfile (pack.name, "inst", "packinfo"));
1125 if (exist (fullfile (pack.name, "inst", "doc"), "dir")) 1125 if (exist (fullfile (pack.name, "inst", "doc"), "dir"))
1126 movefile (fullfile (pack.name, "inst", "doc"), pack.name); 1126 movefile (fullfile (pack.name, "inst", "doc"), pack.name);
1127 endif 1127 endif
1128 if (exist (fullfile (pack.name, "inst", "bin"), "dir")) 1128 if (exist (fullfile (pack.name, "inst", "bin"), "dir"))
1129 movefile (fullfile (pack.name, "inst", "bin"), pack.name); 1129 movefile (fullfile (pack.name, "inst", "bin"), pack.name);
1130 endif 1130 endif
1131 archdir = fullfile (pack.archprefix, cstrcat (pack.name, "-", 1131 archdir = fullfile (pack.archprefix, cstrcat (pack.name, "-",
1132 pack.version), getarch ()); 1132 pack.version), getarch ());
1133 if (exist (archdir, "dir")) 1133 if (exist (archdir, "dir"))
1134 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file")) 1134 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file"))
1135 unlink (fullfile (pack.name, "inst", "PKG_ADD")); 1135 unlink (fullfile (pack.name, "inst", "PKG_ADD"));
1136 endif 1136 endif
1137 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file")) 1137 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file"))
1138 unlink (fullfile (pack.name, "inst", "PKG_DEL")); 1138 unlink (fullfile (pack.name, "inst", "PKG_DEL"));
1139 endif 1139 endif
1140 if (exist (fullfile (archdir, "PKG_ADD"), "file")) 1140 if (exist (fullfile (archdir, "PKG_ADD"), "file"))
1141 movefile (fullfile (archdir, "PKG_ADD"), 1141 movefile (fullfile (archdir, "PKG_ADD"),
1142 fullfile (pack.name, "PKG_ADD")); 1142 fullfile (pack.name, "PKG_ADD"));
1143 endif 1143 endif
1144 if (exist (fullfile (archdir, "PKG_DEL"), "file")) 1144 if (exist (fullfile (archdir, "PKG_DEL"), "file"))
1145 movefile (fullfile (archdir, "PKG_DEL"), 1145 movefile (fullfile (archdir, "PKG_DEL"),
1146 fullfile (pack.name, "PKG_DEL")); 1146 fullfile (pack.name, "PKG_DEL"));
1147 endif 1147 endif
1148 else 1148 else
1149 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file")) 1149 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file"))
1150 movefile (fullfile (pack.name, "inst", "PKG_ADD"), 1150 movefile (fullfile (pack.name, "inst", "PKG_ADD"),
1151 fullfile (pack.name, "PKG_ADD")); 1151 fullfile (pack.name, "PKG_ADD"));
1152 endif 1152 endif
1153 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file")) 1153 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file"))
1154 movefile (fullfile (pack.name, "inst", "PKG_DEL"), 1154 movefile (fullfile (pack.name, "inst", "PKG_DEL"),
1155 fullfile (pack.name, "PKG_DEL")); 1155 fullfile (pack.name, "PKG_DEL"));
1156 endif 1156 endif
1157 endif 1157 endif
1158 tfile = cstrcat (pack.name, "-", pack.version, ".tar"); 1158 tfile = cstrcat (pack.name, "-", pack.version, ".tar");
1159 tar (tfile, pack.name); 1159 tar (tfile, pack.name);
1160 try 1160 try
1161 gzip (tfile); 1161 gzip (tfile);
1162 unlink (tfile); 1162 unlink (tfile);
1163 catch 1163 catch
1164 warning ("failed to compress %s", tfile); 1164 warning ("failed to compress %s", tfile);
1165 end_try_catch 1165 end_try_catch
1166 unwind_protect_cleanup 1166 unwind_protect_cleanup
1167 if (exist (pack.name, "dir")) 1167 if (exist (pack.name, "dir"))
1168 rm_rf (pack.name); 1168 rm_rf (pack.name);
1169 endif 1169 endif
1170 cd (wd); 1170 cd (wd);
1171 end_unwind_protect 1171 end_unwind_protect
1172 endfor 1172 endfor
1173 endfunction 1173 endfunction
1176 auto = false; 1176 auto = false;
1177 if (isfield (desc{1}, "autoload")) 1177 if (isfield (desc{1}, "autoload"))
1178 a = desc{1}.autoload; 1178 a = desc{1}.autoload;
1179 if ((isnumeric (a) && a > 0) 1179 if ((isnumeric (a) && a > 0)
1180 || (ischar (a) && (strcmpi (a, "true") 1180 || (ischar (a) && (strcmpi (a, "true")
1181 || strcmpi (a, "on") 1181 || strcmpi (a, "on")
1182 || strcmpi (a, "yes") 1182 || strcmpi (a, "yes")
1183 || strcmpi (a, "1")))) 1183 || strcmpi (a, "1"))))
1184 auto = true; 1184 auto = true;
1185 endif 1185 endif
1186 endif 1186 endif
1187 endfunction 1187 endfunction
1188 1188
1205 if (! exist (inst_dir, "dir")) 1205 if (! exist (inst_dir, "dir"))
1206 [status, msg] = mkdir (inst_dir); 1206 [status, msg] = mkdir (inst_dir);
1207 if (status != 1) 1207 if (status != 1)
1208 rm_rf (desc.dir); 1208 rm_rf (desc.dir);
1209 error ("the 'inst' directory did not exist and could not be created: %s", 1209 error ("the 'inst' directory did not exist and could not be created: %s",
1210 msg); 1210 msg);
1211 endif 1211 endif
1212 endif 1212 endif
1213 endfunction 1213 endfunction
1214 1214
1215 function configure_make (desc, packdir, verbose) 1215 function configure_make (desc, packdir, verbose)
1232 flags = cstrcat (flags, " RANLIB=\"", octave_config_info ("RANLIB"), "\""); 1232 flags = cstrcat (flags, " RANLIB=\"", octave_config_info ("RANLIB"), "\"");
1233 endif 1233 endif
1234 [status, output] = shell (strcat ("cd '", src, "'; ./configure --prefix=\"", 1234 [status, output] = shell (strcat ("cd '", src, "'; ./configure --prefix=\"",
1235 desc.dir, "\"", flags)); 1235 desc.dir, "\"", flags));
1236 if (status != 0) 1236 if (status != 0)
1237 rm_rf (desc.dir); 1237 rm_rf (desc.dir);
1238 error ("the configure script returned the following error: %s", output); 1238 error ("the configure script returned the following error: %s", output);
1239 elseif (verbose) 1239 elseif (verbose)
1240 printf("%s", output); 1240 printf("%s", output);
1241 endif 1241 endif
1242 1242
1243 endif 1243 endif
1244 1244
1245 ## Make. 1245 ## Make.
1246 if (exist (fullfile (src, "Makefile"), "file")) 1246 if (exist (fullfile (src, "Makefile"), "file"))
1247 [status, output] = shell (cstrcat ("export INSTALLDIR=\"", desc.dir, 1247 [status, output] = shell (cstrcat ("export INSTALLDIR=\"", desc.dir,
1248 "\"; make -C '", src, "'")); 1248 "\"; make -C '", src, "'"));
1249 if (status != 0) 1249 if (status != 0)
1250 rm_rf (desc.dir); 1250 rm_rf (desc.dir);
1251 error ("'make' returned the following error: %s", output); 1251 error ("'make' returned the following error: %s", output);
1252 elseif (verbose) 1252 elseif (verbose)
1253 printf("%s", output); 1253 printf("%s", output);
1254 endif 1254 endif
1255 endif 1255 endif
1256 1256
1257 ## Copy files to "inst" and "inst/arch" (this is instead of 'make 1257 ## Copy files to "inst" and "inst/arch" (this is instead of 'make
1258 ## install'). 1258 ## install').
1262 1262
1263 ## Get file names. 1263 ## Get file names.
1264 if (exist (files, "file")) 1264 if (exist (files, "file"))
1265 [fid, msg] = fopen (files, "r"); 1265 [fid, msg] = fopen (files, "r");
1266 if (fid < 0) 1266 if (fid < 0)
1267 error ("couldn't open %s: %s", files, msg); 1267 error ("couldn't open %s: %s", files, msg);
1268 endif 1268 endif
1269 filenames = char (fread (fid))'; 1269 filenames = char (fread (fid))';
1270 fclose (fid); 1270 fclose (fid);
1271 if (filenames(end) == "\n") 1271 if (filenames(end) == "\n")
1272 filenames(end) = []; 1272 filenames(end) = [];
1273 endif 1273 endif
1274 filenames = split_by (filenames, "\n"); 1274 filenames = split_by (filenames, "\n");
1275 delete_idx = []; 1275 delete_idx = [];
1276 for i = 1:length (filenames) 1276 for i = 1:length (filenames)
1277 if (! all (isspace (filenames{i}))) 1277 if (! all (isspace (filenames{i})))
1278 filenames{i} = fullfile (src, filenames{i}); 1278 filenames{i} = fullfile (src, filenames{i});
1279 else 1279 else
1280 delete_idx(end+1) = i; 1280 delete_idx(end+1) = i;
1281 endif 1281 endif
1282 endfor 1282 endfor
1283 filenames(delete_idx) = []; 1283 filenames(delete_idx) = [];
1284 else 1284 else
1285 m = dir (fullfile (src, "*.m")); 1285 m = dir (fullfile (src, "*.m"));
1286 oct = dir (fullfile (src, "*.oct")); 1286 oct = dir (fullfile (src, "*.oct"));
1287 mex = dir (fullfile (src, "*.mex")); 1287 mex = dir (fullfile (src, "*.mex"));
1288 1288
1289 filenames = cellfun (@(x) fullfile (src, x), 1289 filenames = cellfun (@(x) fullfile (src, x),
1290 {m.name, oct.name, mex.name}, 1290 {m.name, oct.name, mex.name},
1291 "UniformOutput", false); 1291 "UniformOutput", false);
1292 endif 1292 endif
1293 1293
1294 ## Split into architecture dependent and independent files. 1294 ## Split into architecture dependent and independent files.
1295 if (isempty (filenames)) 1295 if (isempty (filenames))
1296 idx = []; 1296 idx = [];
1300 archdependent = filenames (idx); 1300 archdependent = filenames (idx);
1301 archindependent = filenames (!idx); 1301 archindependent = filenames (!idx);
1302 1302
1303 ## Copy the files. 1303 ## Copy the files.
1304 if (! all (isspace ([filenames{:}]))) 1304 if (! all (isspace ([filenames{:}])))
1305 if (! exist (instdir, "dir")) 1305 if (! exist (instdir, "dir"))
1306 mkdir (instdir); 1306 mkdir (instdir);
1307 endif 1307 endif
1308 if (! all (isspace ([archindependent{:}]))) 1308 if (! all (isspace ([archindependent{:}])))
1309 if (verbose) 1309 if (verbose)
1310 printf ("copyfile"); 1310 printf ("copyfile");
1311 printf (" %s", archindependent{:}); 1311 printf (" %s", archindependent{:});
1312 printf ("%s\n", instdir); 1312 printf ("%s\n", instdir);
1313 endif 1313 endif
1314 [status, output] = copyfile (archindependent, instdir); 1314 [status, output] = copyfile (archindependent, instdir);
1315 if (status != 1) 1315 if (status != 1)
1316 rm_rf (desc.dir); 1316 rm_rf (desc.dir);
1317 error ("Couldn't copy files from 'src' to 'inst': %s", output); 1317 error ("Couldn't copy files from 'src' to 'inst': %s", output);
1318 endif 1318 endif
1319 endif 1319 endif
1320 if (! all (isspace ([archdependent{:}]))) 1320 if (! all (isspace ([archdependent{:}])))
1321 if (verbose) 1321 if (verbose)
1322 printf ("copyfile"); 1322 printf ("copyfile");
1323 printf (" %s", archdependent{:}); 1323 printf (" %s", archdependent{:});
1324 printf (" %s\n", archdir); 1324 printf (" %s\n", archdir);
1325 endif 1325 endif
1326 if (! exist (archdir, "dir")) 1326 if (! exist (archdir, "dir"))
1327 mkdir (archdir); 1327 mkdir (archdir);
1328 endif 1328 endif
1329 [status, output] = copyfile (archdependent, archdir); 1329 [status, output] = copyfile (archdependent, archdir);
1330 if (status != 1) 1330 if (status != 1)
1331 rm_rf (desc.dir); 1331 rm_rf (desc.dir);
1332 error ("Couldn't copy files from 'src' to 'inst': %s", output); 1332 error ("Couldn't copy files from 'src' to 'inst': %s", output);
1333 endif 1333 endif
1334 endif 1334 endif
1335 endif 1335 endif
1336 endif 1336 endif
1337 endfunction 1337 endfunction
1338 1338
1341 pkg = ""; 1341 pkg = "";
1342 if (fid >= 0) 1342 if (fid >= 0)
1343 while (! feof (fid)) 1343 while (! feof (fid))
1344 ln = fgetl (fid); 1344 ln = fgetl (fid);
1345 if (ln > 0) 1345 if (ln > 0)
1346 t = regexp (ln, pat, "tokens"); 1346 t = regexp (ln, pat, "tokens");
1347 if (! isempty (t)) 1347 if (! isempty (t))
1348 pkg = cstrcat (pkg, "\n", t{1}{1}); 1348 pkg = cstrcat (pkg, "\n", t{1}{1});
1349 endif 1349 endif
1350 endif 1350 endif
1351 endwhile 1351 endwhile
1352 if (! isempty (pkg)) 1352 if (! isempty (pkg))
1353 pkg = cstrcat (pkg, "\n"); 1353 pkg = cstrcat (pkg, "\n");
1354 endif 1354 endif
1362 ## If it is exists, most of the PKG_* file should go into the 1362 ## If it is exists, most of the PKG_* file should go into the
1363 ## architecture dependent directory so that the autoload/mfilename 1363 ## architecture dependent directory so that the autoload/mfilename
1364 ## commands work as expected. The only part that doesn't is the 1364 ## commands work as expected. The only part that doesn't is the
1365 ## part in the main directory. 1365 ## part in the main directory.
1366 archdir = fullfile (getarchprefix (desc), cstrcat (desc.name, "-", 1366 archdir = fullfile (getarchprefix (desc), cstrcat (desc.name, "-",
1367 desc.version), getarch ()); 1367 desc.version), getarch ());
1368 if (exist (getarchdir (desc, global_install), "dir")) 1368 if (exist (getarchdir (desc, global_install), "dir"))
1369 archpkg = fullfile (getarchdir (desc, global_install), nm); 1369 archpkg = fullfile (getarchdir (desc, global_install), nm);
1370 archfid = fopen (archpkg, "at"); 1370 archfid = fopen (archpkg, "at");
1371 else 1371 else
1372 archpkg = instpkg; 1372 archpkg = instpkg;
1440 if (status != 1) 1440 if (status != 1)
1441 rm_rf (desc.dir); 1441 rm_rf (desc.dir);
1442 error ("couldn't copy files to the installation directory"); 1442 error ("couldn't copy files to the installation directory");
1443 endif 1443 endif
1444 if (exist (fullfile (desc.dir, getarch ()), "dir") && 1444 if (exist (fullfile (desc.dir, getarch ()), "dir") &&
1445 ! strcmp (fullfile (desc.dir, getarch ()), octfiledir)) 1445 ! strcmp (fullfile (desc.dir, getarch ()), octfiledir))
1446 if (! exist (octfiledir, "dir")) 1446 if (! exist (octfiledir, "dir"))
1447 ## Can be required to create upto three levels of dirs. 1447 ## Can be required to create upto three levels of dirs.
1448 octm1 = fileparts (octfiledir); 1448 octm1 = fileparts (octfiledir);
1449 if (! exist (octm1, "dir")) 1449 if (! exist (octm1, "dir"))
1450 octm2 = fileparts (octm1); 1450 octm2 = fileparts (octm1);
1478 error ("couldn't create installation directory %s : %s", 1478 error ("couldn't create installation directory %s : %s",
1479 octfiledir, output); 1479 octfiledir, output);
1480 endif 1480 endif
1481 endif 1481 endif
1482 [status, output] = movefile (fullfile (desc.dir, getarch (), "*"), 1482 [status, output] = movefile (fullfile (desc.dir, getarch (), "*"),
1483 octfiledir); 1483 octfiledir);
1484 rm_rf (fullfile (desc.dir, getarch ())); 1484 rm_rf (fullfile (desc.dir, getarch ()));
1485 1485
1486 if (status != 1) 1486 if (status != 1)
1487 rm_rf (desc.dir); 1487 rm_rf (desc.dir);
1488 rm_rf (octfiledir); 1488 rm_rf (octfiledir);
1538 error ("couldn't copy INDEX file: %s", output); 1538 error ("couldn't copy INDEX file: %s", output);
1539 endif 1539 endif
1540 else 1540 else
1541 try 1541 try
1542 write_index (desc, fullfile (packdir, "inst"), 1542 write_index (desc, fullfile (packdir, "inst"),
1543 fullfile (packinfo, "INDEX"), global_install); 1543 fullfile (packinfo, "INDEX"), global_install);
1544 catch 1544 catch
1545 rm_rf (desc.dir); 1545 rm_rf (desc.dir);
1546 rm_rf (octfiledir); 1546 rm_rf (octfiledir);
1547 rethrow (lasterror ()); 1547 rethrow (lasterror ());
1548 end_try_catch 1548 end_try_catch
1621 if (line(1) == "#") 1621 if (line(1) == "#")
1622 ## Comments, do nothing. 1622 ## Comments, do nothing.
1623 elseif (isspace(line(1))) 1623 elseif (isspace(line(1)))
1624 ## Continuation lines 1624 ## Continuation lines
1625 if (exist ("keyword", "var") && isfield (desc, keyword)) 1625 if (exist ("keyword", "var") && isfield (desc, keyword))
1626 desc.(keyword) = cstrcat (desc.(keyword), " ", rstrip(line)); 1626 desc.(keyword) = cstrcat (desc.(keyword), " ", rstrip(line));
1627 endif 1627 endif
1628 else 1628 else
1629 ## Keyword/value pair 1629 ## Keyword/value pair
1630 colon = find (line == ":"); 1630 colon = find (line == ":");
1631 if (length (colon) == 0) 1631 if (length (colon) == 0)
1632 disp ("skipping line"); 1632 disp ("skipping line");
1633 else 1633 else
1634 colon = colon(1); 1634 colon = colon(1);
1635 keyword = tolower (strip (line(1:colon-1))); 1635 keyword = tolower (strip (line(1:colon-1)));
1636 value = strip (line (colon+1:end)); 1636 value = strip (line (colon+1:end));
1637 if (length (value) == 0) 1637 if (length (value) == 0)
1638 fclose (fid); 1638 fclose (fid);
1639 error ("the keyword %s has an empty value", desc.keywords{end}); 1639 error ("the keyword %s has an empty value", desc.keywords{end});
1640 endif 1640 endif
1641 desc.(keyword) = value; 1641 desc.(keyword) = value;
1642 endif 1642 endif
1643 endif 1643 endif
1644 line = fgetl (fid); 1644 line = fgetl (fid);
1645 endwhile 1645 endwhile
1646 fclose (fid); 1646 fclose (fid);
1647 1647
1648 ## Make sure all is okay. 1648 ## Make sure all is okay.
1649 needed_fields = {"name", "version", "date", "title", ... 1649 needed_fields = {"name", "version", "date", "title", ...
1650 "author", "maintainer", "description"}; 1650 "author", "maintainer", "description"};
1651 for f = needed_fields 1651 for f = needed_fields
1652 if (! isfield (desc, f{1})) 1652 if (! isfield (desc, f{1}))
1653 error ("description is missing needed field %s", f{1}); 1653 error ("description is missing needed field %s", f{1});
1654 endif 1654 endif
1655 endfor 1655 endfor
1702 if (length (lpar) == 1 && length (rpar) == 1) 1702 if (length (lpar) == 1 && length (rpar) == 1)
1703 package = tolower (strip (dep(1:lpar-1))); 1703 package = tolower (strip (dep(1:lpar-1)));
1704 sub = dep(lpar(1)+1:rpar(1)-1); 1704 sub = dep(lpar(1)+1:rpar(1)-1);
1705 parts = strsplit (sub, " ", true); 1705 parts = strsplit (sub, " ", true);
1706 if (length (parts) != 2) 1706 if (length (parts) != 2)
1707 error ("incorrect syntax for dependency `%s' in the DESCRIPTION file\n", 1707 error ("incorrect syntax for dependency `%s' in the DESCRIPTION file\n",
1708 dep); 1708 dep);
1709 endif 1709 endif
1710 operator = parts{1}; 1710 operator = parts{1};
1711 if (! any (strcmp (operator, {">", ">=", "<=", "<", "=="}))) 1711 if (! any (strcmp (operator, {">", ">=", "<=", "<", "=="})))
1712 error ("unsupported operator: %s", operator); 1712 error ("unsupported operator: %s", operator);
1713 endif 1713 endif
1714 version = fix_version (parts{2}); 1714 version = fix_version (parts{2});
1715 1715
1716 ## If no version is specified for the dependency 1716 ## If no version is specified for the dependency
1717 ## we say that the version should be greater than 1717 ## we say that the version should be greater than
1720 package = tolower (strip (dep)); 1720 package = tolower (strip (dep));
1721 operator = ">="; 1721 operator = ">=";
1722 version = "0.0.0"; 1722 version = "0.0.0";
1723 endif 1723 endif
1724 deps_cell{i} = struct ("package", package, "operator", operator, 1724 deps_cell{i} = struct ("package", package, "operator", operator,
1725 "version", version); 1725 "version", version);
1726 endfor 1726 endfor
1727 endfunction 1727 endfunction
1728 1728
1729 ## Strip the text of spaces from the right 1729 ## Strip the text of spaces from the right
1730 ## Example: " hello world " => " hello world" 1730 ## Example: " hello world " => " hello world"
1837 endif 1837 endif
1838 ## Is the current dependency not Octave? 1838 ## Is the current dependency not Octave?
1839 else 1839 else
1840 ok = false; 1840 ok = false;
1841 for i = 1:length (installed_pkgs_lst) 1841 for i = 1:length (installed_pkgs_lst)
1842 cur_name = installed_pkgs_lst{i}.name; 1842 cur_name = installed_pkgs_lst{i}.name;
1843 cur_version = installed_pkgs_lst{i}.version; 1843 cur_version = installed_pkgs_lst{i}.version;
1844 if (strcmp (dep.package, cur_name) 1844 if (strcmp (dep.package, cur_name)
1845 && compare_versions (cur_version, dep.version, dep.operator)) 1845 && compare_versions (cur_version, dep.version, dep.operator))
1846 ok = true; 1846 ok = true;
1847 break; 1847 break;
1848 endif 1848 endif
1849 endfor 1849 endfor
1850 if (! ok) 1850 if (! ok)
1851 bad_deps{end+1} = dep; 1851 bad_deps{end+1} = dep;
1852 endif 1852 endif
1853 endif 1853 endif
1875 if (find (dup, i)) 1875 if (find (dup, i))
1876 continue; 1876 continue;
1877 endif 1877 endif
1878 for j = (i+1):length (installed_pkgs_lst) 1878 for j = (i+1):length (installed_pkgs_lst)
1879 if (find (dup, j)) 1879 if (find (dup, j))
1880 continue; 1880 continue;
1881 endif 1881 endif
1882 if (strcmp (installed_pkgs_lst{i}.name, installed_pkgs_lst{j}.name)) 1882 if (strcmp (installed_pkgs_lst{i}.name, installed_pkgs_lst{j}.name))
1883 dup = [dup, j]; 1883 dup = [dup, j];
1884 endif 1884 endif
1885 endfor 1885 endfor
1886 endfor 1886 endfor
1887 if (! isempty(dup)) 1887 if (! isempty(dup))
1888 installed_pkgs_lst(dup) = []; 1888 installed_pkgs_lst(dup) = [];
1936 max_name_length = length (h1); 1936 max_name_length = length (h1);
1937 max_version_length = length (h2); 1937 max_version_length = length (h2);
1938 names = cell (num_packages, 1); 1938 names = cell (num_packages, 1);
1939 for i = 1:num_packages 1939 for i = 1:num_packages
1940 max_name_length = max (max_name_length, 1940 max_name_length = max (max_name_length,
1941 length (installed_pkgs_lst{i}.name)); 1941 length (installed_pkgs_lst{i}.name));
1942 max_version_length = max (max_version_length, 1942 max_version_length = max (max_version_length,
1943 length (installed_pkgs_lst{i}.version)); 1943 length (installed_pkgs_lst{i}.version));
1944 names{i} = installed_pkgs_lst{i}.name; 1944 names{i} = installed_pkgs_lst{i}.name;
1945 endfor 1945 endfor
1946 max_dir_length = terminal_size()(2) - max_name_length - ... 1946 max_dir_length = terminal_size()(2) - max_name_length - ...
1947 max_version_length - 7; 1947 max_version_length - 7;
1948 if (max_dir_length < 20) 1948 if (max_dir_length < 20)
1949 max_dir_length = Inf; 1949 max_dir_length = Inf;
1950 endif 1950 endif
1951 1951
1952 h1 = postpad (h1, max_name_length + 1, " "); 1952 h1 = postpad (h1, max_name_length + 1, " ");
1960 tmp(length(h1)+length(h2)+5) = "+"; 1960 tmp(length(h1)+length(h2)+5) = "+";
1961 printf ("%s\n", tmp); 1961 printf ("%s\n", tmp);
1962 1962
1963 ## Print the packages. 1963 ## Print the packages.
1964 format = sprintf ("%%%ds %%1s| %%%ds | %%s\n", max_name_length, 1964 format = sprintf ("%%%ds %%1s| %%%ds | %%s\n", max_name_length,
1965 max_version_length); 1965 max_version_length);
1966 [dummy, idx] = sort (names); 1966 [dummy, idx] = sort (names);
1967 for i = 1:num_packages 1967 for i = 1:num_packages
1968 cur_name = installed_pkgs_lst{idx(i)}.name; 1968 cur_name = installed_pkgs_lst{idx(i)}.name;
1969 cur_version = installed_pkgs_lst{idx(i)}.version; 1969 cur_version = installed_pkgs_lst{idx(i)}.version;
1970 cur_dir = installed_pkgs_lst{idx(i)}.dir; 1970 cur_dir = installed_pkgs_lst{idx(i)}.dir;
1971 if (length (cur_dir) > max_dir_length) 1971 if (length (cur_dir) > max_dir_length)
1972 first_char = length (cur_dir) - max_dir_length + 4; 1972 first_char = length (cur_dir) - max_dir_length + 4;
1973 first_filesep = strfind (cur_dir(first_char:end), filesep()); 1973 first_filesep = strfind (cur_dir(first_char:end), filesep());
1974 if (! isempty (first_filesep)) 1974 if (! isempty (first_filesep))
1975 cur_dir = cstrcat ("...", 1975 cur_dir = cstrcat ("...",
1976 cur_dir((first_char + first_filesep(1) - 1):end)); 1976 cur_dir((first_char + first_filesep(1) - 1):end));
1977 else 1977 else
1978 cur_dir = cstrcat ("...", cur_dir(first_char:end)); 1978 cur_dir = cstrcat ("...", cur_dir(first_char:end));
1979 endif 1979 endif
1980 endif 1980 endif
1981 if (installed_pkgs_lst{idx(i)}.loaded) 1981 if (installed_pkgs_lst{idx(i)}.loaded)
2004 ## Load auto. 2004 ## Load auto.
2005 elseif (length (files) == 1 && strcmp (files{1}, "auto")) 2005 elseif (length (files) == 1 && strcmp (files{1}, "auto"))
2006 idx = []; 2006 idx = [];
2007 for i = 1:length (installed_pkgs_lst) 2007 for i = 1:length (installed_pkgs_lst)
2008 if (exist (fullfile (pdirs{i}, "packinfo", ".autoload"), "file")) 2008 if (exist (fullfile (pdirs{i}, "packinfo", ".autoload"), "file"))
2009 idx (end + 1) = i; 2009 idx (end + 1) = i;
2010 endif 2010 endif
2011 endfor 2011 endfor
2012 ## Load package_name1 ... 2012 ## Load package_name1 ...
2013 else 2013 else
2014 idx = []; 2014 idx = [];
2015 for i = 1:length (files) 2015 for i = 1:length (files)
2016 idx2 = find (strcmp (pnames, files{i})); 2016 idx2 = find (strcmp (pnames, files{i}));
2017 if (! any (idx2)) 2017 if (! any (idx2))
2018 error ("package %s is not installed", files{i}); 2018 error ("package %s is not installed", files{i});
2019 endif 2019 endif
2020 idx (end + 1) = idx2; 2020 idx (end + 1) = idx2;
2021 endfor 2021 endfor
2022 endif 2022 endif
2023 2023
2049 dirs = {}; 2049 dirs = {};
2050 desc = {}; 2050 desc = {};
2051 for i = 1:length (files) 2051 for i = 1:length (files)
2052 idx = strcmp (pnames, files{i}); 2052 idx = strcmp (pnames, files{i});
2053 if (! any (idx)) 2053 if (! any (idx))
2054 error ("package %s is not installed", files{i}); 2054 error ("package %s is not installed", files{i});
2055 endif 2055 endif
2056 dirs{end+1} = pdirs{idx}; 2056 dirs{end+1} = pdirs{idx};
2057 desc{end+1} = installed_pkgs_lst{idx}; 2057 desc{end+1} = installed_pkgs_lst{idx};
2058 endfor 2058 endfor
2059 endif 2059 endif
2060 2060
2061 ## Check for architecture dependent directories. 2061 ## Check for architecture dependent directories.
2130 endif 2130 endif
2131 endfunction 2131 endfunction
2132 2132
2133 function arch = getarch () 2133 function arch = getarch ()
2134 persistent _arch = cstrcat (octave_config_info("canonical_host_type"), ... 2134 persistent _arch = cstrcat (octave_config_info("canonical_host_type"), ...
2135 "-", octave_config_info("api_version")); 2135 "-", octave_config_info("api_version"));
2136 arch = _arch; 2136 arch = _arch;
2137 endfunction 2137 endfunction
2138 2138
2139 function archprefix = getarchprefix (desc, global_install) 2139 function archprefix = getarchprefix (desc, global_install)
2140 if ((nargin == 2 && global_install) || (nargin < 2 && issuperuser ())) 2140 if ((nargin == 2 && global_install) || (nargin < 2 && issuperuser ()))
2141 archprefix = fullfile (octave_config_info ("libexecdir"), "octave", 2141 archprefix = fullfile (octave_config_info ("libexecdir"), "octave",
2142 "packages", cstrcat(desc.name, "-", desc.version)); 2142 "packages", cstrcat(desc.name, "-", desc.version));
2143 else 2143 else
2144 archprefix = desc.dir; 2144 archprefix = desc.dir;
2145 endif 2145 endif
2146 endfunction 2146 endfunction
2147 2147
2182 function newdesc = save_order (desc) 2182 function newdesc = save_order (desc)
2183 newdesc = {}; 2183 newdesc = {};
2184 for i = 1 : length(desc) 2184 for i = 1 : length(desc)
2185 deps = desc{i}.depends; 2185 deps = desc{i}.depends;
2186 if (isempty (deps) || (length (deps) == 1 && 2186 if (isempty (deps) || (length (deps) == 1 &&
2187 strcmp(deps{1}.package, "octave"))) 2187 strcmp(deps{1}.package, "octave")))
2188 newdesc {end + 1} = desc{i}; 2188 newdesc {end + 1} = desc{i};
2189 else 2189 else
2190 tmpdesc = {}; 2190 tmpdesc = {};
2191 for k = 1 : length (deps) 2191 for k = 1 : length (deps)
2192 for j = 1 : length (desc) 2192 for j = 1 : length (desc)
2193 if (strcmp (desc{j}.name, deps{k}.package)) 2193 if (strcmp (desc{j}.name, deps{k}.package))
2194 tmpdesc{end+1} = desc{j}; 2194 tmpdesc{end+1} = desc{j};
2195 break; 2195 break;
2196 endif 2196 endif
2197 endfor 2197 endfor
2198 endfor 2198 endfor
2199 if (! isempty (tmpdesc)) 2199 if (! isempty (tmpdesc))
2200 newdesc = {newdesc{:}, save_order(tmpdesc){:}, desc{i}}; 2200 newdesc = {newdesc{:}, save_order(tmpdesc){:}, desc{i}};
2201 else 2201 else
2202 newdesc{end+1} = desc{i}; 2202 newdesc{end+1} = desc{i};
2203 endif 2203 endif
2204 endif 2204 endif
2214 endfor 2214 endfor
2215 newdesc(idx) = []; 2215 newdesc(idx) = [];
2216 endfunction 2216 endfunction
2217 2217
2218 function load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, 2218 function load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst,
2219 global_install) 2219 global_install)
2220 idx = load_package_dirs (idx, [], handle_deps, installed_pkgs_lst); 2220 idx = load_package_dirs (idx, [], handle_deps, installed_pkgs_lst);
2221 dirs = {}; 2221 dirs = {};
2222 execpath = EXEC_PATH (); 2222 execpath = EXEC_PATH ();
2223 for i = idx; 2223 for i = idx;
2224 ndir = installed_pkgs_lst{i}.dir; 2224 ndir = installed_pkgs_lst{i}.dir;
2247 endfunction 2247 endfunction
2248 2248
2249 function idx = load_package_dirs (lidx, idx, handle_deps, installed_pkgs_lst) 2249 function idx = load_package_dirs (lidx, idx, handle_deps, installed_pkgs_lst)
2250 for i = lidx 2250 for i = lidx
2251 if (isfield (installed_pkgs_lst{i}, "loaded") && 2251 if (isfield (installed_pkgs_lst{i}, "loaded") &&
2252 installed_pkgs_lst{i}.loaded) 2252 installed_pkgs_lst{i}.loaded)
2253 continue; 2253 continue;
2254 else 2254 else
2255 if (handle_deps) 2255 if (handle_deps)
2256 deps = installed_pkgs_lst{i}.depends; 2256 deps = installed_pkgs_lst{i}.depends;
2257 if ((length (deps) > 1) || (length (deps) == 1 && 2257 if ((length (deps) > 1) || (length (deps) == 1 &&
2258 ! strcmp(deps{1}.package, "octave"))) 2258 ! strcmp(deps{1}.package, "octave")))
2259 tmplidx = []; 2259 tmplidx = [];
2260 for k = 1 : length (deps) 2260 for k = 1 : length (deps)
2261 for j = 1 : length (installed_pkgs_lst) 2261 for j = 1 : length (installed_pkgs_lst)
2262 if (strcmp (installed_pkgs_lst{j}.name, deps{k}.package)) 2262 if (strcmp (installed_pkgs_lst{j}.name, deps{k}.package))
2263 tmplidx (end + 1) = j; 2263 tmplidx (end + 1) = j;
2264 break; 2264 break;
2265 endif 2265 endif
2266 endfor 2266 endfor
2267 endfor 2267 endfor
2268 idx = load_package_dirs (tmplidx, idx, handle_deps, 2268 idx = load_package_dirs (tmplidx, idx, handle_deps,
2269 installed_pkgs_lst); 2269 installed_pkgs_lst);
2270 endif 2270 endif
2271 endif 2271 endif
2272 if (isempty (find(idx == i))) 2272 if (isempty (find(idx == i)))
2273 idx (end + 1) = i; 2273 idx (end + 1) = i;
2274 endif 2274 endif
2289 isglob = false; 2289 isglob = false;
2290 endif 2290 endif
2291 pos = findstr (nm, ext); 2291 pos = findstr (nm, ext);
2292 if (pos) 2292 if (pos)
2293 if (! isglob && (length(nm) - pos(end) != length(ext) - 1)) 2293 if (! isglob && (length(nm) - pos(end) != length(ext) - 1))
2294 continue; 2294 continue;
2295 endif 2295 endif
2296 dep = true; 2296 dep = true;
2297 break; 2297 break;
2298 endif 2298 endif
2299 endfor 2299 endfor