view scripts/pkg/private/installed_packages.m @ 21633:dcf8922b724b

Deprecate printf, puts, and scanf. Make fputs a M-file. * libinterp/corefcn/file-io.cc: extracted printf, puts, and scanf to M-files. * scripts/deprecated/printf.m: new function, equivalent to version file-io.cc. * scripts/deprecated/puts.m: new function, equivalent to version file-io.cc. * scripts/deprecated/scanf.m: new function, equivalent to version file-io.cc. * scripts/deprecated/module.mk: added printf, puts, and scanf. * scripts/io/fputs.m: new function, equivalent to version file-io.cc. * scripts/io/module.mk: added fputs. * doc/interpreter/io.txi: adapted documentation to current implementation. * NEWS: announced changes. * doc/interpreter/basics.txi: replaced printf by fprintf. * doc/interpreter/stmt.txi: replaced printf by fprintf. * doc/interpreter/var.txi: replaced printf by fprintf. * doc/refcard/refcard.tex: removed printf and scanf. * examples/code/@FIRfilter/display.m: replaced printf by fprintf. * examples/code/@polynomial/display.m: replaced printf by fprintf. * scripts/@ftp/display.m: replaced printf by fprintf. * scripts/general/inputParser.m: replaced printf by fprintf. * scripts/general/methods.m: replaced printf by fprintf. * scripts/general/profexplore.m: replaced printf by fprintf. * scripts/general/profshow.m: replaced printf by fprintf. * scripts/help/help.m: replaced puts by fputs and printf by fprintf. * scripts/help/lookfor.m: replaced puts by fputs and printf by fprintf. * scripts/help/which.m: replaced printf by fprintf. * scripts/image/imformats.m: replaced printf by fprintf. * scripts/io/beep.m: replaced puts by fputs. * scripts/io/textread.m: replaced printf by fprintf. * scripts/java/javaclasspath.m: replaced printf by fprintf. * scripts/java/javamem.m: replaced printf by fprintf. * scripts/miscellaneous/dir.m: replaced printf by fprintf. * scripts/miscellaneous/dos.m: replaced printf by fprintf. * scripts/miscellaneous/fact.m: replaced printf by fprintf. * scripts/miscellaneous/info.m: replaced printf by fprintf. * scripts/miscellaneous/license.m: replaced printf by fprintf. * scripts/miscellaneous/ls.m: replaced puts by fputs. * scripts/miscellaneous/menu.m: replaced printf by fprintf. * scripts/miscellaneous/mkoctfile.m: replaced printf by fprintf. * scripts/miscellaneous/private/display_info_file.m: * scripts/miscellaneous/unix.m: replaced printf by fprintf. * scripts/miscellaneous/ver.m: replaced printf by fprintf. * scripts/miscellaneous/what.m: replaced printf by fprintf. * scripts/ode/ode23.m: replaced printf by fprintf. * scripts/ode/ode45.m: replaced printf by fprintf. * scripts/optimization/fminbnd.m: replaced printf by fprintf. * scripts/optimization/optimset.m: replaced puts by fputs and printf by fprintf. * scripts/optimization/sqp.m: replaced printf by fprintf. * scripts/pkg/pkg.m: replaced printf by fprintf. * scripts/pkg/private/describe.m: replaced printf by fprintf. * scripts/pkg/private/install.m: replaced printf by fprintf. * scripts/pkg/private/installed_packages.m: replaced printf by fprintf. * scripts/pkg/private/list_forge_packages.m: replaced puts by fputs and printf by fprintf. * scripts/pkg/private/rebuild.m: replaced printf by fprintf. * scripts/plot/util/__gnuplot_drawnow__.m: replaced puts by fputs and printf by fprintf. * scripts/signal/stft.m: replaced printf by fprintf. * scripts/sparse/bicg.m: replaced printf by fprintf. * scripts/sparse/bicgstab.m: replaced printf by fprintf. * scripts/sparse/cgs.m: replaced printf by fprintf. * scripts/sparse/pcg.m: replaced printf by fprintf. * scripts/sparse/pcr.m: replaced printf by fprintf. * scripts/sparse/qmr.m: replaced printf by fprintf. * scripts/statistics/models/logistic_regression.m: replaced printf by fprintf. * scripts/statistics/tests/anova.m: replaced printf by fprintf. * scripts/statistics/tests/bartlett_test.m: replaced printf by fprintf. * scripts/statistics/tests/chisquare_test_homogeneity.m: replaced printf by fprintf. * scripts/statistics/tests/chisquare_test_independence.m: replaced printf by fprintf. * scripts/statistics/tests/cor_test.m: replaced printf by fprintf. * scripts/statistics/tests/f_test_regression.m: replaced printf by fprintf. * scripts/statistics/tests/hotelling_test.m: replaced printf by fprintf. * scripts/statistics/tests/hotelling_test_2.m: replaced printf by fprintf. * scripts/statistics/tests/kolmogorov_smirnov_test.m: replaced printf by fprintf. * scripts/statistics/tests/kolmogorov_smirnov_test_2.m: replaced printf by fprintf. * scripts/statistics/tests/kruskal_wallis_test.m: replaced printf by fprintf. * scripts/statistics/tests/manova.m: replaced printf by fprintf. * scripts/statistics/tests/mcnemar_test.m: replaced printf by fprintf. * scripts/statistics/tests/prop_test_2.m: replaced printf by fprintf. * scripts/statistics/tests/run_test.m: replaced printf by fprintf. * scripts/statistics/tests/sign_test.m: replaced printf by fprintf. * scripts/statistics/tests/t_test.m: replaced printf by fprintf. * scripts/statistics/tests/t_test_2.m: replaced printf by fprintf. * scripts/statistics/tests/t_test_regression.m: replaced printf by fprintf. * scripts/statistics/tests/u_test.m: replaced printf by fprintf. * scripts/statistics/tests/var_test.m: replaced printf by fprintf. * scripts/statistics/tests/welch_test.m: replaced printf by fprintf. * scripts/statistics/tests/wilcoxon_test.m: replaced printf by fprintf. * scripts/statistics/tests/z_test.m: replaced printf by fprintf. * scripts/statistics/tests/z_test_2.m: replaced printf by fprintf. * scripts/strings/strtok.m: replaced printf by fprintf. * scripts/testfun/__run_test_suite__.m: replaced puts by fputs and printf by fprintf. * scripts/testfun/demo.m: replaced printf by fprintf. * scripts/testfun/example.m: replaced printf by fprintf. * scripts/testfun/private/compare_plot_demos.m: replaced printf by fprintf. * scripts/testfun/rundemos.m: replaced printf by fprintf. * scripts/testfun/runtests.m: replaced puts by fputs and printf by fprintf. * scripts/testfun/speed.m: replaced printf by fprintf. * scripts/testfun/test.m: replaced printf by fprintf. * scripts/time/calendar.m: replaced puts by fputs and printf by fprintf. * test/io.tst: replaced printf by fprintf.
author Kai T. Ohlhus <k.ohlhus@gmail.com>
date Wed, 20 Apr 2016 17:53:10 +0200
parents 516bb87ea72e
children 96518f623c91
line wrap: on
line source

