Mercurial > octave-nkf
comparison scripts/pkg/pkg.m @ 20510:7fa1970a655d
pkg.m: drop check of nargout value, the interpreter already does that.
* scripts/pkg/pkg.m: the interpreter already checks if there was any variable
that got no value assigned, there's no need to make the code more
complicated to cover that. Also, there's no point in calling describe()
with different nargout since it doesn't check nargout.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Thu, 03 Sep 2015 16:21:08 +0100 |
parents | 9fc020886ae9 |
children | ad7fe3cb6fd2 |
comparison
equal
deleted
inserted
replaced
20509:7d8ec197b08b | 20510:7fa1970a655d |
---|---|
360 | 360 |
361 ## Take action | 361 ## Take action |
362 switch (action) | 362 switch (action) |
363 case "list" | 363 case "list" |
364 if (octave_forge) | 364 if (octave_forge) |
365 if (nargout > 0) | 365 if (nargout) |
366 local_packages = list_forge_packages (); | 366 local_packages = list_forge_packages (); |
367 else | 367 else |
368 list_forge_packages (); | 368 list_forge_packages (); |
369 endif | 369 endif |
370 else | 370 else |
371 if (nargout == 0) | 371 if (nargout) |
372 installed_packages (local_list, global_list, files); | |
373 elseif (nargout == 1) | |
374 local_packages = installed_packages (local_list, global_list, files); | |
375 elseif (nargout == 2) | |
376 [local_packages, global_packages] = installed_packages (local_list, | 372 [local_packages, global_packages] = installed_packages (local_list, |
377 global_list, | 373 global_list, |
378 files); | 374 files); |
379 else | 375 else |
380 error ("too many output arguments requested"); | 376 installed_packages (local_list, global_list, files); |
381 endif | 377 endif |
382 endif | 378 endif |
383 | 379 |
384 case "install" | 380 case "install" |
385 if (isempty (files)) | 381 if (isempty (files)) |
426 error ("you must specify at least one package or 'all' when calling 'pkg unload'"); | 422 error ("you must specify at least one package or 'all' when calling 'pkg unload'"); |
427 endif | 423 endif |
428 unload_packages (files, deps, local_list, global_list); | 424 unload_packages (files, deps, local_list, global_list); |
429 | 425 |
430 case "prefix" | 426 case "prefix" |
431 if (isempty (files) && nargout == 0) | 427 if (isempty (files) && ! nargout) |
432 printf ("Installation prefix: %s\n", prefix); | 428 printf ("Installation prefix: %s\n", prefix); |
433 printf ("Architecture dependent prefix: %s\n", archprefix); | 429 printf ("Architecture dependent prefix: %s\n", archprefix); |
434 elseif (isempty (files) && nargout >= 1) | 430 elseif (isempty (files) && nargout) |
435 local_packages = prefix; | 431 local_packages = prefix; |
436 global_packages = archprefix; | 432 global_packages = archprefix; |
437 elseif (numel (files) >= 1 && nargout <= 2 && ischar (files{1})) | 433 elseif (numel (files) >= 1 && ischar (files{1})) |
438 prefix = tilde_expand (files{1}); | 434 prefix = tilde_expand (files{1}); |
439 if (! exist (prefix, "dir")) | 435 if (! exist (prefix, "dir")) |
440 [status, msg] = mkdir (prefix); | 436 [status, msg] = mkdir (prefix); |
441 if (status == 0) | 437 if (status == 0) |
442 error ("cannot create prefix %s: %s", prefix, msg); | 438 error ("cannot create prefix %s: %s", prefix, msg); |
459 else | 455 else |
460 error ("you must specify a prefix directory, or request an output argument"); | 456 error ("you must specify a prefix directory, or request an output argument"); |
461 endif | 457 endif |
462 | 458 |
463 case "local_list" | 459 case "local_list" |
464 if (isempty (files) && nargout == 0) | 460 if (isempty (files) && ! nargout) |
465 disp (local_list); | 461 disp (local_list); |
466 elseif (isempty (files) && nargout == 1) | 462 elseif (isempty (files) && nargout) |
467 local_packages = local_list; | 463 local_packages = local_list; |
468 elseif (numel (files) == 1 && nargout == 0 && ischar (files{1})) | 464 elseif (numel (files) == 1 && ! nargout && ischar (files{1})) |
469 local_list = files{1}; | 465 local_list = files{1}; |
470 if (! exist (local_list, "file")) | 466 if (! exist (local_list, "file")) |
471 try | 467 try |
472 ## Force file to be created | 468 ## Force file to be created |
473 fclose (fopen (local_list, "wt")); | 469 fclose (fopen (local_list, "wt")); |
479 else | 475 else |
480 error ("you must specify a local_list file, or request an output argument"); | 476 error ("you must specify a local_list file, or request an output argument"); |
481 endif | 477 endif |
482 | 478 |
483 case "global_list" | 479 case "global_list" |
484 if (isempty (files) && nargout == 0) | 480 if (isempty (files) && ! nargout) |
485 disp (global_list); | 481 disp (global_list); |
486 elseif (isempty (files) && nargout == 1) | 482 elseif (isempty (files) && nargout) |
487 local_packages = global_list; | 483 local_packages = global_list; |
488 elseif (numel (files) == 1 && nargout == 0 && ischar (files{1})) | 484 elseif (numel (files) == 1 && ! nargout && ischar (files{1})) |
489 global_list = files{1}; | 485 global_list = files{1}; |
490 if (! exist (global_list, "file")) | 486 if (! exist (global_list, "file")) |
491 try | 487 try |
492 ## Force file to be created | 488 ## Force file to be created |
493 fclose (fopen (files{1}, "wt")); | 489 fclose (fopen (files{1}, "wt")); |
504 if (global_install) | 500 if (global_install) |
505 global_packages = rebuild (prefix, archprefix, global_list, files, | 501 global_packages = rebuild (prefix, archprefix, global_list, files, |
506 auto, verbose); | 502 auto, verbose); |
507 global_packages = save_order (global_packages); | 503 global_packages = save_order (global_packages); |
508 save (global_list, "global_packages"); | 504 save (global_list, "global_packages"); |
509 if (nargout > 0) | 505 if (nargout) |
510 local_packages = global_packages; | 506 local_packages = global_packages; |
511 endif | 507 endif |
512 else | 508 else |
513 local_packages = rebuild (prefix, archprefix, local_list, files, | 509 local_packages = rebuild (prefix, archprefix, local_list, files, |
514 auto, verbose); | 510 auto, verbose); |
515 local_packages = save_order (local_packages); | 511 local_packages = save_order (local_packages); |
516 save (local_list, "local_packages"); | 512 save (local_list, "local_packages"); |
517 if (nargout == 0) | 513 if (! nargout) |
518 clear ("local_packages"); | 514 clear ("local_packages"); |
519 endif | 515 endif |
520 endif | 516 endif |
521 | 517 |
522 case "build" | 518 case "build" |
528 case "describe" | 524 case "describe" |
529 if (isempty (files)) | 525 if (isempty (files)) |
530 error ("you must specify at least one package or 'all' when calling 'pkg describe'"); | 526 error ("you must specify at least one package or 'all' when calling 'pkg describe'"); |
531 endif | 527 endif |
532 ## FIXME: name of the output variables is inconsistent with their content | 528 ## FIXME: name of the output variables is inconsistent with their content |
533 switch (nargout) | 529 if (nargout) |
534 case 0 | 530 [local_packages, global_packages] = describe (files, verbose, |
535 describe (files, verbose, local_list, global_list); | 531 local_list, global_list); |
536 case 1 | 532 else |
537 pkg_desc_list = describe (files, verbose, local_list, global_list); | 533 describe (files, verbose, local_list, global_list); |
538 local_packages = pkg_desc_list; | 534 endif |
539 case 2 | |
540 [pkg_desc_list, flag] = describe (files, verbose, local_list, ... | |
541 global_list); | |
542 local_packages = pkg_desc_list; | |
543 global_packages = flag; | |
544 otherwise | |
545 error ("you can request at most two outputs when calling 'pkg describe'"); | |
546 endswitch | |
547 | 535 |
548 case "update" | 536 case "update" |
549 if (nargout == 0) | 537 installed_pkgs_lst = installed_packages (local_list, global_list); |
550 installed_pkgs_lst = installed_packages (local_list, global_list); | 538 if (numel (files) > 0) |
551 if (numel (files) > 0) | 539 update_lst = {}; |
552 update_lst = {}; | 540 installed_names = {installed_pkgs_list.name}'; |
553 installed_names = {installed_pkgs_list.name}'; | 541 for i = 1:numel (files) |
554 for i = 1:numel (files) | 542 idx = find (strcmp (files{i}, installed_names), 1); |
555 idx = find (strcmp (files{i}, installed_names), 1); | 543 if (isempty (idx)) |
556 if (isempty (idx)) | 544 warning ("Package %s is not installed - not updating this package", files{i}); |
557 warning ("Package %s is not installed - not updating this package", files{i}); | 545 else |
558 else | 546 update_lst = { update_lst, installed_pkgs_lst{idx} }; |
559 update_lst = { update_lst, installed_pkgs_lst{idx} }; | 547 endif |
560 endif | 548 endfor |
561 endfor | 549 installed_pkgs_lst = update_lst; |
562 installed_pkgs_lst = update_lst; | 550 endif |
563 endif | 551 for i = 1:numel (installed_pkgs_lst) |
564 for i = 1:numel (installed_pkgs_lst) | 552 installed_pkg_name = installed_pkgs_lst{i}.name; |
565 installed_pkg_name = installed_pkgs_lst{i}.name; | 553 installed_pkg_version = installed_pkgs_lst{i}.version; |
566 installed_pkg_version = installed_pkgs_lst{i}.version; | 554 forge_pkg_version = get_forge_pkg (installed_pkg_name); |
567 forge_pkg_version = get_forge_pkg (installed_pkg_name); | 555 if (compare_versions (forge_pkg_version, installed_pkg_version, ">")) |
568 if (compare_versions (forge_pkg_version, installed_pkg_version, ">")) | 556 feval (@pkg, "install", "-forge", installed_pkg_name); |
569 feval (@pkg, "install", "-forge", installed_pkg_name); | 557 endif |
570 endif | 558 endfor |
571 endfor | |
572 else | |
573 error ("no output arguments available"); | |
574 endif | |
575 | 559 |
576 otherwise | 560 otherwise |
577 error ("you must specify a valid action for 'pkg'. See 'help pkg' for details"); | 561 error ("you must specify a valid action for 'pkg'. See 'help pkg' for details"); |
578 endswitch | 562 endswitch |
579 | 563 |