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