annotate scripts/pkg/private/get_forge_pkg.m @ 14138:72c96de7a403 stable

maint: update copyright notices for 2012
author John W. Eaton <jwe@octave.org>
date Mon, 02 Jan 2012 14:25:41 -0500
parents d0b799dafede
children aad7ad0e15c1 7ad3eea8a3af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 12575
diff changeset
1 ## Copyright (C) 2010-2012 VZLU Prague, a.s.
10684
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
2 ##
11104
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
3 ## This file is part of Octave.
10684
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
4 ##
11104
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
6 ## under the terms of the GNU General Public License as published by
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
8 ## your option) any later version.
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
9 ##
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
13 ## General Public License for more details.
10684
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
14 ##
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
11104
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
10684
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
18
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10684
diff changeset
20 ## @deftypefn {Function File} {[@var{ver}, @var{url}] =} get_forge_pkg (@var{name})
12575
d0b799dafede Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents: 12561
diff changeset
21 ## Try to discover the current version of an OctaveForge package from the web,
10684
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
22 ## using a working internet connection and the urlread function.
12575
d0b799dafede Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents: 12561
diff changeset
23 ## If two output arguments are requested, also return an address from which
d0b799dafede Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents: 12561
diff changeset
24 ## to download the file.
10684
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25 ## @end deftypefn
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
26
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
27 function [ver, url] = get_forge_pkg (name)
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
28 if (nargin != 1)
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
29 print_usage ();
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
30 endif
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
31 ## Verify that name is valid.
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
32 if (! (ischar (name) && rows (name) == 1 && ndims (name) == 2))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11104
diff changeset
33 error ("get_forge_pkg: package NAME must be a string");
10959
4f46520e2103 relax check in get_forge_pkg
Jaroslav Hajek <highegg@gmail.com>
parents: 10793
diff changeset
34 elseif (! all (isalnum (name) | name == "-" | name == "." | name == "_"))
10684
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
35 error ("get_forge_pkg: invalid package name: %s", name);
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
36 endif
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
37
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
38 name = tolower (name);
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
39
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
40 ## Try to download package's index page.
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
41 [html, succ] = urlread (sprintf ("http://octave.sourceforge.net/%s/index.html", name));
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
42 if (succ)
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
43 ## Remove blanks for simpler matching.
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
44 html(isspace(html)) = [];
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
45 ## Good. Let's grep for the version.
12468
46b3883d800c fixed typo in PCRE style RE
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12462
diff changeset
46 pat = "<tdclass=""package_table"">PackageVersion:</td><td>([\\d.]*)</td>";
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10959
diff changeset
47 t = regexp (html, pat, "tokens");
10684
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
48 if (isempty (t) || isempty(t{1}))
11588
d5bd2766c640 style fixes for warning and error messages in script files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
49 error ("get_forge_pkg: could not read version number from package's page");
10684
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
50 else
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
51 ver = t{1}{1};
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
52 if (nargout > 1)
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
53 # Build download string.
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54 urlbase = "http://downloads.sourceforge.net/octave/%s-%s.tar.gz?download";
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55 url = sprintf (urlbase, name, ver);
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56 ## Verify that the string exists on the page.
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
57 if (isempty (strfind (html, url)))
11588
d5bd2766c640 style fixes for warning and error messages in script files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
58 warning ("get_forge_pkg: download URL not verified");
10684
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
59 endif
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
60 endif
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
61 endif
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
62 else
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
63 ## Try get the list of all packages.
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
64 [html, succ] = urlread ("http://octave.sourceforge.net/packages.php");
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
65 if (succ)
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10959
diff changeset
66 t = regexp (html, "<div class=""package"" id=""(\\w+)"">", "tokens");
10684
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
67 t = horzcat (t{:});
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
68 if (any (strcmp (t, name)))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11104
diff changeset
69 error ("get_forge_pkg: package NAME exists, but index page not available");
10684
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
70 else
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
71 ## Try a simplistic method to determine close names.
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
72 dist = cellfun (@(n) length (setdiff (name, n)), t);
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
73 [~, i] = min (dist);
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
74 error ("get_forge_pkg: package not found: ""%s"". Maybe you meant ""%s?""", name, t{i});
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
75 endif
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
76 else
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
77 error ("get_forge_pkg: could not read URL, please verify internet connection");
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
78 endif
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
79 endif
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
80
76aba4305f1f support pkg install -forge
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
81 endfunction