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