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