Mercurial > hg > octave-nkf
annotate scripts/pkg/get_forge_pkg.m @ 10793:be55736a0783
Grammarcheck the documentation from m-files.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 18 Jul 2010 20:35:16 -0700 |
parents | 76aba4305f1f |
children | 4f46520e2103 |
rev | line source |
---|---|
10684 | 1 ## Copyright (C) 2010 VZLU Prague, a.s. |
2 ## | |
3 ## This program is free software; you can redistribute it and/or modify | |
4 ## it under the terms of the GNU General Public License as published by | |
5 ## the Free Software Foundation; either version 3 of the License, or | |
6 ## (at your option) any later version. | |
7 ## | |
8 ## This program is distributed in the hope that it will be useful, | |
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 ## GNU General Public License for more details. | |
12 ## | |
13 ## You should have received a copy of the GNU General Public License | |
14 ## along with this program; see the file COPYING. If not, see | |
15 ## <http://www.gnu.org/licenses/>. | |
16 | |
17 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10684
diff
changeset
|
18 ## @deftypefn {Function File} {[@var{ver}, @var{url}] =} get_forge_pkg (@var{name}) |
10684 | 19 ## Tries to discover the current version of an OctaveForge package from the web, |
20 ## using a working internet connection and the urlread function. | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10684
diff
changeset
|
21 ## If two output arguments are requested, returns also an address to download |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10684
diff
changeset
|
22 ## the file. |
10684 | 23 ## @end deftypefn |
24 | |
25 function [ver, url] = get_forge_pkg (name) | |
26 if (nargin != 1) | |
27 print_usage (); | |
28 endif | |
29 ## Verify that name is valid. | |
30 if (! (ischar (name) && rows (name) == 1 && ndims (name) == 2)) | |
31 error ("get_forge_pkg: package name must be a string"); | |
32 elseif (! all (isalnum (name) | name == "-" | name == ".")) | |
33 error ("get_forge_pkg: invalid package name: %s", name); | |
34 endif | |
35 | |
36 name = tolower (name); | |
37 | |
38 ## Try to download package's index page. | |
39 [html, succ] = urlread (sprintf ("http://octave.sourceforge.net/%s/index.html", name)); | |
40 if (succ) | |
41 ## Remove blanks for simpler matching. | |
42 html(isspace(html)) = []; | |
43 ## Good. Let's grep for the version. | |
44 pat = "<tdclass=""package_table"">PackageVersion:</td><td>([0-9\\.]*)</td>"; | |
45 [~, ~, ~, ~, t] = regexp (html, pat); | |
46 if (isempty (t) || isempty(t{1})) | |
47 error ("get_forge_pkg: could not read version number from package's page."); | |
48 else | |
49 ver = t{1}{1}; | |
50 if (nargout > 1) | |
51 # Build download string. | |
52 urlbase = "http://downloads.sourceforge.net/octave/%s-%s.tar.gz?download"; | |
53 url = sprintf (urlbase, name, ver); | |
54 ## Verify that the string exists on the page. | |
55 if (isempty (strfind (html, url))) | |
56 warning ("get_forge_pkg: download URL not verified."); | |
57 endif | |
58 endif | |
59 endif | |
60 else | |
61 ## Try get the list of all packages. | |
62 [html, succ] = urlread ("http://octave.sourceforge.net/packages.php"); | |
63 if (succ) | |
64 [~, ~, ~, ~, t] = regexp (html, "<div class=""package"" id=""(\\w+)"">"); | |
65 t = horzcat (t{:}); | |
66 if (any (strcmp (t, name))) | |
67 error ("get_forge_pkg: package name exists, but index page not available"); | |
68 else | |
69 ## Try a simplistic method to determine close names. | |
70 dist = cellfun (@(n) length (setdiff (name, n)), t); | |
71 [~, i] = min (dist); | |
72 error ("get_forge_pkg: package not found: ""%s"". Maybe you meant ""%s?""", name, t{i}); | |
73 endif | |
74 else | |
75 error ("get_forge_pkg: could not read URL, please verify internet connection"); | |
76 endif | |
77 endif | |
78 | |
79 endfunction |