## Copyright (C) 2005-2015 Søren Hauberg
## Copyright (C) 2010 VZLU Prague, a.s.
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {} {[@var{out1}, @var{out2}] =} installed_packages (@var{local_list}, @var{global_list})
## Undocumented internal function.
## @end deftypefn

function [out1, out2] = installed_packages (local_list, global_list, pkgname = {})

  ## Get the list of installed packages.
  try
    local_packages = load (local_list).local_packages;
  catch
    local_packages = {};
  end_try_catch
  try
    global_packages = load (global_list).global_packages;
  catch
    global_packages = {};
  end_try_catch
  installed_pkgs_lst = {local_packages{:}, global_packages{:}};

  ## Eliminate duplicates in the installed package list.
  ## Locally installed packages take precedence.
  installed_names = cellfun (@(x) x.name, installed_pkgs_lst,
                             "uniformoutput", false);
  [~, idx] = unique (installed_names, "first");
  installed_names = installed_names(idx);
  installed_pkgs_lst = installed_pkgs_lst(idx);

  ## Check whether info on a particular package was requested
  if (! isempty (pkgname))
    idx = find (strcmp (pkgname{1}, installed_names));
    if (isempty (idx))
      installed_names = {};
      installed_pkgs_lst = {};
    else
      installed_names = installed_names(idx);
      installed_pkgs_lst = installed_pkgs_lst(idx);
    endif
  endif

  ## Now check if the package is loaded.
  ## FIXME: couldn't dir_in_loadpath() be used here?
  tmppath = strrep (path (), "\\", "/");
  for i = 1:numel (installed_pkgs_lst)
    if (strfind (tmppath, strrep (installed_pkgs_lst{i}.dir, '\', '/')))
      installed_pkgs_lst{i}.loaded = true;
    else
      installed_pkgs_lst{i}.loaded = false;
    endif
  endfor
  for i = 1:numel (local_packages)
    if (strfind (tmppath, strrep (local_packages{i}.dir, '\', '/')))
      local_packages{i}.loaded = true;
    else
      local_packages{i}.loaded = false;
    endif
  endfor
  for i = 1:numel (global_packages)
    if (strfind (tmppath, strrep (global_packages{i}.dir, '\', '/')))
      global_packages{i}.loaded = true;
    else
      global_packages{i}.loaded = false;
    endif
  endfor

  ## Should we return something?
  if (nargout == 1)
    out1 = installed_pkgs_lst;
  elseif (nargout > 1)
    out1 = local_packages;
    out2 = global_packages;
  else
    ## Don't return anything, instead we'll print something.
    num_packages = numel (installed_pkgs_lst);
    if (num_packages == 0)
      if (isempty (pkgname))
        fprintf ("no packages installed.\n");
      else
        fprintf ("package %s is not installed.\n", pkgname{1});
      endif
      return;
    endif

    ## Compute the maximal lengths of name, version, and dir.
    h1 = "Package Name";
    h2 = "Version";
    h3 = "Installation directory";
    max_name_length = max ([length(h1), cellfun(@length, installed_names)]);
    version_lengths = cellfun (@(x) length (x.version), installed_pkgs_lst);
    max_version_length = max ([length(h2), version_lengths]);
    ncols = terminal_size ()(2);
    max_dir_length = ncols - max_name_length - max_version_length - 7;
    if (max_dir_length < 20)
      max_dir_length = Inf;
    endif

    h1 = postpad (h1, max_name_length + 1, " ");
    h2 = postpad (h2, max_version_length, " ");;

    ## Print a header.
    header = sprintf ("%s | %s | %s\n", h1, h2, h3);
    fprintf (header);
    tmp = sprintf (repmat ("-", 1, length (header) - 1));
    tmp(length(h1)+2) = "+";
    tmp(length(h1)+length(h2)+5) = "+";
    fprintf ("%s\n", tmp);

    ## Print the packages.
    format = sprintf ("%%%ds %%1s| %%%ds | %%s\n",
                      max_name_length, max_version_length);
    for i = 1:num_packages
      cur_name = installed_pkgs_lst{i}.name;
      cur_version = installed_pkgs_lst{i}.version;
      cur_dir = installed_pkgs_lst{i}.dir;
      if (length (cur_dir) > max_dir_length)
        first_char = length (cur_dir) - max_dir_length + 4;
        first_filesep = strfind (cur_dir(first_char:end), filesep ());
        if (! isempty (first_filesep))
          cur_dir = ["..." cur_dir((first_char + first_filesep(1) - 1):end)];
        else
          cur_dir = ["..." cur_dir(first_char:end)];
        endif
      endif
      if (installed_pkgs_lst{i}.loaded)
        cur_loaded = "*";
      else
        cur_loaded = " ";
      endif
      fprintf (format, cur_name, cur_loaded, cur_version, cur_dir);
    endfor
  endif
endfunction