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