annotate scripts/pkg/private/installed_packages.m @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 7854d5752dd2
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 2005-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27879
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
7 ##
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
8 ## This file is part of Octave.
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24370
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24370
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
14 ##
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
19 ##
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24370
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
25
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
26 ## -*- texinfo -*-
22760
c4d80b9d2898 maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents: 22755
diff changeset
27 ## @deftypefn {} {[@var{out1}, @var{out2}] =} installed_packages (@var{local_list}, @var{global_list}, @var{pkgname})
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
28 ## Undocumented internal function.
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
29 ## @end deftypefn
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
30
19187
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
31 function [out1, out2] = installed_packages (local_list, global_list, pkgname = {})
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
32
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
33 ## Get the list of installed packages.
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
34 try
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
35 local_packages = load (local_list).local_packages;
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
36 catch
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
37 local_packages = {};
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
38 end_try_catch
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
39 try
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
40 global_packages = load (global_list).global_packages;
27707
377f069841c1 Make packages installation dirs in global octave_packages file relative
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 27573
diff changeset
41 global_packages = expand_rel_paths (global_packages);
377f069841c1 Make packages installation dirs in global octave_packages file relative
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 27573
diff changeset
42 if (ispc)
377f069841c1 Make packages installation dirs in global octave_packages file relative
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 27573
diff changeset
43 ## On Windows ensure 8.3 style paths are turned into LFN paths
377f069841c1 Make packages installation dirs in global octave_packages file relative
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 27573
diff changeset
44 global_packages = standardize_paths (global_packages);
377f069841c1 Make packages installation dirs in global octave_packages file relative
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 27573
diff changeset
45 endif
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
46 catch
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
47 global_packages = {};
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
48 end_try_catch
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
49 installed_pkgs_lst = {local_packages{:}, global_packages{:}};
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
50
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
51 ## Eliminate duplicates in the installed package list.
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
52 ## Locally installed packages take precedence.
19187
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
53 installed_names = cellfun (@(x) x.name, installed_pkgs_lst,
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
54 "uniformoutput", false);
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
55 [~, idx] = unique (installed_names, "first");
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
56 installed_names = installed_names(idx);
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
57 installed_pkgs_lst = installed_pkgs_lst(idx);
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
58
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
59 ## Check whether info on a particular package was requested
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
60 if (! isempty (pkgname))
27879
b9710ee393ac Allow multiple package names for each pkg action (bug #57489).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 27707
diff changeset
61 idx = [];
b9710ee393ac Allow multiple package names for each pkg action (bug #57489).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 27707
diff changeset
62 for i = 1 : numel (pkgname)
b9710ee393ac Allow multiple package names for each pkg action (bug #57489).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 27707
diff changeset
63 idx = [idx, find(strcmp (pkgname{i}, installed_names))];
b9710ee393ac Allow multiple package names for each pkg action (bug #57489).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 27707
diff changeset
64 endfor
19187
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
65 if (isempty (idx))
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
66 installed_names = {};
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
67 installed_pkgs_lst = {};
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
68 else
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
69 installed_names = installed_names(idx);
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
70 installed_pkgs_lst = installed_pkgs_lst(idx);
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
71 endif
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
72 endif
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
73
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
74 ## Now check if the package is loaded.
22760
c4d80b9d2898 maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents: 22755
diff changeset
75 ## FIXME: Couldn't dir_in_loadpath() be used here?
27573
0cedd1e23c1f Adapt path styles for pkg.m on Windows (bug #57083)
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 26376
diff changeset
76 tmppath = path ();
19187
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
77 for i = 1:numel (installed_pkgs_lst)
27573
0cedd1e23c1f Adapt path styles for pkg.m on Windows (bug #57083)
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 26376
diff changeset
78 if (strfind (tmppath, installed_pkgs_lst{i}.dir))
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
79 installed_pkgs_lst{i}.loaded = true;
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
80 else
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
81 installed_pkgs_lst{i}.loaded = false;
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
82 endif
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
83 endfor
19187
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
84 for i = 1:numel (local_packages)
27573
0cedd1e23c1f Adapt path styles for pkg.m on Windows (bug #57083)
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 26376
diff changeset
85 if (strfind (tmppath, local_packages{i}.dir))
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
86 local_packages{i}.loaded = true;
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
87 else
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
88 local_packages{i}.loaded = false;
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
89 endif
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
90 endfor
19187
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
91 for i = 1:numel (global_packages)
27573
0cedd1e23c1f Adapt path styles for pkg.m on Windows (bug #57083)
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 26376
diff changeset
92 if (strfind (tmppath, global_packages{i}.dir))
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
93 global_packages{i}.loaded = true;
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
94 else
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
95 global_packages{i}.loaded = false;
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
96 endif
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
97 endfor
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
98
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
99 ## Should we return something?
20480
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
100 if (nargout == 1)
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
101 out1 = installed_pkgs_lst;
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
102 elseif (nargout > 1)
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
103 out1 = local_packages;
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
104 out2 = global_packages;
20480
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
105 else
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
106 ## Don't return anything, instead we'll print something.
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
107 num_packages = numel (installed_pkgs_lst);
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
108 if (num_packages == 0)
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
109 if (isempty (pkgname))
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
110 printf ("no packages installed.\n");
20480
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
111 else
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
112 printf ("package %s is not installed.\n", pkgname{1});
20480
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
113 endif
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
114 return;
19187
b54093acb8fe ver.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
115 endif
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
116
20480
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
117 ## Compute the maximal lengths of name, version, and dir.
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
118 h1 = "Package Name";
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
119 h2 = "Version";
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
120 h3 = "Installation directory";
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
121 max_name_length = max ([length(h1), cellfun(@length, installed_names)]);
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
122 version_lengths = cellfun (@(x) length (x.version), installed_pkgs_lst);
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
123 max_version_length = max ([length(h2), version_lengths]);
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
124 ncols = terminal_size ()(2);
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
125 max_dir_length = ncols - max_name_length - max_version_length - 7;
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
126 if (max_dir_length < 20)
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
127 max_dir_length = Inf;
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
128 endif
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
129
20480
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
130 h1 = postpad (h1, max_name_length + 1, " ");
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
131 h2 = postpad (h2, max_version_length, " ");;
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
132
20480
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
133 ## Print a header.
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
134 header = sprintf ("%s | %s | %s\n", h1, h2, h3);
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
135 printf (header);
20480
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
136 tmp = sprintf (repmat ("-", 1, length (header) - 1));
28912
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 27923
diff changeset
137 tmp(length (h1)+2) = "+";
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 27923
diff changeset
138 tmp(length (h1)+length (h2)+5) = "+";
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
139 printf ("%s\n", tmp);
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
140
20480
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
141 ## Print the packages.
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
142 format = sprintf ("%%%ds %%1s| %%%ds | %%s\n",
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
143 max_name_length, max_version_length);
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
144 for i = 1:num_packages
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
145 cur_name = installed_pkgs_lst{i}.name;
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
146 cur_version = installed_pkgs_lst{i}.version;
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
147 cur_dir = installed_pkgs_lst{i}.dir;
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
148 if (length (cur_dir) > max_dir_length)
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
149 first_char = length (cur_dir) - max_dir_length + 4;
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
150 first_filesep = strfind (cur_dir(first_char:end), filesep ());
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
151 if (! isempty (first_filesep))
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
152 cur_dir = ["..." cur_dir((first_char + first_filesep(1) - 1):end)];
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
153 else
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
154 cur_dir = ["..." cur_dir(first_char:end)];
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
155 endif
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
156 endif
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
157 if (installed_pkgs_lst{i}.loaded)
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
158 cur_loaded = "*";
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
159 else
20480
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
160 cur_loaded = " ";
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
161 endif
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
162 printf (format, cur_name, cur_loaded, cur_version, cur_dir);
20480
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
163 endfor
ad7fe3cb6fd2 pkg: fix regression on output of pkg list (bug #45873)
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
164 endif
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21634
diff changeset
165
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
166 endfunction