Mercurial > hg > octave-lyh
annotate scripts/pkg/pkg.m @ 12931:cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
* accumarray.m arrayfun.m, blkdiag.m, cell2mat.m, common_size.m, interp3.m,
interpn.m, __isequal__.m, structfun.m, voronoi.m, strread.m, fullfile.m,
getfield.m, __xzip__.m, setfield.m, what.m, pkg.m, axis.m, pareto.m,
__ghostscript__.m, __go_draw_axes__.m, __patch__.m, refreshdata.m, whitebg.m,
lcm.m, index.m, strcat.m, strmatch.m, validatestring.m: Replace function
handles in calls to cellfun with double quoted function names.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 06 Aug 2011 18:03:18 -0700 |
parents | 095fd5c8b7e1 |
children | e81ddf9cacd5 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2005-2011 S�ren Hauberg |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
2 ## Copyright (C) 2010 VZLU Prague, a.s. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3 ## |
6440 | 4 ## This file is part of Octave. |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
6440 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
5801 | 16 ## You should have received a copy of the GNU General Public License |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5801 | 19 |
20 ## -*- texinfo -*- | |
11547 | 21 ## @deftypefn {Command} {} pkg @var{command} @var{pkg_name} |
22 ## @deftypefnx {Command} {} pkg @var{command} @var{option} @var{pkg_name} | |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
23 ## Manage packages (groups of add-on functions) for Octave. Different actions |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
24 ## are available depending on the value of @var{command}. |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
25 ## |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
26 ## Available commands: |
6032 | 27 ## |
28 ## @table @samp | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
29 ## |
6032 | 30 ## @item install |
6070 | 31 ## Install named packages. For example, |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
32 ## |
6070 | 33 ## @example |
34 ## pkg install image-1.0.0.tar.gz | |
35 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
36 ## |
6070 | 37 ## @noindent |
9307
c2923c27c877
Various documentation improvements
Rik <rdrider0-list@yahoo.com>
parents:
9258
diff
changeset
|
38 ## installs the package found in the file @file{image-1.0.0.tar.gz}. |
6070 | 39 ## |
6645 | 40 ## The @var{option} variable can contain options that affect the manner |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
41 ## in which a package is installed. These options can be one or more of |
6645 | 42 ## |
43 ## @table @code | |
44 ## @item -nodeps | |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
45 ## The package manager will disable dependency checking. With this option it |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
46 ## is possible to install a package even when it depends on another package |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
47 ## which is not installed on the system. @strong{Use this option with care.} |
6645 | 48 ## |
49 ## @item -noauto | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
50 ## The package manager will not automatically load the installed package |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
51 ## when starting Octave. This overrides any setting within the package. |
6258 | 52 ## |
6645 | 53 ## @item -auto |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
54 ## The package manager will automatically load the installed package when |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
55 ## starting Octave. This overrides any setting within the package. |
6645 | 56 ## |
57 ## @item -local | |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
58 ## A local installation (package available only to current user) is forced, |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
59 ## even if the user has system privileges. |
6258 | 60 ## |
6645 | 61 ## @item -global |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
62 ## A global installation (package available to all users) is forced, even if |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
63 ## the user doesn't normally have system privileges. |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12561
diff
changeset
|
64 ## |
12561
0ade5992e374
Add documentation for '-forge' option (bug #32464).
Rik <octave@nomad.inbox5.com>
parents:
12167
diff
changeset
|
65 ## @item -forge |
0ade5992e374
Add documentation for '-forge' option (bug #32464).
Rik <octave@nomad.inbox5.com>
parents:
12167
diff
changeset
|
66 ## Install a package directly from the Octave-Forge repository. This |
0ade5992e374
Add documentation for '-forge' option (bug #32464).
Rik <octave@nomad.inbox5.com>
parents:
12167
diff
changeset
|
67 ## requires an internet connection and the cURL library. |
6614 | 68 ## |
6645 | 69 ## @item -verbose |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
70 ## The package manager will print the output of all commands as |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
71 ## they are performed. |
6645 | 72 ## @end table |
73 ## | |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
74 ## @item update |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
75 ## Check installed Octave-Forge pacakages against repository and update any |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
76 ## outdated items. This requires an internet connection and the cURL library. |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
77 ## Usage: |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
78 ## |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
79 ## @example |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
80 ## pkg update |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
81 ## @end example |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
82 ## |
6032 | 83 ## @item uninstall |
6070 | 84 ## Uninstall named packages. For example, |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
85 ## |
6070 | 86 ## @example |
87 ## pkg uninstall image | |
88 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
89 ## |
6070 | 90 ## @noindent |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
91 ## removes the @code{image} package from the system. If another installed |
6070 | 92 ## package depends on the @code{image} package an error will be issued. |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10685
diff
changeset
|
93 ## The package can be uninstalled anyway by using the @option{-nodeps} option. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
94 ## |
6032 | 95 ## @item load |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
96 ## Add named packages to the path. After loading a package it is |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
97 ## possible to use the functions provided by the package. For example, |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
98 ## |
6070 | 99 ## @example |
100 ## pkg load image | |
101 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
102 ## |
6070 | 103 ## @noindent |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
104 ## adds the @code{image} package to the path. It is possible to load all |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
105 ## installed packages at once with the keyword @samp{all}. Usage: |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
106 ## |
6070 | 107 ## @example |
108 ## pkg load all | |
109 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
110 ## |
6203 | 111 ## @item unload |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
112 ## Remove named packages from the path. After unloading a package it is |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
113 ## no longer possible to use the functions provided by the package. It is |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
114 ## possible to unload all installed packages at once with the keyword |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
115 ## @samp{all}. Usage: |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
116 ## |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
117 ## @example |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
118 ## pkg unload all |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
119 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
120 ## |
6032 | 121 ## @item list |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
122 ## Show the list of currently installed packages. For example, |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
123 ## |
6070 | 124 ## @example |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
125 ## installed_packages = pkg ("list") |
6070 | 126 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
127 ## |
6070 | 128 ## @noindent |
129 ## returns a cell array containing a structure for each installed package. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
130 ## |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
131 ## If two output arguments are requested @code{pkg} splits the list of |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
132 ## installed packages into those which were installed by the current user, |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
133 ## and those which were installed by the system administrator. |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
134 ## |
6070 | 135 ## @example |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
136 ## [user_packages, system_packages] = pkg ("list") |
6070 | 137 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
138 ## |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
139 ## The option '-forge' lists packages available at the Octave-Forge repository. |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
140 ## This requires an internet connection and the cURL library. For example: |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
141 ## |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
142 ## @example |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
143 ## oct_forge_pkgs = pkg ("list", "-forge") |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
144 ## @end example |
12561
0ade5992e374
Add documentation for '-forge' option (bug #32464).
Rik <octave@nomad.inbox5.com>
parents:
12167
diff
changeset
|
145 ## |
7497 | 146 ## @item describe |
147 ## Show a short description of the named installed packages, with the option | |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
148 ## '-verbose' also list functions provided by the package. For example, |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
149 ## |
7497 | 150 ## @example |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
151 ## pkg describe -verbose all |
7497 | 152 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
153 ## |
7497 | 154 ## @noindent |
155 ## will describe all installed packages and the functions they provide. | |
156 ## If one output is requested a cell of structure containing the | |
157 ## description and list of functions of each package is returned as | |
158 ## output rather than printed on screen: | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
159 ## |
7497 | 160 ## @example |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
161 ## desc = pkg ("describe", "secs1d", "image") |
7497 | 162 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
163 ## |
7497 | 164 ## @noindent |
165 ## If any of the requested packages is not installed, pkg returns an | |
166 ## error, unless a second output is requested: | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
167 ## |
7497 | 168 ## @example |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
169 ## [desc, flag] = pkg ("describe", "secs1d", "image") |
7497 | 170 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
171 ## |
7497 | 172 ## @noindent |
173 ## @var{flag} will take one of the values "Not installed", "Loaded" or | |
174 ## "Not loaded" for each of the named packages. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
175 ## |
6034 | 176 ## @item prefix |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
177 ## Set the installation prefix directory. For example, |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
178 ## |
6070 | 179 ## @example |
180 ## pkg prefix ~/my_octave_packages | |
181 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
182 ## |
6070 | 183 ## @noindent |
9307
c2923c27c877
Various documentation improvements
Rik <rdrider0-list@yahoo.com>
parents:
9258
diff
changeset
|
184 ## sets the installation prefix to @file{~/my_octave_packages}. |
6070 | 185 ## Packages will be installed in this directory. |
6034 | 186 ## |
6070 | 187 ## It is possible to get the current installation prefix by requesting an |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
188 ## output argument. For example: |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
189 ## |
6070 | 190 ## @example |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
191 ## pfx = pkg ("prefix") |
6070 | 192 ## @end example |
6925 | 193 ## |
194 ## The location in which to install the architecture dependent files can be | |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
195 ## independently specified with an addition argument. For example: |
6925 | 196 ## |
197 ## @example | |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
198 ## pkg prefix ~/my_octave_packages ~/my_arch_dep_pkgs |
6925 | 199 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
200 ## |
6189 | 201 ## @item local_list |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
202 ## Set the file in which to look for information on locally |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
203 ## installed packages. Locally installed packages are those that are |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
204 ## available only to the current user. For example: |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
205 ## |
6189 | 206 ## @example |
207 ## pkg local_list ~/.octave_packages | |
208 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
209 ## |
6189 | 210 ## It is possible to get the current value of local_list with the following |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
211 ## |
6189 | 212 ## @example |
213 ## pkg local_list | |
214 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
215 ## |
6189 | 216 ## @item global_list |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
217 ## Set the file in which to look for information on globally |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
218 ## installed packages. Globally installed packages are those that are |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
219 ## available to all users. For example: |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
220 ## |
6189 | 221 ## @example |
222 ## pkg global_list /usr/share/octave/octave_packages | |
223 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
224 ## |
6189 | 225 ## It is possible to get the current value of global_list with the following |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
226 ## |
6189 | 227 ## @example |
228 ## pkg global_list | |
229 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
230 ## |
6675 | 231 ## @item build |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
232 ## Build a binary form of a package or packages. The binary file produced |
6675 | 233 ## will itself be an Octave package that can be installed normally with |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8942
diff
changeset
|
234 ## @code{pkg}. The form of the command to build a binary package is |
6675 | 235 ## |
236 ## @example | |
237 ## pkg build builddir image-1.0.0.tar.gz @dots{} | |
238 ## @end example | |
239 ## | |
240 ## @noindent | |
9079
4d610aba7347
Cleanup documentation for system.texi, package.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
241 ## where @code{builddir} is the name of a directory where the temporary |
6675 | 242 ## installation will be produced and the binary packages will be found. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
243 ## The options @option{-verbose} and @option{-nodeps} are respected, while |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
244 ## all other options are ignored. |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
245 ## |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
246 ## @item rebuild |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
247 ## Rebuild the package database from the installed directories. This can |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
248 ## be used in cases where the package database has been corrupted. |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
249 ## It can also take the @option{-auto} and @option{-noauto} options to allow the |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
250 ## autoloading state of a package to be changed. For example, |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
251 ## |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
252 ## @example |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
253 ## pkg rebuild -noauto image |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
254 ## @end example |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
255 ## |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
256 ## @noindent |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
257 ## will remove the autoloading status of the image package. |
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
258 ## |
6032 | 259 ## @end table |
11547 | 260 ## @end deftypefn |
5947 | 261 |
6496 | 262 function [local_packages, global_packages] = pkg (varargin) |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8174
diff
changeset
|
263 ## Installation prefix (FIXME: what should these be on windows?) |
6645 | 264 persistent user_prefix = false; |
6496 | 265 persistent prefix = -1; |
6925 | 266 persistent archprefix = -1; |
7498 | 267 persistent local_list = tilde_expand (fullfile ("~", ".octave_packages")); |
6496 | 268 persistent global_list = fullfile (OCTAVE_HOME (), "share", "octave", |
10549 | 269 "octave_packages"); |
6496 | 270 mlock (); |
6189 | 271 |
6925 | 272 global_install = issuperuser (); |
6683 | 273 |
6496 | 274 if (prefix == -1) |
6645 | 275 if (global_install) |
6496 | 276 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); |
12710
762d10c77277
maint: use libdir for .oct files, not libexecdir
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
277 archprefix = fullfile (octave_config_info ("libdir"), |
10549 | 278 "octave", "packages"); |
6496 | 279 else |
280 prefix = fullfile ("~", "octave"); | |
6925 | 281 archprefix = prefix; |
5801 | 282 endif |
6645 | 283 prefix = tilde_expand (prefix); |
6925 | 284 archprefix = tilde_expand (archprefix); |
6496 | 285 endif |
286 | |
7498 | 287 available_actions = {"list", "install", "uninstall", "load", ... |
12779
095fd5c8b7e1
doc: Update docstring for pkg()
Rik <octave@nomad.inbox5.com>
parents:
12778
diff
changeset
|
288 "unload", "prefix", "local_list", ... |
12778
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
289 "global_list", "rebuild", "build", ... |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
290 "describe", "update"}; |
6496 | 291 ## Handle input |
292 if (length (varargin) == 0 || ! iscellstr (varargin)) | |
293 print_usage (); | |
294 endif | |
295 files = {}; | |
296 deps = true; | |
297 auto = 0; | |
298 action = "none"; | |
6614 | 299 verbose = false; |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
300 octave_forge = false; |
6496 | 301 for i = 1:length (varargin) |
302 switch (varargin{i}) | |
303 case "-nodeps" | |
10549 | 304 deps = false; |
6496 | 305 case "-noauto" |
10549 | 306 auto = -1; |
6496 | 307 case "-auto" |
10549 | 308 auto = 1; |
6614 | 309 case "-verbose" |
10549 | 310 verbose = true; |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
311 case "-forge" |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
312 octave_forge = true; |
6645 | 313 case "-local" |
10549 | 314 global_install = false; |
315 if (! user_prefix) | |
316 prefix = tilde_expand (fullfile ("~", "octave")); | |
317 archprefix = prefix; | |
318 endif | |
6645 | 319 case "-global" |
10549 | 320 global_install = true; |
321 if (! user_prefix) | |
322 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); | |
12710
762d10c77277
maint: use libdir for .oct files, not libexecdir
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
323 archprefix = fullfile (octave_config_info ("libdir"), |
10549 | 324 "octave", "packages"); |
325 endif | |
7497 | 326 case available_actions |
10549 | 327 if (strcmp (action, "none")) |
328 action = varargin{i}; | |
329 else | |
330 error ("more than one action specified"); | |
331 endif | |
6496 | 332 otherwise |
10549 | 333 files{end+1} = varargin{i}; |
5801 | 334 endswitch |
6496 | 335 endfor |
336 | |
10685
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
337 if (octave_forge && ! any (strcmp (action, {"install", "list"}))) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
338 error ("-forge can only be used with install or list"); |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
339 endif |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
340 |
6496 | 341 ## Take action |
342 switch (action) | |
343 case "list" | |
10685
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
344 if (octave_forge) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
345 if (nargout > 0) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
346 local_packages = list_forge_packages (); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
347 else |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
348 list_forge_packages (); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
349 endif |
6496 | 350 else |
10685
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
351 if (nargout == 0) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
352 installed_packages (local_list, global_list); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
353 elseif (nargout == 1) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
354 local_packages = installed_packages (local_list, global_list); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
355 elseif (nargout == 2) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
356 [local_packages, global_packages] = installed_packages (local_list, |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
357 global_list); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
358 else |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
359 error ("too many output arguments requested"); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
360 endif |
6496 | 361 endif |
362 | |
363 case "install" | |
364 if (length (files) == 0) | |
10549 | 365 error ("you must specify at least one filename when calling 'pkg install'"); |
6496 | 366 endif |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
367 |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
368 local_files = {}; |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
369 unwind_protect |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
370 |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
371 if (octave_forge) |
12931
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
12779
diff
changeset
|
372 [urls, local_files] = cellfun ("get_forge_download", files, "uniformoutput", false); |
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
12779
diff
changeset
|
373 [files, succ] = cellfun ("urlwrite", urls, local_files, "uniformoutput", false); |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
374 succ = [succ{:}]; |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
375 if (! all (succ)) |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
376 i = find (! succ, 1); |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
377 error ("could not download file %s from url %s", local_files{i}, urls{i}); |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
378 endif |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
379 endif |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
380 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
381 install (files, deps, auto, prefix, archprefix, verbose, local_list, |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
382 global_list, global_install); |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
383 |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
384 unwind_protect_cleanup |
12931
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
12779
diff
changeset
|
385 cellfun ("unlink", local_files); |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
386 end_unwind_protect |
6496 | 387 |
388 case "uninstall" | |
389 if (length (files) == 0) | |
10549 | 390 error ("you must specify at least one package when calling 'pkg uninstall'"); |
6496 | 391 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
392 uninstall (files, deps, verbose, local_list, |
10549 | 393 global_list, global_install); |
6496 | 394 |
395 case "load" | |
396 if (length (files) == 0) | |
10549 | 397 error ("you must specify at least one package, 'all' or 'auto' when calling 'pkg load'"); |
6496 | 398 endif |
399 load_packages (files, deps, local_list, global_list); | |
400 | |
401 case "unload" | |
402 if (length (files) == 0) | |
10549 | 403 error ("you must specify at least one package or 'all' when calling 'pkg unload'"); |
6496 | 404 endif |
405 unload_packages (files, deps, local_list, global_list); | |
406 | |
407 case "prefix" | |
408 if (length (files) == 0 && nargout == 0) | |
10549 | 409 printf ("Installation prefix: %s\n", prefix); |
410 printf ("Architecture dependent prefix: %s\n", archprefix); | |
6925 | 411 elseif (length (files) == 0 && nargout >= 1) |
10549 | 412 local_packages = prefix; |
413 global_packages = archprefix; | |
6925 | 414 elseif (length (files) >= 1 && nargout <= 2 && ischar (files{1})) |
10549 | 415 prefix = files{1}; |
416 prefix = absolute_pathname (prefix); | |
417 local_packages = prefix; | |
418 user_prefix = true; | |
419 if (length (files) >= 2 && ischar (files{2})) | |
420 archprefix = files{2}; | |
421 try | |
422 archprefix = absolute_pathname (archprefix); | |
6925 | 423 catch |
10549 | 424 mkdir (archprefix); |
425 warning ("creating the directory %s\n", archprefix); | |
426 archprefix = absolute_pathname (archprefix); | |
427 end_try_catch | |
428 global_packages = archprefix; | |
429 endif | |
6496 | 430 else |
10549 | 431 error ("you must specify a prefix directory, or request an output argument"); |
6496 | 432 endif |
433 | |
434 case "local_list" | |
435 if (length (files) == 0 && nargout == 0) | |
10549 | 436 disp (local_list); |
6496 | 437 elseif (length (files) == 0 && nargout == 1) |
10549 | 438 local_packages = local_list; |
6496 | 439 elseif (length (files) == 1 && nargout == 0 && ischar (files{1})) |
10549 | 440 try |
441 local_list = absolute_pathname (files{1}); | |
442 catch | |
443 ## Force file to be created | |
444 fclose (fopen (files{1}, "wt")); | |
445 local_list = absolute_pathname (files{1}); | |
446 end_try_catch | |
6496 | 447 else |
10549 | 448 error ("you must specify a local_list file, or request an output argument"); |
6496 | 449 endif |
450 | |
451 case "global_list" | |
452 if (length (files) == 0 && nargout == 0) | |
10549 | 453 disp(global_list); |
6496 | 454 elseif (length (files) == 0 && nargout == 1) |
10549 | 455 local_packages = global_list; |
6496 | 456 elseif (length (files) == 1 && nargout == 0 && ischar (files{1})) |
10549 | 457 try |
458 global_list = absolute_pathname (files{1}); | |
459 catch | |
460 ## Force file to be created | |
461 fclose (fopen (files{1}, "wt")); | |
462 global_list = absolute_pathname (files{1}); | |
463 end_try_catch | |
6496 | 464 else |
10549 | 465 error ("you must specify a global_list file, or request an output argument"); |
6496 | 466 endif |
6645 | 467 |
468 case "rebuild" | |
469 if (global_install) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
470 global_packages = rebuild (prefix, archprefix, global_list, files, |
10549 | 471 auto, verbose); |
472 global_packages = save_order (global_packages); | |
473 save (global_list, "global_packages"); | |
474 if (nargout > 0) | |
475 local_packages = global_packages; | |
476 endif | |
6645 | 477 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
478 local_packages = rebuild (prefix, archprefix, local_list, files, auto, |
10549 | 479 verbose); |
480 local_packages = save_order (local_packages); | |
481 save (local_list, "local_packages"); | |
482 if (nargout == 0) | |
483 clear ("local_packages"); | |
484 endif | |
6645 | 485 endif |
486 | |
6675 | 487 case "build" |
488 if (length (files) < 2) | |
10549 | 489 error ("you must specify at least the build directory and one filename\nwhen calling 'pkg build'"); |
6675 | 490 endif |
491 build (files, deps, auto, verbose); | |
492 | |
7497 | 493 case "describe" |
494 if (length (files) == 0) | |
10549 | 495 error ("you must specify at least one package or 'all' when calling 'pkg describe'"); |
7497 | 496 endif |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8174
diff
changeset
|
497 ## FIXME: the name of the output variables is inconsistent |
7497 | 498 ## with their content |
499 switch (nargout) | |
10549 | 500 case 0 |
501 describe (files, verbose, local_list, global_list); | |
502 case 1 | |
503 pkg_desc_list = describe (files, verbose, local_list, ... | |
504 global_list); | |
505 local_packages = pkg_desc_list; | |
506 case 2 | |
507 [pkg_desc_list, flag] = describe (files, verbose, local_list, ... | |
508 global_list); | |
509 local_packages = pkg_desc_list; | |
510 global_packages = flag; | |
511 otherwise | |
512 error ("you can request at most two outputs when calling 'pkg describe'"); | |
7498 | 513 endswitch |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
514 |
12778
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
515 case "update" |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
516 if (nargout == 0) |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
517 installed_pkgs_lst = installed_packages (local_list, global_list); |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
518 for i = 1:length (installed_pkgs_lst) |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
519 installed_pkg_name = installed_pkgs_lst{i}.name; |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
520 installed_pkg_version = installed_pkgs_lst{i}.version; |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
521 forge_pkg_version = get_forge_pkg (installed_pkg_name); |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
522 if (compare_versions (forge_pkg_version, installed_pkg_version, ">")) |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
523 feval (@pkg, "install", "-forge", installed_pkg_name); |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
524 endif |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
525 endfor |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
526 else |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
527 error ("no output arguments available"); |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
528 endif |
0ca5672d5f1a
Implement pkg update command
Lukas Reichlin <lukas.reichlin@gmail.com>
parents:
12710
diff
changeset
|
529 |
6496 | 530 otherwise |
531 error ("you must specify a valid action for 'pkg'. See 'help pkg' for details"); | |
532 endswitch | |
533 endfunction | |
534 | |
6925 | 535 function descriptions = rebuild (prefix, archprefix, list, files, auto, verbose) |
6645 | 536 if (isempty (files)) |
537 [dirlist, err, msg] = readdir (prefix); | |
538 if (err) | |
539 error ("couldn't read directory %s: %s", prefix, msg); | |
540 endif | |
541 ## the two first entries of dirlist are "." and ".." | |
542 dirlist([1,2]) = []; | |
543 else | |
544 old_descriptions = installed_packages (list, list); | |
545 wd = pwd (); | |
6663 | 546 unwind_protect |
547 cd (prefix); | |
11191
01ddaedd6ad5
Reverse changeset b1f4bdc276b6. Use all lower case for "uniformoutput" option.
Rik <octave@nomad.inbox5.com>
parents:
11190
diff
changeset
|
548 dirlist = glob (cellfun(@(x) cstrcat(x, '-*'), files, 'uniformoutput', 0)); |
6663 | 549 unwind_protect_cleanup |
550 cd (wd); | |
551 end_unwind_protect | |
6645 | 552 endif |
553 descriptions = {}; | |
554 for k = 1:length (dirlist) | |
555 descfile = fullfile (prefix, dirlist{k}, "packinfo", "DESCRIPTION"); | |
556 if (verbose) | |
557 printf ("recreating package description from %s\n", dirlist{k}); | |
558 endif | |
559 if (exist (descfile, "file")) | |
560 desc = get_description (descfile); | |
561 desc.dir = fullfile (prefix, dirlist{k}); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
562 desc.archprefix = fullfile (archprefix, cstrcat (desc.name, "-", |
10549 | 563 desc.version)); |
6645 | 564 if (auto != 0) |
10549 | 565 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file")) |
566 unlink (fullfile (desc.dir, "packinfo", ".autoload")); | |
567 endif | |
6645 | 568 if (auto < 0) |
10549 | 569 desc.autoload = 0; |
570 elseif (auto > 0) | |
571 desc.autoload = 1; | |
572 fclose (fopen (fullfile (desc.dir, "packinfo", ".autoload"), "wt")); | |
573 endif | |
6645 | 574 else |
10549 | 575 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file")) |
576 desc.autoload = 1; | |
577 else | |
578 desc.autoload = 0; | |
579 endif | |
6645 | 580 endif |
581 descriptions{end + 1} = desc; | |
582 elseif (verbose) | |
583 warning ("directory %s is not a valid package", dirlist{k}); | |
584 endif | |
585 endfor | |
586 | |
6663 | 587 if (! isempty (files)) |
6645 | 588 ## We are rebuilding for a particular package(s) so we should take |
589 ## care to keep the other untouched packages in the descriptions | |
6663 | 590 descriptions = {descriptions{:}, old_descriptions{:}}; |
6645 | 591 |
592 dup = []; | |
593 for i = 1:length (descriptions) | |
594 if (find (dup, i)) | |
10549 | 595 continue; |
6645 | 596 endif |
597 for j = (i+1):length (descriptions) | |
10549 | 598 if (find (dup, j)) |
599 continue; | |
600 endif | |
601 if (strcmp (descriptions{i}.name, descriptions{j}.name)) | |
602 dup = [dup, j]; | |
603 endif | |
6645 | 604 endfor |
605 endfor | |
606 if (! isempty (dup)) | |
607 descriptions (dup) = []; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
608 endif |
6645 | 609 endif |
610 endfunction | |
611 | |
6675 | 612 function build (files, handle_deps, autoload, verbose) |
613 if (length (files) < 1) | |
614 error ("insufficient number of files"); | |
615 endif | |
616 builddir = files{1}; | |
617 if (! exist (builddir, "dir")) | |
618 warning ("creating build directory %s", builddir); | |
619 [status, msg] = mkdir (builddir); | |
620 if (status != 1) | |
621 error ("could not create installation directory: %s", msg); | |
622 endif | |
6496 | 623 endif |
6675 | 624 builddir = absolute_pathname (builddir); |
625 installdir = fullfile (builddir, "install"); | |
626 if (! exist (installdir, "dir")) | |
627 [status, msg] = mkdir (installdir); | |
628 if (status != 1) | |
629 error ("could not create installation directory: %s", msg); | |
630 endif | |
631 endif | |
632 files(1) = []; | |
633 buildlist = fullfile (builddir, "octave_packages"); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
634 install (files, handle_deps, autoload, installdir, installdir, verbose, |
10549 | 635 buildlist, "", false); |
6675 | 636 unwind_protect |
637 repackage (builddir, buildlist); | |
638 unwind_protect_cleanup | |
639 unload_packages ({"all"}, handle_deps, buildlist, ""); | |
640 if (exist (installdir, "dir")) | |
641 rm_rf (installdir); | |
642 endif | |
643 if (exist (buildlist, "file")) | |
644 unlink (buildlist); | |
645 endif | |
646 end_unwind_protect | |
5801 | 647 endfunction |
648 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
649 function install (files, handle_deps, autoload, prefix, archprefix, verbose, |
10549 | 650 local_list, global_list, global_install) |
6496 | 651 |
8506 | 652 ## Check that the directory in prefix exist. If it doesn't: create it! |
6496 | 653 if (! exist (prefix, "dir")) |
654 warning ("creating installation directory %s", prefix); | |
655 [status, msg] = mkdir (prefix); | |
656 if (status != 1) | |
657 error ("could not create installation directory: %s", msg); | |
658 endif | |
659 endif | |
660 | |
8506 | 661 ## Get the list of installed packages. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
662 [local_packages, global_packages] = installed_packages (local_list, |
10549 | 663 global_list); |
6496 | 664 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
665 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 666 |
667 if (global_install) | |
668 packages = global_packages; | |
669 else | |
670 packages = local_packages; | |
671 endif | |
672 | |
8506 | 673 ## Uncompress the packages and read the DESCRIPTION files. |
6496 | 674 tmpdirs = packdirs = descriptions = {}; |
675 try | |
8506 | 676 ## Warn about non existent files. |
6683 | 677 for i = 1:length (files) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
678 if (isempty (glob(files{i}))) |
10549 | 679 warning ("file %s does not exist", files{i}); |
6683 | 680 endif |
681 endfor | |
682 | |
8506 | 683 ## Unpack the package files and read the DESCRIPTION files. |
6496 | 684 files = glob (files); |
685 packages_to_uninstall = []; | |
686 for i = 1:length (files) | |
687 tgz = files{i}; | |
688 | |
6645 | 689 if (exist (tgz, "file")) |
10549 | 690 ## Create a temporary directory. |
691 tmpdir = tmpnam (); | |
692 tmpdirs{end+1} = tmpdir; | |
6645 | 693 if (verbose) |
10549 | 694 printf ("mkdir (%s)\n", tmpdir); |
695 endif | |
696 [status, msg] = mkdir (tmpdir); | |
697 if (status != 1) | |
698 error ("couldn't create temporary directory: %s", msg); | |
699 endif | |
6496 | 700 |
10549 | 701 ## Uncompress the package. |
702 if (verbose) | |
703 printf ("untar (%s, %s)\n", tgz, tmpdir); | |
704 endif | |
705 untar (tgz, tmpdir); | |
6496 | 706 |
10549 | 707 ## Get the name of the directories produced by tar. |
708 [dirlist, err, msg] = readdir (tmpdir); | |
709 if (err) | |
710 error ("couldn't read directory produced by tar: %s", msg); | |
711 endif | |
6496 | 712 |
10549 | 713 if (length (dirlist) > 3) |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11588
diff
changeset
|
714 error ("bundles of packages are not allowed"); |
10549 | 715 endif |
7632
d6e63a15cc75
Allow installation of already extracted packages
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
7548
diff
changeset
|
716 endif |
6496 | 717 |
8506 | 718 ## The filename pointed to an uncompressed package to begin with. |
7632
d6e63a15cc75
Allow installation of already extracted packages
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
7548
diff
changeset
|
719 if (exist (tgz, "dir")) |
10549 | 720 dirlist = {".", "..", tgz}; |
7632
d6e63a15cc75
Allow installation of already extracted packages
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
7548
diff
changeset
|
721 endif |
6645 | 722 |
7632
d6e63a15cc75
Allow installation of already extracted packages
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
7548
diff
changeset
|
723 if (exist (tgz, "file") || exist (tgz, "dir")) |
10549 | 724 ## The two first entries of dirlist are "." and "..". |
725 if (exist (tgz, "file")) | |
726 packdir = fullfile (tmpdir, dirlist{3}); | |
727 else | |
728 packdir = fullfile (pwd(), dirlist{3}); | |
729 endif | |
730 packdirs{end+1} = packdir; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
731 |
10549 | 732 ## Make sure the package contains necessary files. |
733 verify_directory (packdir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
734 |
10549 | 735 ## Read the DESCRIPTION file. |
736 filename = fullfile (packdir, "DESCRIPTION"); | |
737 desc = get_description (filename); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
738 |
10549 | 739 ## Verify that package name corresponds with filename. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
740 [dummy, nm] = fileparts (tgz); |
10549 | 741 if ((length (nm) >= length (desc.name)) |
742 && ! strcmp (desc.name, nm(1:length(desc.name)))) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
743 error ("package name '%s' doesn't correspond to its filename '%s'", |
10549 | 744 desc.name, nm); |
745 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
746 |
10549 | 747 ## Set default installation directory. |
748 desc.dir = fullfile (prefix, cstrcat (desc.name, "-", desc.version)); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
749 |
10549 | 750 ## Set default architectire dependent installation directory. |
751 desc.archprefix = fullfile (archprefix, cstrcat (desc.name, "-", | |
752 desc.version)); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
753 |
10549 | 754 ## Save desc. |
755 descriptions{end+1} = desc; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
756 |
10549 | 757 ## Are any of the new packages already installed? |
758 ## If so we'll remove the old version. | |
759 for j = 1:length (packages) | |
760 if (strcmp (packages{j}.name, desc.name)) | |
761 packages_to_uninstall(end+1) = j; | |
762 endif | |
763 endfor | |
6645 | 764 endif |
6496 | 765 endfor |
766 catch | |
8506 | 767 ## Something went wrong, delete tmpdirs. |
6496 | 768 for i = 1:length (tmpdirs) |
769 rm_rf (tmpdirs{i}); | |
770 endfor | |
6655 | 771 rethrow (lasterror ()); |
6496 | 772 end_try_catch |
773 | |
8506 | 774 ## Check dependencies. |
6496 | 775 if (handle_deps) |
776 ok = true; | |
777 error_text = ""; | |
778 for i = 1:length (descriptions) | |
779 desc = descriptions{i}; | |
10196
69bb6e1e10d2
complement->setdiff in pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
780 idx2 = setdiff (1:length(descriptions), i); |
6695 | 781 if (global_install) |
10549 | 782 ## Global installation is not allowed to have dependencies on locally |
783 ## installed packages. | |
784 idx1 = setdiff (1:length(global_packages), packages_to_uninstall); | |
785 pseudo_installed_packages = {global_packages{idx1}, ... | |
786 descriptions{idx2}}; | |
6695 | 787 else |
10549 | 788 idx1 = setdiff (1:length(local_packages), packages_to_uninstall); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
789 pseudo_installed_packages = {local_packages{idx1}, ... |
10549 | 790 global_packages{:}, ... |
791 descriptions{idx2}}; | |
6695 | 792 endif |
6496 | 793 bad_deps = get_unsatisfied_deps (desc, pseudo_installed_packages); |
794 ## Are there any unsatisfied dependencies? | |
795 if (! isempty (bad_deps)) | |
10549 | 796 ok = false; |
797 for i = 1:length (bad_deps) | |
798 dep = bad_deps{i}; | |
799 error_text = cstrcat (error_text, " ", desc.name, " needs ", | |
800 dep.package, " ", dep.operator, " ", | |
801 dep.version, "\n"); | |
802 endfor | |
6496 | 803 endif |
804 endfor | |
805 | |
806 ## Did we find any unsatisfied dependencies? | |
807 if (! ok) | |
808 error ("the following dependencies where unsatisfied:\n %s", error_text); | |
809 endif | |
810 endif | |
811 | |
8506 | 812 ## Prepare each package for installation. |
6496 | 813 try |
814 for i = 1:length (descriptions) | |
815 desc = descriptions{i}; | |
816 pdir = packdirs{i}; | |
817 prepare_installation (desc, pdir); | |
6614 | 818 configure_make (desc, pdir, verbose); |
6496 | 819 endfor |
820 catch | |
8506 | 821 ## Something went wrong, delete tmpdirs. |
6496 | 822 for i = 1:length (tmpdirs) |
823 rm_rf (tmpdirs{i}); | |
824 endfor | |
6655 | 825 rethrow (lasterror ()); |
6496 | 826 end_try_catch |
827 | |
8506 | 828 ## Uninstall the packages that will be replaced. |
6496 | 829 try |
830 for i = packages_to_uninstall | |
6695 | 831 if (global_install) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
832 uninstall ({global_packages{i}.name}, false, verbose, local_list, |
10549 | 833 global_list, global_install); |
6695 | 834 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
835 uninstall ({local_packages{i}.name}, false, verbose, local_list, |
10549 | 836 global_list, global_install); |
6695 | 837 endif |
6496 | 838 endfor |
839 catch | |
8506 | 840 ## Something went wrong, delete tmpdirs. |
6496 | 841 for i = 1:length (tmpdirs) |
842 rm_rf (tmpdirs{i}); | |
843 endfor | |
6655 | 844 rethrow (lasterror ()); |
6496 | 845 end_try_catch |
846 | |
8506 | 847 ## Install each package. |
6496 | 848 try |
849 for i = 1:length (descriptions) | |
850 desc = descriptions{i}; | |
851 pdir = packdirs{i}; | |
6925 | 852 copy_files (desc, pdir, global_install); |
853 create_pkgadddel (desc, pdir, "PKG_ADD", global_install); | |
854 create_pkgadddel (desc, pdir, "PKG_DEL", global_install); | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
855 finish_installation (desc, pdir, global_install); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
856 generate_lookfor_cache (desc); |
6496 | 857 endfor |
858 catch | |
8506 | 859 ## Something went wrong, delete tmpdirs. |
6496 | 860 for i = 1:length (tmpdirs) |
861 rm_rf (tmpdirs{i}); | |
862 endfor | |
863 for i = 1:length (descriptions) | |
864 rm_rf (descriptions{i}.dir); | |
6925 | 865 rm_rf (getarchdir (descriptions{i})); |
6496 | 866 endfor |
6655 | 867 rethrow (lasterror ()); |
6496 | 868 end_try_catch |
869 | |
870 ## Check if the installed directory is empty. If it is remove it | |
8506 | 871 ## from the list. |
6496 | 872 for i = length (descriptions):-1:1 |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
873 if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
874 && dirempty (getarchdir (descriptions{i}))) |
6655 | 875 warning ("package %s is empty\n", descriptions{i}.name); |
6496 | 876 rm_rf (descriptions{i}.dir); |
6925 | 877 rm_rf (getarchdir (descriptions{i})); |
6496 | 878 descriptions(i) = []; |
879 endif | |
880 endfor | |
881 | |
882 ## If the package requested that it is autoloaded, or the installer | |
883 ## requested that it is, then mark the package as autoloaded. | |
884 for i = length (descriptions):-1:1 | |
885 if (autoload > 0 || (autoload == 0 && isautoload (descriptions(i)))) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
886 fclose (fopen (fullfile (descriptions{i}.dir, "packinfo", |
10549 | 887 ".autoload"), "wt")); |
6695 | 888 descriptions{i}.autoload = 1; |
6496 | 889 endif |
890 endfor | |
891 | |
8506 | 892 ## Add the packages to the package list. |
6496 | 893 try |
894 if (global_install) | |
10196
69bb6e1e10d2
complement->setdiff in pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
895 idx = setdiff (1:length(global_packages), packages_to_uninstall); |
6695 | 896 global_packages = save_order ({global_packages{idx}, descriptions{:}}); |
6496 | 897 save (global_list, "global_packages"); |
6820 | 898 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 899 else |
10196
69bb6e1e10d2
complement->setdiff in pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
900 idx = setdiff (1:length(local_packages), packages_to_uninstall); |
6695 | 901 local_packages = save_order ({local_packages{idx}, descriptions{:}}); |
6496 | 902 save (local_list, "local_packages"); |
6820 | 903 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 904 endif |
905 catch | |
8506 | 906 ## Something went wrong, delete tmpdirs. |
6496 | 907 for i = 1:length (tmpdirs) |
908 rm_rf (tmpdirs{i}); | |
909 endfor | |
910 for i = 1:length (descriptions) | |
911 rm_rf (descriptions{i}.dir); | |
912 endfor | |
913 if (global_install) | |
6695 | 914 printf ("error: couldn't append to %s\n", global_list); |
6496 | 915 else |
6695 | 916 printf ("error: couldn't append to %s\n", local_list); |
6496 | 917 endif |
6695 | 918 rethrow (lasterror ()); |
6496 | 919 end_try_catch |
920 | |
8506 | 921 ## All is well, let's clean up. |
6496 | 922 for i = 1:length (tmpdirs) |
923 [status, msg] = rm_rf (tmpdirs{i}); | |
924 if (status != 1) | |
925 warning ("couldn't clean up after my self: %s\n", msg); | |
926 endif | |
927 endfor | |
928 | |
929 ## Add the newly installed packages to the path, so the user | |
8506 | 930 ## can begin using them. Only load them if they are marked autoload. |
6496 | 931 if (length (descriptions) > 0) |
6695 | 932 idx = []; |
6496 | 933 for i = 1:length (descriptions) |
6695 | 934 if (isautoload (descriptions(i))) |
10549 | 935 nm = descriptions{i}.name; |
936 for j = 1:length (installed_pkgs_lst) | |
937 if (strcmp (nm, installed_pkgs_lst{j}.name)) | |
938 idx (end + 1) = j; | |
939 break; | |
940 endif | |
941 endfor | |
6614 | 942 endif |
6496 | 943 endfor |
6925 | 944 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, |
10549 | 945 global_install); |
6496 | 946 endif |
947 endfunction | |
948 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
949 function uninstall (pkgnames, handle_deps, verbose, local_list, |
10549 | 950 global_list, global_install) |
8506 | 951 ## Get the list of installed packages. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
952 [local_packages, global_packages] = installed_packages(local_list, |
10549 | 953 global_list); |
6645 | 954 if (global_install) |
6820 | 955 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 956 else |
6820 | 957 installed_pkgs_lst = local_packages; |
6496 | 958 endif |
959 | |
6820 | 960 num_packages = length (installed_pkgs_lst); |
6496 | 961 delete_idx = []; |
962 for i = 1:num_packages | |
6820 | 963 cur_name = installed_pkgs_lst{i}.name; |
6496 | 964 if (any (strcmp (cur_name, pkgnames))) |
965 delete_idx(end+1) = i; | |
966 endif | |
967 endfor | |
968 | |
969 ## Are all the packages that should be uninstalled already installed? | |
970 if (length (delete_idx) != length (pkgnames)) | |
6645 | 971 if (global_install) |
8506 | 972 ## Try again for a locally installed package. |
6820 | 973 installed_pkgs_lst = local_packages; |
6496 | 974 |
6820 | 975 num_packages = length (installed_pkgs_lst); |
6496 | 976 delete_idx = []; |
977 for i = 1:num_packages | |
10549 | 978 cur_name = installed_pkgs_lst{i}.name; |
979 if (any (strcmp (cur_name, pkgnames))) | |
980 delete_idx(end+1) = i; | |
981 endif | |
6496 | 982 endfor |
983 if (length (delete_idx) != length (pkgnames)) | |
10549 | 984 ## FIXME: We should have a better error message. |
985 warning ("some of the packages you want to uninstall are not installed"); | |
6496 | 986 endif |
987 else | |
8506 | 988 ## FIXME: We should have a better error message. |
8664 | 989 warning ("some of the packages you want to uninstall are not installed"); |
6496 | 990 endif |
991 endif | |
992 | |
8506 | 993 ## Compute the packages that will remain installed. |
10196
69bb6e1e10d2
complement->setdiff in pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
994 idx = setdiff (1:num_packages, delete_idx); |
6820 | 995 remaining_packages = {installed_pkgs_lst{idx}}; |
6496 | 996 |
8506 | 997 ## Check dependencies. |
6496 | 998 if (handle_deps) |
999 error_text = ""; | |
1000 for i = 1:length (remaining_packages) | |
1001 desc = remaining_packages{i}; | |
1002 bad_deps = get_unsatisfied_deps (desc, remaining_packages); | |
1003 | |
1004 ## Will the uninstallation break any dependencies? | |
1005 if (! isempty (bad_deps)) | |
10549 | 1006 for i = 1:length (bad_deps) |
1007 dep = bad_deps{i}; | |
1008 error_text = cstrcat (error_text, " ", desc.name, " needs ", | |
1009 dep.package, " ", dep.operator, " ", | |
1010 dep.version, "\n"); | |
1011 endfor | |
6496 | 1012 endif |
1013 endfor | |
1014 | |
1015 if (! isempty (error_text)) | |
1016 error ("the following dependencies where unsatisfied:\n %s", error_text); | |
1017 endif | |
1018 endif | |
1019 | |
8506 | 1020 ## Delete the directories containing the packages. |
6496 | 1021 for i = delete_idx |
6820 | 1022 desc = installed_pkgs_lst{i}; |
6496 | 1023 ## If an 'on_uninstall.m' exist, call it! |
1024 if (exist (fullfile (desc.dir, "packinfo", "on_uninstall.m"), "file")) | |
6614 | 1025 wd = pwd (); |
7498 | 1026 cd (fullfile (desc.dir, "packinfo")); |
6614 | 1027 on_uninstall (desc); |
1028 cd (wd); | |
6496 | 1029 endif |
8506 | 1030 ## Do the actual deletion. |
6675 | 1031 if (desc.loaded) |
1032 rmpath (desc.dir); | |
6925 | 1033 if (exist (getarchdir (desc))) |
10549 | 1034 rmpath (getarchdir (desc)); |
6675 | 1035 endif |
6614 | 1036 endif |
6496 | 1037 if (exist (desc.dir, "dir")) |
1038 [status, msg] = rm_rf (desc.dir); | |
1039 if (status != 1) | |
10549 | 1040 error ("couldn't delete directory %s: %s", desc.dir, msg); |
6496 | 1041 endif |
6925 | 1042 [status, msg] = rm_rf (getarchdir (desc)); |
1043 if (status != 1) | |
10549 | 1044 error ("couldn't delete directory %s: %s", getarchdir (desc), msg); |
6925 | 1045 endif |
1046 if (dirempty (desc.archprefix)) | |
10549 | 1047 rm_rf (desc.archprefix); |
6925 | 1048 endif |
6496 | 1049 else |
1050 warning ("directory %s previously lost", desc.dir); | |
1051 endif | |
1052 endfor | |
1053 | |
8506 | 1054 ## Write a new ~/.octave_packages. |
6645 | 1055 if (global_install) |
6496 | 1056 if (length (remaining_packages) == 0) |
1057 unlink (global_list); | |
1058 else | |
6695 | 1059 global_packages = save_order (remaining_packages); |
6496 | 1060 save (global_list, "global_packages"); |
1061 endif | |
1062 else | |
1063 if (length (remaining_packages) == 0) | |
1064 unlink (local_list); | |
1065 else | |
6695 | 1066 local_packages = save_order (remaining_packages); |
6496 | 1067 save (local_list, "local_packages"); |
1068 endif | |
1069 endif | |
1070 | |
1071 endfunction | |
1072 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1073 function [pkg_desc_list, flag] = describe (pkgnames, verbose, |
10549 | 1074 local_list, global_list) |
7497 | 1075 |
8506 | 1076 ## Get the list of installed packages. |
7497 | 1077 installed_pkgs_lst = installed_packages(local_list, global_list); |
7498 | 1078 num_packages = length (installed_pkgs_lst); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1079 |
7497 | 1080 |
7498 | 1081 describe_all = false; |
1082 if (any (strcmp ("all", pkgnames))) | |
1083 describe_all = true; | |
8455
fd11a08a9b31
disallow invalid {}-indexed assigments
Jaroslav Hajek <highegg@gmail.com>
parents:
8202
diff
changeset
|
1084 flag(1:num_packages) = {"Not Loaded"}; |
7498 | 1085 num_pkgnames = num_packages; |
7497 | 1086 else |
7498 | 1087 num_pkgnames = length (pkgnames); |
8455
fd11a08a9b31
disallow invalid {}-indexed assigments
Jaroslav Hajek <highegg@gmail.com>
parents:
8202
diff
changeset
|
1088 flag(1:num_pkgnames) = {"Not installed"}; |
7498 | 1089 endif |
7497 | 1090 |
1091 for i = 1:num_packages | |
8507 | 1092 curr_name = installed_pkgs_lst{i}.name; |
7497 | 1093 if (describe_all) |
1094 name_pos = i; | |
1095 else | |
1096 name_pos = find(strcmp (curr_name, pkgnames)); | |
7498 | 1097 endif |
1098 | |
1099 if (! isempty (name_pos)) | |
7497 | 1100 if (installed_pkgs_lst{i}.loaded) |
10549 | 1101 flag{name_pos} = "Loaded"; |
7497 | 1102 else |
10549 | 1103 flag{name_pos} = "Not loaded"; |
7497 | 1104 endif |
1105 | |
7498 | 1106 pkg_desc_list{name_pos}.name = installed_pkgs_lst{i}.name; |
9258
a653c61ee98c
let pkg describe return version information
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9220
diff
changeset
|
1107 pkg_desc_list{name_pos}.version = installed_pkgs_lst{i}.version; |
7498 | 1108 pkg_desc_list{name_pos}.description = installed_pkgs_lst{i}.description; |
1109 pkg_desc_list{name_pos}.provides = parse_pkg_idx (installed_pkgs_lst{i}.dir); | |
7497 | 1110 |
1111 endif | |
1112 endfor | |
1113 | |
7498 | 1114 non_inst = find (strcmp (flag, "Not installed")); |
9220
70177bf9cc16
Fix bug when calling pkg describe to check whether a package is installed
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9153
diff
changeset
|
1115 if (! isempty (non_inst)) |
70177bf9cc16
Fix bug when calling pkg describe to check whether a package is installed
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9153
diff
changeset
|
1116 if (nargout < 2) |
70177bf9cc16
Fix bug when calling pkg describe to check whether a package is installed
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9153
diff
changeset
|
1117 non_inst_str = sprintf (" %s ", pkgnames{non_inst}); |
70177bf9cc16
Fix bug when calling pkg describe to check whether a package is installed
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9153
diff
changeset
|
1118 error ("some packages are not installed: %s", non_inst_str); |
70177bf9cc16
Fix bug when calling pkg describe to check whether a package is installed
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9153
diff
changeset
|
1119 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1120 pkg_desc_list{non_inst} = struct ("name", {}, "description", |
10549 | 1121 {}, "provides", {}); |
9220
70177bf9cc16
Fix bug when calling pkg describe to check whether a package is installed
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9153
diff
changeset
|
1122 endif |
7497 | 1123 endif |
1124 | |
1125 if (nargout == 0) | |
7498 | 1126 for i = 1:num_pkgnames |
9258
a653c61ee98c
let pkg describe return version information
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9220
diff
changeset
|
1127 print_package_description (pkg_desc_list{i}.name, |
10549 | 1128 pkg_desc_list{i}.version, |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1129 pkg_desc_list{i}.provides, |
10549 | 1130 pkg_desc_list{i}.description, |
1131 flag{i}, verbose); | |
7497 | 1132 endfor |
1133 endif | |
1134 | |
1135 endfunction | |
1136 | |
8506 | 1137 ## AUXILIARY FUNCTIONS |
6496 | 1138 |
8506 | 1139 ## Read an INDEX file. |
7498 | 1140 function [pkg_idx_struct] = parse_pkg_idx (packdir) |
7497 | 1141 |
7498 | 1142 index_file = fullfile (packdir, "packinfo", "INDEX"); |
1143 | |
1144 if (! exist (index_file, "file")) | |
1145 error ("could not find any INDEX file in directory %s, try 'pkg rebuild all' to generate missing INDEX files", packdir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1146 endif |
7497 | 1147 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1148 |
7498 | 1149 [fid, msg] = fopen (index_file, "r"); |
7497 | 1150 if (fid == -1) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1151 error ("the INDEX file %s could not be read: %s", |
10549 | 1152 index_file, msg); |
7497 | 1153 endif |
7498 | 1154 |
7497 | 1155 cat_num = 1; |
1156 pkg_idx_struct{1}.category = "Uncategorized"; | |
1157 pkg_idx_struct{1}.functions = {}; | |
1158 | |
7498 | 1159 line = fgetl (fid); |
1160 while (isempty (strfind (line, ">>")) && ! feof (fid)) | |
1161 line = fgetl (fid); | |
7497 | 1162 endwhile |
1163 | |
7498 | 1164 while (! feof (fid) || line != -1) |
1165 if (! any (! isspace (line)) || line(1) == "#" || any (line == "=")) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1166 ## Comments, blank lines or comments about unimplemented |
7497 | 1167 ## functions: do nothing |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8174
diff
changeset
|
1168 ## FIXME: probably comments and pointers to external functions |
7497 | 1169 ## could be treated better when printing to screen? |
7498 | 1170 elseif (! isempty (strfind (line, ">>"))) |
8506 | 1171 ## Skip package name and description as they are in DESCRIPTION |
1172 ## already. | |
7498 | 1173 elseif (! isspace (line(1))) |
8506 | 1174 ## Category. |
7498 | 1175 if (! isempty (pkg_idx_struct{cat_num}.functions)) |
10549 | 1176 pkg_idx_struct{++cat_num}.functions = {}; |
7497 | 1177 endif |
7498 | 1178 pkg_idx_struct{cat_num}.category = deblank (line); |
7497 | 1179 else |
8506 | 1180 ## Function names. |
7498 | 1181 while (any (! isspace (line))) |
10549 | 1182 [fun_name, line] = strtok (line); |
1183 pkg_idx_struct{cat_num}.functions{end+1} = deblank (fun_name); | |
7497 | 1184 endwhile |
1185 endif | |
7498 | 1186 line = fgetl (fid); |
7497 | 1187 endwhile |
1188 fclose (fid); | |
1189 endfunction | |
1190 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1191 function print_package_description (pkg_name, pkg_ver, pkg_idx_struct, |
10549 | 1192 pkg_desc, status, verbose) |
7497 | 1193 |
7498 | 1194 printf ("---\nPackage name:\n\t%s\n", pkg_name); |
9258
a653c61ee98c
let pkg describe return version information
Carlo de Falco <kingcrimson@tiscali.it>
parents:
9220
diff
changeset
|
1195 printf ("Version:\n\t%s\n", pkg_ver); |
7498 | 1196 printf ("Short description:\n\t%s\n", pkg_desc); |
1197 printf ("Status:\n\t%s\n", status); | |
7497 | 1198 if (verbose) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1199 printf ("---\nProvides:\n"); |
7498 | 1200 for i = 1:length(pkg_idx_struct) |
1201 if (! isempty (pkg_idx_struct{i}.functions)) | |
10549 | 1202 printf ("%s\n", pkg_idx_struct{i}.category); |
1203 for j = 1:length(pkg_idx_struct{i}.functions) | |
1204 printf ("\t%s\n", pkg_idx_struct{i}.functions{j}); | |
1205 endfor | |
7497 | 1206 endif |
1207 endfor | |
1208 endif | |
1209 | |
1210 endfunction | |
1211 | |
1212 | |
6675 | 1213 function pth = absolute_pathname (pth) |
7498 | 1214 [status, msg, msgid] = fileattrib (pth); |
6729 | 1215 if (status != 1) |
1216 error ("could not find the file or path %s", pth); | |
1217 else | |
1218 pth = msg.Name; | |
1219 endif | |
6675 | 1220 endfunction |
1221 | |
1222 function repackage (builddir, buildlist) | |
1223 packages = installed_packages (buildlist, buildlist); | |
1224 | |
1225 wd = pwd(); | |
1226 for i = 1 : length(packages) | |
1227 pack = packages{i}; | |
1228 unwind_protect | |
1229 cd (builddir); | |
1230 mkdir (pack.name); | |
1231 mkdir (fullfile (pack.name, "inst")); | |
1232 copyfile (fullfile (pack.dir, "*"), fullfile (pack.name, "inst")); | |
1233 movefile (fullfile (pack.name, "inst","packinfo", "*"), pack.name); | |
1234 if (exist (fullfile (pack.name, "inst","packinfo", ".autoload"), "file")) | |
10549 | 1235 unlink (fullfile (pack.name, "inst","packinfo", ".autoload")); |
6675 | 1236 endif |
1237 rmdir (fullfile (pack.name, "inst", "packinfo")); | |
1238 if (exist (fullfile (pack.name, "inst", "doc"), "dir")) | |
10549 | 1239 movefile (fullfile (pack.name, "inst", "doc"), pack.name); |
6675 | 1240 endif |
1241 if (exist (fullfile (pack.name, "inst", "bin"), "dir")) | |
10549 | 1242 movefile (fullfile (pack.name, "inst", "bin"), pack.name); |
6675 | 1243 endif |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1244 archdir = fullfile (pack.archprefix, cstrcat (pack.name, "-", |
10549 | 1245 pack.version), getarch ()); |
6675 | 1246 if (exist (archdir, "dir")) |
10549 | 1247 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file")) |
1248 unlink (fullfile (pack.name, "inst", "PKG_ADD")); | |
1249 endif | |
1250 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file")) | |
1251 unlink (fullfile (pack.name, "inst", "PKG_DEL")); | |
1252 endif | |
1253 if (exist (fullfile (archdir, "PKG_ADD"), "file")) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1254 movefile (fullfile (archdir, "PKG_ADD"), |
10549 | 1255 fullfile (pack.name, "PKG_ADD")); |
1256 endif | |
1257 if (exist (fullfile (archdir, "PKG_DEL"), "file")) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1258 movefile (fullfile (archdir, "PKG_DEL"), |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1259 fullfile (pack.name, "PKG_DEL")); |
10549 | 1260 endif |
6675 | 1261 else |
10549 | 1262 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file")) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1263 movefile (fullfile (pack.name, "inst", "PKG_ADD"), |
10549 | 1264 fullfile (pack.name, "PKG_ADD")); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1265 endif |
10549 | 1266 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file")) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1267 movefile (fullfile (pack.name, "inst", "PKG_DEL"), |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1268 fullfile (pack.name, "PKG_DEL")); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1269 endif |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1270 endif |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1271 tfile = cstrcat (pack.name, "-", pack.version, ".tar"); |
6675 | 1272 tar (tfile, pack.name); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1273 try |
10549 | 1274 gzip (tfile); |
1275 unlink (tfile); | |
6925 | 1276 catch |
10549 | 1277 warning ("failed to compress %s", tfile); |
6925 | 1278 end_try_catch |
6675 | 1279 unwind_protect_cleanup |
1280 if (exist (pack.name, "dir")) | |
10549 | 1281 rm_rf (pack.name); |
6675 | 1282 endif |
1283 cd (wd); | |
1284 end_unwind_protect | |
1285 endfor | |
1286 endfunction | |
1287 | |
1288 function auto = isautoload (desc) | |
6695 | 1289 auto = false; |
1290 if (isfield (desc{1}, "autoload")) | |
1291 a = desc{1}.autoload; | |
1292 if ((isnumeric (a) && a > 0) | |
1293 || (ischar (a) && (strcmpi (a, "true") | |
10549 | 1294 || strcmpi (a, "on") |
1295 || strcmpi (a, "yes") | |
1296 || strcmpi (a, "1")))) | |
6695 | 1297 auto = true; |
1298 endif | |
6675 | 1299 endif |
1300 endfunction | |
1301 | |
6496 | 1302 function prepare_installation (desc, packdir) |
1303 ## Is there a pre_install to call? | |
1304 if (exist (fullfile (packdir, "pre_install.m"), "file")) | |
1305 wd = pwd (); | |
1306 try | |
1307 cd (packdir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1308 pre_install (desc); |
6496 | 1309 cd (wd); |
1310 catch | |
1311 cd (wd); | |
6695 | 1312 rethrow (lasterror ()); |
6496 | 1313 end_try_catch |
1314 endif | |
1315 | |
8506 | 1316 ## If the directory "inst" doesn't exist, we create it. |
6496 | 1317 inst_dir = fullfile (packdir, "inst"); |
1318 if (! exist (inst_dir, "dir")) | |
1319 [status, msg] = mkdir (inst_dir); | |
1320 if (status != 1) | |
1321 rm_rf (desc.dir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1322 error ("the 'inst' directory did not exist and could not be created: %s", |
10549 | 1323 msg); |
6258 | 1324 endif |
1325 endif | |
1326 endfunction | |
1327 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1328 function configure_make (desc, packdir, verbose) |
8506 | 1329 ## Perform ./configure, make, make install in "src". |
6496 | 1330 if (exist (fullfile (packdir, "src"), "dir")) |
1331 src = fullfile (packdir, "src"); | |
12167
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1332 octave_bindir = octave_config_info ("bindir"); |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1333 ver = version (); |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1334 mkoctfile = fullfile (octave_bindir, sprintf ("mkoctfile-%s", ver)); |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1335 octave_config = fullfile (octave_bindir, sprintf ("octave-config-%s", ver)); |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1336 octave_binary = fullfile (octave_bindir, sprintf ("octave-%s", ver)); |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1337 cenv = {"MKOCTFILE"; mkoctfile; |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1338 "OCTAVE_CONFIG"; octave_config; |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1339 "OCTAVE"; octave_binary; |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1340 "INSTALLDIR"; desc.dir}; |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1341 scenv = sprintf ("%s=\"%s\" ", cenv{:}); |
8506 | 1342 ## Configure. |
6496 | 1343 if (exist (fullfile (src, "configure"), "file")) |
7111 | 1344 flags = ""; |
1345 if (isempty (getenv ("CC"))) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1346 flags = cstrcat (flags, " CC=\"", octave_config_info ("CC"), "\""); |
7111 | 1347 endif |
1348 if (isempty (getenv ("CXX"))) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1349 flags = cstrcat (flags, " CXX=\"", octave_config_info ("CXX"), "\""); |
7111 | 1350 endif |
1351 if (isempty (getenv ("AR"))) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1352 flags = cstrcat (flags, " AR=\"", octave_config_info ("AR"), "\""); |
7111 | 1353 endif |
1354 if (isempty (getenv ("RANLIB"))) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1355 flags = cstrcat (flags, " RANLIB=\"", octave_config_info ("RANLIB"), "\""); |
7111 | 1356 endif |
12167
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1357 [status, output] = shell (cstrcat ("cd '", src, "'; ", scenv, |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1358 "./configure --prefix=\"", |
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1359 desc.dir, "\"", flags)); |
6496 | 1360 if (status != 0) |
10549 | 1361 rm_rf (desc.dir); |
1362 error ("the configure script returned the following error: %s", output); | |
6675 | 1363 elseif (verbose) |
10549 | 1364 printf("%s", output); |
6496 | 1365 endif |
6675 | 1366 |
5801 | 1367 endif |
1368 | |
8506 | 1369 ## Make. |
6496 | 1370 if (exist (fullfile (src, "Makefile"), "file")) |
12167
ad636c1f353b
Let pkg.m export environment variables MKOCTFILE, OCTAVE_CONFIG and OCTAVE.
Olaf Till <olaf.till@uni-jena.de>
parents:
11589
diff
changeset
|
1371 [status, output] = shell (cstrcat (scenv, "make -C '", src, "'")); |
6496 | 1372 if (status != 0) |
10549 | 1373 rm_rf (desc.dir); |
1374 error ("'make' returned the following error: %s", output); | |
6675 | 1375 elseif (verbose) |
10549 | 1376 printf("%s", output); |
6496 | 1377 endif |
5801 | 1378 endif |
1379 | |
8506 | 1380 ## Copy files to "inst" and "inst/arch" (this is instead of 'make |
1381 ## install'). | |
6496 | 1382 files = fullfile (src, "FILES"); |
1383 instdir = fullfile (packdir, "inst"); | |
6614 | 1384 archdir = fullfile (packdir, "inst", getarch ()); |
6950 | 1385 |
8506 | 1386 ## Get file names. |
6496 | 1387 if (exist (files, "file")) |
1388 [fid, msg] = fopen (files, "r"); | |
1389 if (fid < 0) | |
10549 | 1390 error ("couldn't open %s: %s", files, msg); |
5971 | 1391 endif |
6496 | 1392 filenames = char (fread (fid))'; |
1393 fclose (fid); | |
1394 if (filenames(end) == "\n") | |
10549 | 1395 filenames(end) = []; |
6258 | 1396 endif |
6655 | 1397 filenames = split_by (filenames, "\n"); |
6496 | 1398 delete_idx = []; |
6655 | 1399 for i = 1:length (filenames) |
10549 | 1400 if (! all (isspace (filenames{i}))) |
1401 filenames{i} = fullfile (src, filenames{i}); | |
1402 else | |
1403 delete_idx(end+1) = i; | |
1404 endif | |
5971 | 1405 endfor |
6655 | 1406 filenames(delete_idx) = []; |
6496 | 1407 else |
1408 m = dir (fullfile (src, "*.m")); | |
1409 oct = dir (fullfile (src, "*.oct")); | |
1410 mex = dir (fullfile (src, "*.mex")); | |
8174
ea9b5f31bfac
pkg.m: better handling of filenames with spaces
John W. Eaton <jwe@octave.org>
parents:
8172
diff
changeset
|
1411 |
ea9b5f31bfac
pkg.m: better handling of filenames with spaces
John W. Eaton <jwe@octave.org>
parents:
8172
diff
changeset
|
1412 filenames = cellfun (@(x) fullfile (src, x), |
10549 | 1413 {m.name, oct.name, mex.name}, |
11191
01ddaedd6ad5
Reverse changeset b1f4bdc276b6. Use all lower case for "uniformoutput" option.
Rik <octave@nomad.inbox5.com>
parents:
11190
diff
changeset
|
1414 "uniformoutput", false); |
5971 | 1415 endif |
5801 | 1416 |
8506 | 1417 ## Split into architecture dependent and independent files. |
7024 | 1418 if (isempty (filenames)) |
1419 idx = []; | |
1420 else | |
12931
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
12779
diff
changeset
|
1421 idx = cellfun ("is_architecture_dependent", filenames); |
7024 | 1422 endif |
6950 | 1423 archdependent = filenames (idx); |
1424 archindependent = filenames (!idx); | |
1425 | |
8506 | 1426 ## Copy the files. |
7548
9cbf1e2011a3
pkg.m: adapt to changes in isspace for cell arrays of strings.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7540
diff
changeset
|
1427 if (! all (isspace ([filenames{:}]))) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1428 if (! exist (instdir, "dir")) |
10549 | 1429 mkdir (instdir); |
1430 endif | |
1431 if (! all (isspace ([archindependent{:}]))) | |
1432 if (verbose) | |
1433 printf ("copyfile"); | |
1434 printf (" %s", archindependent{:}); | |
1435 printf ("%s\n", instdir); | |
1436 endif | |
1437 [status, output] = copyfile (archindependent, instdir); | |
1438 if (status != 1) | |
1439 rm_rf (desc.dir); | |
1440 error ("Couldn't copy files from 'src' to 'inst': %s", output); | |
1441 endif | |
6614 | 1442 endif |
10549 | 1443 if (! all (isspace ([archdependent{:}]))) |
1444 if (verbose) | |
1445 printf ("copyfile"); | |
1446 printf (" %s", archdependent{:}); | |
1447 printf (" %s\n", archdir); | |
1448 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1449 if (! exist (archdir, "dir")) |
10549 | 1450 mkdir (archdir); |
1451 endif | |
1452 [status, output] = copyfile (archdependent, archdir); | |
1453 if (status != 1) | |
1454 rm_rf (desc.dir); | |
1455 error ("Couldn't copy files from 'src' to 'inst': %s", output); | |
1456 endif | |
6614 | 1457 endif |
5801 | 1458 endif |
6496 | 1459 endif |
5801 | 1460 endfunction |
1461 | |
5971 | 1462 function pkg = extract_pkg (nm, pat) |
5955 | 1463 fid = fopen (nm, "rt"); |
5971 | 1464 pkg = ""; |
5955 | 1465 if (fid >= 0) |
6496 | 1466 while (! feof (fid)) |
5955 | 1467 ln = fgetl (fid); |
1468 if (ln > 0) | |
10549 | 1469 t = regexp (ln, pat, "tokens"); |
1470 if (! isempty (t)) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1471 pkg = cstrcat (pkg, "\n", t{1}{1}); |
10549 | 1472 endif |
5955 | 1473 endif |
1474 endwhile | |
6496 | 1475 if (! isempty (pkg)) |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1476 pkg = cstrcat (pkg, "\n"); |
5955 | 1477 endif |
1478 fclose (fid); | |
1479 endif | |
1480 endfunction | |
1481 | |
6925 | 1482 function create_pkgadddel (desc, packdir, nm, global_install) |
6675 | 1483 instpkg = fullfile (desc.dir, nm); |
1484 instfid = fopen (instpkg, "wt"); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1485 ## If it is exists, most of the PKG_* file should go into the |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1486 ## architecture dependent directory so that the autoload/mfilename |
6675 | 1487 ## commands work as expected. The only part that doesn't is the |
1488 ## part in the main directory. | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
1489 archdir = fullfile (getarchprefix (desc), cstrcat (desc.name, "-", |
10549 | 1490 desc.version), getarch ()); |
6925 | 1491 if (exist (getarchdir (desc, global_install), "dir")) |
1492 archpkg = fullfile (getarchdir (desc, global_install), nm); | |
1493 archfid = fopen (archpkg, "at"); | |
6675 | 1494 else |
1495 archpkg = instpkg; | |
1496 archfid = instfid; | |
1497 endif | |
6634 | 1498 |
6675 | 1499 if (archfid >= 0 && instfid >= 0) |
8506 | 1500 ## Search all dot-m files for PKG commands. |
7498 | 1501 lst = dir (fullfile (packdir, "inst", "*.m")); |
6496 | 1502 for i = 1:length (lst) |
7498 | 1503 nam = fullfile (packdir, "inst", lst(i).name); |
6675 | 1504 fwrite (instfid, extract_pkg (nam, ['^[#%][#%]* *' nm ': *(.*)$'])); |
5955 | 1505 endfor |
1506 | |
8506 | 1507 ## Search all C++ source files for PKG commands. |
7498 | 1508 lst = dir (fullfile (packdir, "src", "*.cc")); |
6496 | 1509 for i = 1:length (lst) |
7498 | 1510 nam = fullfile (packdir, "src", lst(i).name); |
6675 | 1511 fwrite (archfid, extract_pkg (nam, ['^//* *' nm ': *(.*)$'])); |
1512 fwrite (archfid, extract_pkg (nam, ['^/\** *' nm ': *(.*) *\*/$'])); | |
5955 | 1513 endfor |
1514 | |
8506 | 1515 ## Add developer included PKG commands. |
6496 | 1516 packdirnm = fullfile (packdir, nm); |
1517 if (exist (packdirnm, "file")) | |
6675 | 1518 fid = fopen (packdirnm, "rt"); |
1519 if (fid >= 0) | |
1520 while (! feof (fid)) | |
1521 ln = fgets (fid); | |
5955 | 1522 if (ln > 0) |
6675 | 1523 fwrite (archfid, ln); |
5955 | 1524 endif |
1525 endwhile | |
6675 | 1526 fclose (fid); |
5955 | 1527 endif |
1528 endif | |
5971 | 1529 |
8506 | 1530 ## If the files is empty remove it. |
6675 | 1531 fclose (instfid); |
1532 t = dir (instpkg); | |
5971 | 1533 if (t.bytes <= 0) |
6675 | 1534 unlink (instpkg); |
1535 endif | |
1536 | |
1537 if (instfid != archfid) | |
1538 fclose (archfid); | |
1539 t = dir (archpkg); | |
1540 if (t.bytes <= 0) | |
1541 unlink (archpkg); | |
1542 endif | |
5971 | 1543 endif |
5955 | 1544 endif |
1545 endfunction | |
1546 | |
6925 | 1547 function copy_files (desc, packdir, global_install) |
8506 | 1548 ## Create the installation directory. |
6496 | 1549 if (! exist (desc.dir, "dir")) |
1550 [status, output] = mkdir (desc.dir); | |
1551 if (status != 1) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1552 error ("couldn't create installation directory %s : %s", |
6496 | 1553 desc.dir, output); |
6020 | 1554 endif |
6496 | 1555 endif |
6020 | 1556 |
6925 | 1557 octfiledir = getarchdir (desc); |
1558 | |
8506 | 1559 ## Copy the files from "inst" to installdir. |
6496 | 1560 instdir = fullfile (packdir, "inst"); |
1561 if (! dirempty (instdir)) | |
1562 [status, output] = copyfile (fullfile (instdir, "*"), desc.dir); | |
1563 if (status != 1) | |
1564 rm_rf (desc.dir); | |
1565 error ("couldn't copy files to the installation directory"); | |
5801 | 1566 endif |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
1567 if (exist (fullfile (desc.dir, getarch ()), "dir") |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
1568 && ! strcmp (fullfile (desc.dir, getarch ()), octfiledir)) |
6925 | 1569 if (! exist (octfiledir, "dir")) |
8506 | 1570 ## Can be required to create upto three levels of dirs. |
6925 | 1571 octm1 = fileparts (octfiledir); |
1572 if (! exist (octm1, "dir")) | |
1573 octm2 = fileparts (octm1); | |
1574 if (! exist (octm2, "dir")) | |
1575 octm3 = fileparts (octm2); | |
1576 if (! exist (octm3, "dir")) | |
1577 [status, output] = mkdir (octm3); | |
1578 if (status != 1) | |
1579 rm_rf (desc.dir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1580 error ("couldn't create installation directory %s : %s", |
6925 | 1581 octm3, output); |
1582 endif | |
1583 endif | |
1584 [status, output] = mkdir (octm2); | |
1585 if (status != 1) | |
1586 rm_rf (desc.dir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1587 error ("couldn't create installation directory %s : %s", |
6925 | 1588 octm2, output); |
1589 endif | |
1590 endif | |
1591 [status, output] = mkdir (octm1); | |
1592 if (status != 1) | |
1593 rm_rf (desc.dir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1594 error ("couldn't create installation directory %s : %s", |
6925 | 1595 octm1, output); |
1596 endif | |
1597 endif | |
1598 [status, output] = mkdir (octfiledir); | |
1599 if (status != 1) | |
1600 rm_rf (desc.dir); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1601 error ("couldn't create installation directory %s : %s", |
6925 | 1602 octfiledir, output); |
1603 endif | |
1604 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1605 [status, output] = movefile (fullfile (desc.dir, getarch (), "*"), |
10549 | 1606 octfiledir); |
6925 | 1607 rm_rf (fullfile (desc.dir, getarch ())); |
1608 | |
1609 if (status != 1) | |
1610 rm_rf (desc.dir); | |
1611 rm_rf (octfiledir); | |
1612 error ("couldn't copy files to the installation directory"); | |
1613 endif | |
1614 endif | |
1615 | |
6496 | 1616 endif |
5801 | 1617 |
8506 | 1618 ## Create the "packinfo" directory. |
6496 | 1619 packinfo = fullfile (desc.dir, "packinfo"); |
1620 [status, msg] = mkdir (packinfo); | |
1621 if (status != 1) | |
1622 rm_rf (desc.dir); | |
6925 | 1623 rm_rf (octfiledir); |
6496 | 1624 error ("couldn't create packinfo directory: %s", msg); |
1625 endif | |
5801 | 1626 |
8506 | 1627 ## Copy DESCRIPTION. |
6496 | 1628 [status, output] = copyfile (fullfile (packdir, "DESCRIPTION"), packinfo); |
1629 if (status != 1) | |
6925 | 1630 rm_rf (desc.dir); |
1631 rm_rf (octfiledir); | |
1632 error ("couldn't copy DESCRIPTION: %s", output); | |
6496 | 1633 endif |
5801 | 1634 |
8506 | 1635 ## Copy COPYING. |
6496 | 1636 [status, output] = copyfile (fullfile (packdir, "COPYING"), packinfo); |
1637 if (status != 1) | |
6925 | 1638 rm_rf (desc.dir); |
1639 rm_rf (octfiledir); | |
1640 error ("couldn't copy COPYING: %s", output); | |
6496 | 1641 endif |
5993 | 1642 |
8506 | 1643 ## If the file ChangeLog exists, copy it. |
7498 | 1644 changelog_file = fullfile (packdir, "ChangeLog"); |
1645 if (exist (changelog_file, "file")) | |
1646 [status, output] = copyfile (changelog_file, packinfo); | |
6496 | 1647 if (status != 1) |
1648 rm_rf (desc.dir); | |
6925 | 1649 rm_rf (octfiledir); |
6496 | 1650 error ("couldn't copy ChangeLog file: %s", output); |
6254 | 1651 endif |
6496 | 1652 endif |
6254 | 1653 |
6496 | 1654 ## Is there an INDEX file to copy or should we generate one? |
7498 | 1655 index_file = fullfile (packdir, "INDEX"); |
1656 if (exist(index_file, "file")) | |
1657 [status, output] = copyfile (index_file, packinfo); | |
6496 | 1658 if (status != 1) |
1659 rm_rf (desc.dir); | |
6925 | 1660 rm_rf (octfiledir); |
6496 | 1661 error ("couldn't copy INDEX file: %s", output); |
5801 | 1662 endif |
6496 | 1663 else |
1664 try | |
7498 | 1665 write_index (desc, fullfile (packdir, "inst"), |
10549 | 1666 fullfile (packinfo, "INDEX"), global_install); |
6496 | 1667 catch |
1668 rm_rf (desc.dir); | |
6925 | 1669 rm_rf (octfiledir); |
6695 | 1670 rethrow (lasterror ()); |
6496 | 1671 end_try_catch |
1672 endif | |
5971 | 1673 |
6496 | 1674 ## Is there an 'on_uninstall.m' to install? |
7498 | 1675 fon_uninstall = fullfile (packdir, "on_uninstall.m"); |
6496 | 1676 if (exist (fon_uninstall, "file")) |
1677 [status, output] = copyfile (fon_uninstall, packinfo); | |
1678 if (status != 1) | |
1679 rm_rf (desc.dir); | |
6925 | 1680 rm_rf (octfiledir); |
6496 | 1681 error ("couldn't copy on_uninstall.m: %s", output); |
5971 | 1682 endif |
6496 | 1683 endif |
5971 | 1684 |
8506 | 1685 ## Is there a doc/ directory that needs to be installed? |
6496 | 1686 docdir = fullfile (packdir, "doc"); |
1687 if (exist (docdir, "dir") && ! dirempty (docdir)) | |
6925 | 1688 [status, output] = copyfile (docdir, desc.dir); |
6496 | 1689 endif |
1690 | |
8506 | 1691 ## Is there a bin/ directory that needs to be installed? |
6950 | 1692 ## FIXME: Need to treat architecture dependent files in bin/ |
6496 | 1693 bindir = fullfile (packdir, "bin"); |
1694 if (exist (bindir, "dir") && ! dirempty (bindir)) | |
6925 | 1695 [status, output] = copyfile (bindir, desc.dir); |
6496 | 1696 endif |
5801 | 1697 endfunction |
1698 | |
6925 | 1699 function finish_installation (desc, packdir, global_install) |
6496 | 1700 ## Is there a post-install to call? |
1701 if (exist (fullfile (packdir, "post_install.m"), "file")) | |
1702 wd = pwd (); | |
1703 try | |
1704 cd (packdir); | |
1705 post_install (desc); | |
1706 cd (wd); | |
1707 catch | |
1708 cd (wd); | |
1709 rm_rf (desc.dir); | |
6925 | 1710 rm_rf (getarchdir (desc), global_install); |
6695 | 1711 rethrow (lasterror ()); |
6496 | 1712 end_try_catch |
1713 endif | |
5801 | 1714 endfunction |
1715 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
1716 function generate_lookfor_cache (desc) |
8863
34a821854961
pkg.m (generate_lookfor_cache): generate a DOC file for each directory
Jason Riedy <jason@acm.org>
parents:
8746
diff
changeset
|
1717 dirs = split_by (genpath (desc.dir), pathsep ()); |
34a821854961
pkg.m (generate_lookfor_cache): generate a DOC file for each directory
Jason Riedy <jason@acm.org>
parents:
8746
diff
changeset
|
1718 for i = 1 : length (dirs) |
8942
c4383701e10d
use doc-cache instead of DOC for doc cache file name
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
1719 gen_doc_cache (fullfile (dirs{i}, "doc-cache"), dirs{i}); |
8863
34a821854961
pkg.m (generate_lookfor_cache): generate a DOC file for each directory
Jason Riedy <jason@acm.org>
parents:
8746
diff
changeset
|
1720 endfor |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
1721 endfunction |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8507
diff
changeset
|
1722 |
7498 | 1723 ## Make sure the package contains the essential files. |
6496 | 1724 function verify_directory (dir) |
1725 needed_files = {"COPYING", "DESCRIPTION"}; | |
1726 for f = needed_files | |
1727 if (! exist (fullfile (dir, f{1}), "file")) | |
1728 error ("package is missing file: %s", f{1}); | |
1729 endif | |
1730 endfor | |
5801 | 1731 endfunction |
1732 | |
8506 | 1733 ## Parse the DESCRIPTION file. |
6496 | 1734 function desc = get_description (filename) |
1735 [fid, msg] = fopen (filename, "r"); | |
1736 if (fid == -1) | |
1737 error ("the DESCRIPTION file %s could not be read: %s", filename, msg); | |
1738 endif | |
1739 | |
1740 desc = struct (); | |
5801 | 1741 |
6496 | 1742 line = fgetl (fid); |
1743 while (line != -1) | |
1744 if (line(1) == "#") | |
8506 | 1745 ## Comments, do nothing. |
6496 | 1746 elseif (isspace(line(1))) |
1747 ## Continuation lines | |
1748 if (exist ("keyword", "var") && isfield (desc, keyword)) | |
10549 | 1749 desc.(keyword) = cstrcat (desc.(keyword), " ", rstrip(line)); |
6496 | 1750 endif |
5801 | 1751 else |
6496 | 1752 ## Keyword/value pair |
1753 colon = find (line == ":"); | |
1754 if (length (colon) == 0) | |
10549 | 1755 disp ("skipping line"); |
6496 | 1756 else |
10549 | 1757 colon = colon(1); |
1758 keyword = tolower (strip (line(1:colon-1))); | |
1759 value = strip (line (colon+1:end)); | |
1760 if (length (value) == 0) | |
1761 fclose (fid); | |
1762 error ("the keyword %s has an empty value", desc.keywords{end}); | |
1763 endif | |
1764 desc.(keyword) = value; | |
6496 | 1765 endif |
5801 | 1766 endif |
6496 | 1767 line = fgetl (fid); |
1768 endwhile | |
1769 fclose (fid); | |
1770 | |
8506 | 1771 ## Make sure all is okay. |
6496 | 1772 needed_fields = {"name", "version", "date", "title", ... |
10549 | 1773 "author", "maintainer", "description"}; |
6496 | 1774 for f = needed_fields |
1775 if (! isfield (desc, f{1})) | |
1776 error ("description is missing needed field %s", f{1}); | |
1777 endif | |
1778 endfor | |
1779 desc.version = fix_version (desc.version); | |
1780 if (isfield (desc, "depends")) | |
1781 desc.depends = fix_depends (desc.depends); | |
1782 else | |
1783 desc.depends = ""; | |
1784 endif | |
1785 desc.name = tolower (desc.name); | |
5801 | 1786 endfunction |
1787 | |
7498 | 1788 ## Make sure the version string v is a valid x.y.z version string |
8506 | 1789 ## Examples: "0.1" => "0.1.0", "monkey" => error(...). |
6496 | 1790 function out = fix_version (v) |
1791 dots = find (v == "."); | |
1792 if (length (dots) == 1) | |
1793 major = str2num (v(1:dots-1)); | |
1794 minor = str2num (v(dots+1:end)); | |
1795 if (length (major) != 0 && length (minor) != 0) | |
1796 out = sprintf ("%d.%d.0", major, minor); | |
1797 return; | |
5801 | 1798 endif |
6496 | 1799 elseif (length (dots) == 2) |
1800 major = str2num (v(1:dots(1)-1)); | |
1801 minor = str2num (v(dots(1)+1:dots(2)-1)); | |
7498 | 1802 rev = str2num (v(dots(2)+1:end)); |
6496 | 1803 if (length (major) != 0 && length (minor) != 0 && length (rev) != 0) |
1804 out = sprintf ("%d.%d.%d", major, minor, rev); | |
1805 return; | |
1806 endif | |
1807 endif | |
1808 error ("bad version string: %s", v); | |
5801 | 1809 endfunction |
1810 | |
7498 | 1811 ## Make sure the depends field is of the right format. |
5801 | 1812 ## This function returns a cell of structures with the following fields: |
1813 ## package, version, operator | |
6496 | 1814 function deps_cell = fix_depends (depends) |
1815 deps = split_by (tolower (depends), ","); | |
1816 deps_cell = cell (1, length (deps)); | |
1817 | |
8506 | 1818 ## For each dependency. |
6496 | 1819 for i = 1:length (deps) |
1820 dep = deps{i}; | |
1821 lpar = find (dep == "("); | |
1822 rpar = find (dep == ")"); | |
1823 ## Does the dependency specify a version | |
8506 | 1824 ## Example: package(>= version). |
6496 | 1825 if (length (lpar) == 1 && length (rpar) == 1) |
1826 package = tolower (strip (dep(1:lpar-1))); | |
1827 sub = dep(lpar(1)+1:rpar(1)-1); | |
8900
63ad1133d0ed
fix & simplify fix_depends pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
8877
diff
changeset
|
1828 parts = strsplit (sub, " ", true); |
63ad1133d0ed
fix & simplify fix_depends pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
8877
diff
changeset
|
1829 if (length (parts) != 2) |
10549 | 1830 error ("incorrect syntax for dependency `%s' in the DESCRIPTION file\n", |
1831 dep); | |
6496 | 1832 endif |
8900
63ad1133d0ed
fix & simplify fix_depends pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
8877
diff
changeset
|
1833 operator = parts{1}; |
6496 | 1834 if (! any (strcmp (operator, {">", ">=", "<=", "<", "=="}))) |
10549 | 1835 error ("unsupported operator: %s", operator); |
6496 | 1836 endif |
8900
63ad1133d0ed
fix & simplify fix_depends pkg.m
Jaroslav Hajek <highegg@gmail.com>
parents:
8877
diff
changeset
|
1837 version = fix_version (parts{2}); |
6496 | 1838 |
1839 ## If no version is specified for the dependency | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1840 ## we say that the version should be greater than |
8506 | 1841 ## or equal to "0.0.0". |
6496 | 1842 else |
1843 package = tolower (strip (dep)); | |
1844 operator = ">="; | |
1845 version = "0.0.0"; | |
1846 endif | |
1847 deps_cell{i} = struct ("package", package, "operator", operator, | |
10549 | 1848 "version", version); |
6496 | 1849 endfor |
5801 | 1850 endfunction |
1851 | |
7498 | 1852 ## Strip the text of spaces from the right |
8506 | 1853 ## Example: " hello world " => " hello world" |
1854 ## FIXME -- is this the same as deblank? | |
6496 | 1855 function text = rstrip (text) |
1856 chars = find (! isspace (text)); | |
1857 if (length (chars) > 0) | |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8174
diff
changeset
|
1858 ## FIXME: shouldn't it be text = text(1:chars(end)); |
6496 | 1859 text = text (chars(1):end); |
1860 else | |
1861 text = ""; | |
1862 endif | |
5801 | 1863 endfunction |
1864 | |
8506 | 1865 ## Strip the text of spaces from the left and the right. |
5801 | 1866 ## Example: " hello world " => "hello world" |
6496 | 1867 function text = strip (text) |
1868 chars = find (! isspace (text)); | |
1869 if (length (chars) > 0) | |
1870 text = text(chars(1):chars(end)); | |
1871 else | |
1872 text = ""; | |
1873 endif | |
5801 | 1874 endfunction |
1875 | |
8506 | 1876 ## Split the text into a cell array of strings by sep. |
5801 | 1877 ## Example: "A, B" => {"A", "B"} (with sep = ",") |
6496 | 1878 function out = split_by (text, sep) |
8877
2c8b2399247b
implement strsplit; deprecate split
Jaroslav Hajek <highegg@gmail.com>
parents:
8863
diff
changeset
|
1879 out = strtrim (strsplit (text, sep)); |
5801 | 1880 endfunction |
1881 | |
7498 | 1882 ## Create an INDEX file for a package that doesn't provide one. |
5801 | 1883 ## 'desc' describes the package. |
7498 | 1884 ## 'dir' is the 'inst' directory in temporary directory. |
1885 ## 'index_file' is the name (including path) of resulting INDEX file. | |
1886 function write_index (desc, dir, index_file, global_install) | |
6496 | 1887 ## Get names of functions in dir |
1888 [files, err, msg] = readdir (dir); | |
1889 if (err) | |
1890 error ("couldn't read directory %s: %s", dir, msg); | |
1891 endif | |
1892 | |
10401
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1893 ## Get classes in dir |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1894 class_idx = strmatch ("@", files); |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1895 for k = 1:length (class_idx) |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1896 class_name = files {class_idx (k)}; |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1897 class_dir = fullfile (dir, class_name); |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1898 if (exist (class_dir, "dir")) |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1899 [files2, err, msg] = readdir (class_dir); |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1900 if (err) |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1901 error ("couldn't read directory %s: %s", class_dir, msg); |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1902 endif |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1903 files2 = strcat (class_name, filesep (), files2); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1904 files = [files; files2]; |
10401
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1905 endif |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1906 endfor |
6d1e49abf95f
pkg/pkg.m (write_index): include classes in autogenerated INDEX files
Soren Hauberg <hauberg@gmail.com>
parents:
10199
diff
changeset
|
1907 |
8506 | 1908 ## Check for architecture dependent files. |
6925 | 1909 tmpdir = getarchdir (desc); |
6634 | 1910 if (exist (tmpdir, "dir")) |
1911 [files2, err, msg] = readdir (tmpdir); | |
1912 if (err) | |
1913 error ("couldn't read directory %s: %s", tmpdir, msg); | |
1914 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
1915 files = [files; files2]; |
6634 | 1916 endif |
1917 | |
6496 | 1918 functions = {}; |
1919 for i = 1:length (files) | |
1920 file = files{i}; | |
1921 lf = length (file); | |
1922 if (lf > 2 && strcmp (file(end-1:end), ".m")) | |
1923 functions{end+1} = file(1:end-2); | |
1924 elseif (lf > 4 && strcmp (file(end-3:end), ".oct")) | |
1925 functions{end+1} = file(1:end-4); | |
5801 | 1926 endif |
6496 | 1927 endfor |
1928 | |
1929 ## Does desc have a categories field? | |
1930 if (! isfield (desc, "categories")) | |
1931 error ("the DESCRIPTION file must have a Categories field, when no INDEX file is given"); | |
1932 endif | |
1933 categories = split_by (desc.categories, ","); | |
1934 if (length (categories) < 1) | |
1935 error ("the Category field is empty"); | |
1936 endif | |
1937 | |
8506 | 1938 ## Write INDEX. |
7498 | 1939 fid = fopen (index_file, "w"); |
6496 | 1940 if (fid == -1) |
11588
d5bd2766c640
style fixes for warning and error messages in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
1941 error ("couldn't open %s for writing", index_file); |
6496 | 1942 endif |
1943 fprintf (fid, "%s >> %s\n", desc.name, desc.title); | |
1944 fprintf (fid, "%s\n", categories{1}); | |
1945 fprintf (fid, " %s\n", functions{:}); | |
1946 fclose (fid); | |
5801 | 1947 endfunction |
1948 | |
6820 | 1949 function bad_deps = get_unsatisfied_deps (desc, installed_pkgs_lst) |
6496 | 1950 bad_deps = {}; |
5801 | 1951 |
8506 | 1952 ## For each dependency. |
6496 | 1953 for i = 1:length (desc.depends) |
1954 dep = desc.depends{i}; | |
5801 | 1955 |
6496 | 1956 ## Is the current dependency Octave? |
1957 if (strcmp (dep.package, "octave")) | |
1958 if (! compare_versions (OCTAVE_VERSION, dep.version, dep.operator)) | |
1959 bad_deps{end+1} = dep; | |
6258 | 1960 endif |
8506 | 1961 ## Is the current dependency not Octave? |
6496 | 1962 else |
1963 ok = false; | |
6820 | 1964 for i = 1:length (installed_pkgs_lst) |
10549 | 1965 cur_name = installed_pkgs_lst{i}.name; |
1966 cur_version = installed_pkgs_lst{i}.version; | |
1967 if (strcmp (dep.package, cur_name) | |
1968 && compare_versions (cur_version, dep.version, dep.operator)) | |
1969 ok = true; | |
1970 break; | |
1971 endif | |
6258 | 1972 endfor |
6496 | 1973 if (! ok) |
1974 bad_deps{end+1} = dep; | |
1975 endif | |
5801 | 1976 endif |
6496 | 1977 endfor |
1978 endfunction | |
1979 | |
1980 function [out1, out2] = installed_packages (local_list, global_list) | |
8506 | 1981 ## Get the list of installed packages. |
6496 | 1982 try |
1983 local_packages = load (local_list).local_packages; | |
1984 catch | |
1985 local_packages = {}; | |
1986 end_try_catch | |
1987 try | |
6675 | 1988 global_packages = load (global_list).global_packages; |
6496 | 1989 catch |
1990 global_packages = {}; | |
1991 end_try_catch | |
6820 | 1992 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496 | 1993 |
1994 ## Eliminate duplicates in the installed package list. | |
8506 | 1995 ## Locally installed packages take precedence. |
6496 | 1996 dup = []; |
6820 | 1997 for i = 1:length (installed_pkgs_lst) |
6496 | 1998 if (find (dup, i)) |
1999 continue; | |
5801 | 2000 endif |
6820 | 2001 for j = (i+1):length (installed_pkgs_lst) |
6496 | 2002 if (find (dup, j)) |
10549 | 2003 continue; |
6496 | 2004 endif |
6820 | 2005 if (strcmp (installed_pkgs_lst{i}.name, installed_pkgs_lst{j}.name)) |
10549 | 2006 dup = [dup, j]; |
6496 | 2007 endif |
5987 | 2008 endfor |
6496 | 2009 endfor |
2010 if (! isempty(dup)) | |
6820 | 2011 installed_pkgs_lst(dup) = []; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2012 endif |
6496 | 2013 |
8506 | 2014 ## Now check if the package is loaded. |
6645 | 2015 tmppath = strrep (path(), "\\", "/"); |
6820 | 2016 for i = 1:length (installed_pkgs_lst) |
2017 if (findstr (tmppath, strrep (installed_pkgs_lst{i}.dir, "\\", "/"))) | |
2018 installed_pkgs_lst{i}.loaded = true; | |
6616 | 2019 else |
6820 | 2020 installed_pkgs_lst{i}.loaded = false; |
6616 | 2021 endif |
2022 endfor | |
6675 | 2023 for i = 1:length (local_packages) |
6776 | 2024 if (findstr (tmppath, strrep (local_packages{i}.dir, "\\", "/"))) |
6675 | 2025 local_packages{i}.loaded = true; |
2026 else | |
2027 local_packages{i}.loaded = false; | |
2028 endif | |
2029 endfor | |
2030 for i = 1:length (global_packages) | |
6776 | 2031 if (findstr (tmppath, strrep (global_packages{i}.dir, "\\", "/"))) |
6675 | 2032 global_packages{i}.loaded = true; |
2033 else | |
2034 global_packages{i}.loaded = false; | |
2035 endif | |
2036 endfor | |
6616 | 2037 |
6496 | 2038 ## Should we return something? |
2039 if (nargout == 2) | |
2040 out1 = local_packages; | |
2041 out2 = global_packages; | |
2042 return; | |
2043 elseif (nargout == 1) | |
6820 | 2044 out1 = installed_pkgs_lst; |
6496 | 2045 return; |
2046 endif | |
2047 | |
8506 | 2048 ## We shouldn't return something, so we'll print something. |
6820 | 2049 num_packages = length (installed_pkgs_lst); |
6496 | 2050 if (num_packages == 0) |
2051 printf ("no packages installed.\n"); | |
2052 return; | |
2053 endif | |
2054 | |
8506 | 2055 ## Compute the maximal lengths of name, version, and dir. |
6496 | 2056 h1 = "Package Name"; |
2057 h2 = "Version"; | |
2058 h3 = "Installation directory"; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2059 max_name_length = length (h1); |
6496 | 2060 max_version_length = length (h2); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2061 names = cell (num_packages, 1); |
6496 | 2062 for i = 1:num_packages |
2063 max_name_length = max (max_name_length, | |
10549 | 2064 length (installed_pkgs_lst{i}.name)); |
6496 | 2065 max_version_length = max (max_version_length, |
10549 | 2066 length (installed_pkgs_lst{i}.version)); |
6820 | 2067 names{i} = installed_pkgs_lst{i}.name; |
6496 | 2068 endfor |
6698 | 2069 max_dir_length = terminal_size()(2) - max_name_length - ... |
10549 | 2070 max_version_length - 7; |
6698 | 2071 if (max_dir_length < 20) |
2072 max_dir_length = Inf; | |
2073 endif | |
2074 | |
6616 | 2075 h1 = postpad (h1, max_name_length + 1, " "); |
6496 | 2076 h2 = postpad (h2, max_version_length, " ");; |
2077 | |
8506 | 2078 ## Print a header. |
6496 | 2079 header = sprintf("%s | %s | %s\n", h1, h2, h3); |
2080 printf (header); | |
2081 tmp = sprintf (repmat ("-", 1, length(header)-1)); | |
2082 tmp(length(h1)+2) = "+"; | |
2083 tmp(length(h1)+length(h2)+5) = "+"; | |
2084 printf ("%s\n", tmp); | |
2085 | |
8506 | 2086 ## Print the packages. |
6616 | 2087 format = sprintf ("%%%ds %%1s| %%%ds | %%s\n", max_name_length, |
10549 | 2088 max_version_length); |
6496 | 2089 [dummy, idx] = sort (names); |
2090 for i = 1:num_packages | |
6820 | 2091 cur_name = installed_pkgs_lst{idx(i)}.name; |
2092 cur_version = installed_pkgs_lst{idx(i)}.version; | |
2093 cur_dir = installed_pkgs_lst{idx(i)}.dir; | |
6698 | 2094 if (length (cur_dir) > max_dir_length) |
2095 first_char = length (cur_dir) - max_dir_length + 4; | |
2096 first_filesep = strfind (cur_dir(first_char:end), filesep()); | |
2097 if (! isempty (first_filesep)) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2098 cur_dir = cstrcat ("...", |
10549 | 2099 cur_dir((first_char + first_filesep(1) - 1):end)); |
6698 | 2100 else |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
2101 cur_dir = cstrcat ("...", cur_dir(first_char:end)); |
6698 | 2102 endif |
2103 endif | |
6820 | 2104 if (installed_pkgs_lst{idx(i)}.loaded) |
6616 | 2105 cur_loaded = "*"; |
2106 else | |
2107 cur_loaded = " "; | |
2108 endif | |
2109 printf (format, cur_name, cur_loaded, cur_version, cur_dir); | |
6496 | 2110 endfor |
5801 | 2111 endfunction |
2112 | |
6496 | 2113 function load_packages (files, handle_deps, local_list, global_list) |
6820 | 2114 installed_pkgs_lst = installed_packages (local_list, global_list); |
2115 num_packages = length (installed_pkgs_lst); | |
6496 | 2116 |
8506 | 2117 ## Read package names and installdirs into a more convenient format. |
6496 | 2118 pnames = pdirs = cell (1, num_packages); |
2119 for i = 1:num_packages | |
6820 | 2120 pnames{i} = installed_pkgs_lst{i}.name; |
2121 pdirs{i} = installed_pkgs_lst{i}.dir; | |
6496 | 2122 endfor |
2123 | |
8506 | 2124 ## Load all. |
6496 | 2125 if (length (files) == 1 && strcmp (files{1}, "all")) |
6820 | 2126 idx = [1:length(installed_pkgs_lst)]; |
8506 | 2127 ## Load auto. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2128 elseif (length (files) == 1 && strcmp (files{1}, "auto")) |
6695 | 2129 idx = []; |
6820 | 2130 for i = 1:length (installed_pkgs_lst) |
6496 | 2131 if (exist (fullfile (pdirs{i}, "packinfo", ".autoload"), "file")) |
10549 | 2132 idx (end + 1) = i; |
6496 | 2133 endif |
6037 | 2134 endfor |
8506 | 2135 ## Load package_name1 ... |
6496 | 2136 else |
6695 | 2137 idx = []; |
6496 | 2138 for i = 1:length (files) |
6695 | 2139 idx2 = find (strcmp (pnames, files{i})); |
2140 if (! any (idx2)) | |
10549 | 2141 error ("package %s is not installed", files{i}); |
6496 | 2142 endif |
6695 | 2143 idx (end + 1) = idx2; |
6496 | 2144 endfor |
2145 endif | |
6037 | 2146 |
8506 | 2147 ## Load the packages, but take care of the ordering of dependencies. |
6925 | 2148 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, true); |
5801 | 2149 endfunction |
5928 | 2150 |
6496 | 2151 function unload_packages (files, handle_deps, local_list, global_list) |
6820 | 2152 installed_pkgs_lst = installed_packages (local_list, global_list); |
2153 num_packages = length (installed_pkgs_lst); | |
6496 | 2154 |
8506 | 2155 ## Read package names and installdirs into a more convenient format. |
6496 | 2156 pnames = pdirs = cell (1, num_packages); |
2157 for i = 1:num_packages | |
6820 | 2158 pnames{i} = installed_pkgs_lst{i}.name; |
2159 pdirs{i} = installed_pkgs_lst{i}.dir; | |
2160 pdeps{i} = installed_pkgs_lst{i}.depends; | |
6496 | 2161 endfor |
2162 | |
8506 | 2163 ## Get the current octave path. |
6496 | 2164 p = split_by (path(), pathsep ()); |
6203 | 2165 |
6496 | 2166 if (length (files) == 1 && strcmp (files{1}, "all")) |
8506 | 2167 ## Unload all. |
2168 dirs = pdirs; | |
2169 desc = installed_pkgs_lst; | |
6496 | 2170 else |
8506 | 2171 ## Unload package_name1 ... |
6496 | 2172 dirs = {}; |
6925 | 2173 desc = {}; |
6496 | 2174 for i = 1:length (files) |
7208 | 2175 idx = strcmp (pnames, files{i}); |
6496 | 2176 if (! any (idx)) |
10549 | 2177 error ("package %s is not installed", files{i}); |
6496 | 2178 endif |
10549 | 2179 dirs{end+1} = pdirs{idx}; |
7208 | 2180 desc{end+1} = installed_pkgs_lst{idx}; |
6496 | 2181 endfor |
2182 endif | |
2183 | |
8506 | 2184 ## Check for architecture dependent directories. |
6614 | 2185 archdirs = {}; |
2186 for i = 1:length (dirs) | |
7208 | 2187 tmpdir = getarchdir (desc{i}); |
6614 | 2188 if (exist (tmpdir, "dir")) |
7208 | 2189 archdirs{end+1} = dirs{i}; |
2190 archdirs{end+1} = tmpdir; | |
6925 | 2191 else |
7208 | 2192 archdirs{end+1} = dirs{i}; |
6614 | 2193 endif |
2194 endfor | |
2195 | |
8506 | 2196 ## Unload the packages. |
6925 | 2197 for i = 1:length (archdirs) |
2198 d = archdirs{i}; | |
6496 | 2199 idx = strcmp (p, d); |
2200 if (any (idx)) | |
2201 rmpath (d); | |
8506 | 2202 ## FIXME: We should also check if we need to remove items from |
2203 ## EXEC_PATH. | |
6203 | 2204 endif |
6496 | 2205 endfor |
6203 | 2206 endfunction |
2207 | |
5928 | 2208 function [status_out, msg_out] = rm_rf (dir) |
6925 | 2209 if (exist (dir)) |
2210 crr = confirm_recursive_rmdir (); | |
2211 unwind_protect | |
2212 confirm_recursive_rmdir (false); | |
2213 [status, msg] = rmdir (dir, "s"); | |
2214 unwind_protect_cleanup | |
2215 confirm_recursive_rmdir (crr); | |
2216 end_unwind_protect | |
2217 else | |
2218 status = 1; | |
2219 msg = ""; | |
2220 endif | |
5928 | 2221 if (nargout > 0) |
2222 status_out = status; | |
2223 endif | |
2224 if (nargout > 1) | |
2225 msg_out = msg; | |
2226 endif | |
2227 endfunction | |
5971 | 2228 |
2229 function emp = dirempty (nm, ign) | |
6925 | 2230 if (exist (nm, "dir")) |
2231 if (nargin < 2) | |
2232 ign = {".", ".."}; | |
2233 else | |
2234 ign = [{".", ".."}, ign]; | |
2235 endif | |
2236 l = dir (nm); | |
2237 for i = 1:length (l) | |
2238 found = false; | |
2239 for j = 1:length (ign) | |
2240 if (strcmp (l(i).name, ign{j})) | |
2241 found = true; | |
2242 break; | |
2243 endif | |
2244 endfor | |
2245 if (! found) | |
2246 emp = false; | |
2247 return | |
5971 | 2248 endif |
2249 endfor | |
6925 | 2250 emp = true; |
2251 else | |
2252 emp = true; | |
2253 endif | |
5971 | 2254 endfunction |
6614 | 2255 |
2256 function arch = getarch () | |
12710
762d10c77277
maint: use libdir for .oct files, not libexecdir
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
2257 persistent _arch = cstrcat (octave_config_info ("canonical_host_type"), |
762d10c77277
maint: use libdir for .oct files, not libexecdir
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
2258 "-", octave_config_info ("api_version")); |
6614 | 2259 arch = _arch; |
2260 endfunction | |
6645 | 2261 |
6925 | 2262 function archprefix = getarchprefix (desc, global_install) |
2263 if ((nargin == 2 && global_install) || (nargin < 2 && issuperuser ())) | |
12710
762d10c77277
maint: use libdir for .oct files, not libexecdir
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
2264 archprefix = fullfile (octave_config_info ("libdir"), "octave", |
10549 | 2265 "packages", cstrcat(desc.name, "-", desc.version)); |
6925 | 2266 else |
2267 archprefix = desc.dir; | |
2268 endif | |
2269 endfunction | |
2270 | |
2271 function archdir = getarchdir (desc) | |
2272 archdir = fullfile (desc.archprefix, getarch()); | |
2273 endfunction | |
2274 | |
2275 function s = issuperuser () | |
2276 if ((ispc () && ! isunix ()) || (geteuid() == 0)) | |
2277 s = true; | |
2278 else | |
2279 s = false; | |
2280 endif | |
2281 endfunction | |
2282 | |
6645 | 2283 function [status, output] = shell (cmd) |
2284 persistent have_sh; | |
2285 | |
2286 cmd = strrep (cmd, "\\", "/"); | |
2287 if (ispc () && ! isunix ()) | |
2288 if (isempty(have_sh)) | |
2289 if (system("sh.exe -c \"exit\"")) | |
2290 have_sh = false; | |
2291 else | |
2292 have_sh = true; | |
2293 endif | |
2294 endif | |
2295 if (have_sh) | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7498
diff
changeset
|
2296 [status, output] = system (cstrcat ("sh.exe -c \"", cmd, "\"")); |
6645 | 2297 else |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11588
diff
changeset
|
2298 error ("Can not find the command shell"); |
6645 | 2299 endif |
2300 else | |
2301 [status, output] = system (cmd); | |
2302 endif | |
2303 endfunction | |
6695 | 2304 |
2305 function newdesc = save_order (desc) | |
2306 newdesc = {}; | |
2307 for i = 1 : length(desc) | |
2308 deps = desc{i}.depends; | |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2309 if (isempty (deps) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2310 || (length (deps) == 1 && strcmp(deps{1}.package, "octave"))) |
6695 | 2311 newdesc {end + 1} = desc{i}; |
2312 else | |
2313 tmpdesc = {}; | |
2314 for k = 1 : length (deps) | |
2315 for j = 1 : length (desc) | |
2316 if (strcmp (desc{j}.name, deps{k}.package)) | |
7208 | 2317 tmpdesc{end+1} = desc{j}; |
10549 | 2318 break; |
6695 | 2319 endif |
2320 endfor | |
2321 endfor | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2322 if (! isempty (tmpdesc)) |
6695 | 2323 newdesc = {newdesc{:}, save_order(tmpdesc){:}, desc{i}}; |
2324 else | |
7208 | 2325 newdesc{end+1} = desc{i}; |
6695 | 2326 endif |
2327 endif | |
2328 endfor | |
8506 | 2329 ## Eliminate the duplicates. |
6695 | 2330 idx = []; |
2331 for i = 1 : length (newdesc) | |
2332 for j = (i + 1) : length (newdesc) | |
2333 if (strcmp (newdesc{i}.name, newdesc{j}.name)) | |
2334 idx (end + 1) = j; | |
2335 endif | |
2336 endfor | |
2337 endfor | |
2338 newdesc(idx) = []; | |
2339 endfunction | |
2340 | |
6925 | 2341 function load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, |
10549 | 2342 global_install) |
6820 | 2343 idx = load_package_dirs (idx, [], handle_deps, installed_pkgs_lst); |
6695 | 2344 dirs = {}; |
2345 execpath = EXEC_PATH (); | |
2346 for i = idx; | |
6820 | 2347 ndir = installed_pkgs_lst{i}.dir; |
7208 | 2348 dirs{end+1} = ndir; |
6695 | 2349 if (exist (fullfile (dirs{end}, "bin"), "dir")) |
11300
4ecc7bc5bc83
search PATH from environment for programs, not EXEC_PATH
John W. Eaton <jwe@octave.org>
parents:
11191
diff
changeset
|
2350 execpath = cstrcat (execpath, pathsep (), fullfile (dirs{end}, "bin")); |
6695 | 2351 endif |
7208 | 2352 tmpdir = getarchdir (installed_pkgs_lst{i}); |
6695 | 2353 if (exist (tmpdir, "dir")) |
2354 dirs{end + 1} = tmpdir; | |
6950 | 2355 if (exist (fullfile (dirs{end}, "bin"), "dir")) |
11300
4ecc7bc5bc83
search PATH from environment for programs, not EXEC_PATH
John W. Eaton <jwe@octave.org>
parents:
11191
diff
changeset
|
2356 execpath = cstrcat (execpath, pathsep (), fullfile (dirs{end}, "bin")); |
6950 | 2357 endif |
6695 | 2358 endif |
2359 endfor | |
2360 | |
8506 | 2361 ## Load the packages. |
6695 | 2362 if (length (dirs) > 0) |
2363 addpath (dirs{:}); | |
2364 endif | |
2365 | |
8506 | 2366 ## Add the binaries to exec_path. |
6695 | 2367 if (! strcmp (EXEC_PATH, execpath)) |
2368 EXEC_PATH (execpath); | |
2369 endif | |
2370 endfunction | |
2371 | |
6820 | 2372 function idx = load_package_dirs (lidx, idx, handle_deps, installed_pkgs_lst) |
6695 | 2373 for i = lidx |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2374 if (isfield (installed_pkgs_lst{i}, "loaded") |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2375 && installed_pkgs_lst{i}.loaded) |
6695 | 2376 continue; |
2377 else | |
2378 if (handle_deps) | |
6820 | 2379 deps = installed_pkgs_lst{i}.depends; |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2380 if ((length (deps) > 1) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2381 || (length (deps) == 1 && ! strcmp(deps{1}.package, "octave"))) |
6695 | 2382 tmplidx = []; |
2383 for k = 1 : length (deps) | |
6820 | 2384 for j = 1 : length (installed_pkgs_lst) |
2385 if (strcmp (installed_pkgs_lst{j}.name, deps{k}.package)) | |
6695 | 2386 tmplidx (end + 1) = j; |
10549 | 2387 break; |
6695 | 2388 endif |
2389 endfor | |
2390 endfor | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2391 idx = load_package_dirs (tmplidx, idx, handle_deps, |
10549 | 2392 installed_pkgs_lst); |
6695 | 2393 endif |
2394 endif | |
2395 if (isempty (find(idx == i))) | |
2396 idx (end + 1) = i; | |
2397 endif | |
2398 endif | |
2399 endfor | |
2400 endfunction | |
6950 | 2401 |
2402 function dep = is_architecture_dependent (nm) | |
7329 | 2403 persistent archdepsuffix = {".oct",".mex",".a",".lib",".so",".so.*",".dll","dylib"}; |
6950 | 2404 |
2405 dep = false; | |
2406 for i = 1 : length (archdepsuffix) | |
7208 | 2407 ext = archdepsuffix{i}; |
6950 | 2408 if (ext(end) == "*") |
2409 isglob = true; | |
2410 ext(end) = []; | |
2411 else | |
2412 isglob = false; | |
2413 endif | |
2414 pos = findstr (nm, ext); | |
2415 if (pos) | |
7208 | 2416 if (! isglob && (length(nm) - pos(end) != length(ext) - 1)) |
10549 | 2417 continue; |
6950 | 2418 endif |
2419 dep = true; | |
2420 break; | |
2421 endif | |
2422 endfor | |
2423 endfunction | |
10684
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
2424 |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
2425 function [url, local_file] = get_forge_download (name) |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
2426 [ver, url] = get_forge_pkg (name); |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
2427 local_file = [name, "-", ver, ".tar.gz"]; |
76aba4305f1f
support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10549
diff
changeset
|
2428 endfunction |
10685
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2429 |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2430 function list = list_forge_packages () |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2431 [list, succ] = urlread ("http://octave.sourceforge.net/list_packages.php"); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2432 if (succ) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2433 list = strsplit (list, " \n\t", true); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2434 else |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2435 error ("pkg: could not read URL, please verify internet connection"); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2436 endif |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2437 if (nargout == 0) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2438 page_screen_output (false, "local"); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2439 puts ("OctaveForge provides these packages:\n"); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2440 for i = 1:length (list) |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2441 try |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2442 ver = get_forge_pkg (list{i}); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2443 catch |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2444 ver = "unknown"; |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2445 end_try_catch |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2446 printf (" %s %s\n", list{i}, ver); |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2447 endfor |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2448 endif |
81a43049dee2
support pkg list -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
10684
diff
changeset
|
2449 endfunction |