Mercurial > hg > octave-lyh
annotate scripts/pkg/private/get_forge_pkg.m @ 17344:b81b9d079515
Use '##' for comments which stand alone on a line.
* libinterp/corefcn/besselj.cc, libinterp/corefcn/conv2.cc,
libinterp/corefcn/pinv.cc, libinterp/corefcn/rand.cc,
libinterp/corefcn/regexp.cc, libinterp/corefcn/sqrtm.cc,
libinterp/dldfcn/qr.cc, libinterp/parse-tree/pt-eval.cc,
scripts/general/cplxpair.m, scripts/general/repmat.m, scripts/help/doc.m,
scripts/help/doc_cache_create.m, scripts/image/colorcube.m,
scripts/image/hsv2rgb.m, scripts/image/image.m, scripts/io/strread.m,
scripts/io/textscan.m, scripts/miscellaneous/bzip2.m,
scripts/miscellaneous/edit.m, scripts/miscellaneous/gzip.m,
scripts/optimization/__all_opts__.m, scripts/optimization/fminbnd.m,
scripts/optimization/sqp.m, scripts/pkg/private/get_forge_pkg.m,
scripts/plot/area.m, scripts/plot/stemleaf.m, scripts/plot/surfc.m,
scripts/plot/uiresume.m, scripts/plot/zlabel.m, scripts/polynomial/mkpp.m,
scripts/polynomial/ppval.m, scripts/set/intersect.m, scripts/signal/freqz.m,
scripts/sparse/pcg.m, scripts/sparse/pcr.m, scripts/sparse/svds.m,
scripts/sparse/treelayout.m, scripts/specfun/ellipke.m,
scripts/special-matrix/toeplitz.m, scripts/strings/dec2base.m,
scripts/strings/strsplit.m, scripts/testfun/test.m, test/build-sparse-tests.sh,
test/index.tst, test/system.tst:
Use '##' for comments which stand alone on a line.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 28 Aug 2013 08:27:38 -0700 |
parents | abf384f5d243 |
children | 1c89599167a6 |
rev | line source |
---|---|
14473
a46b8b0bd325
doc: Fix the encoding in Søren's name
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14470
diff
changeset
|
1 ## Copyright (C) 2005-2012 Søren Hauberg |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
2 ## Copyright (C) 2010-2012 VZLU Prague, a.s. |
10684 | 3 ## |
11104 | 4 ## This file is part of Octave. |
10684 | 5 ## |
11104 | 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 | |
8 ## the Free Software Foundation; either version 3 of the License, or (at | |
9 ## your option) any later version. | |
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. | |
10684 | 15 ## |
16 ## You should have received a copy of the GNU General Public License | |
11104 | 17 ## along with Octave; see the file COPYING. If not, see |
10684 | 18 ## <http://www.gnu.org/licenses/>. |
19 | |
20 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10684
diff
changeset
|
21 ## @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
|
22 ## Try to discover the current version of an OctaveForge package from the web, |
10684 | 23 ## 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
|
24 ## 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
|
25 ## to download the file. |
10684 | 26 ## @end deftypefn |
27 | |
28 function [ver, url] = get_forge_pkg (name) | |
17184
abf384f5d243
maint: Remove unneeded input validation from internal fcns in private/ directories.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
29 |
10684 | 30 ## Verify that name is valid. |
31 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
|
32 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
|
33 elseif (! all (isalnum (name) | name == "-" | name == "." | name == "_")) |
10684 | 34 error ("get_forge_pkg: invalid package name: %s", name); |
35 endif | |
36 | |
37 name = tolower (name); | |
38 | |
39 ## Try to download package's index page. | |
15965
7ad3eea8a3af
use packages.octave.org instead of sourceforge in pkg.m
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
40 [html, succ] = urlread (sprintf ("http://packages.octave.org/%s/index.html", name)); |
10684 | 41 if (succ) |
42 ## Remove blanks for simpler matching. | |
43 html(isspace(html)) = []; | |
44 ## 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
|
45 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
|
46 t = regexp (html, pat, "tokens"); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14473
diff
changeset
|
47 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
|
48 error ("get_forge_pkg: could not read version number from package's page"); |
10684 | 49 else |
50 ver = t{1}{1}; | |
51 if (nargout > 1) | |
17344
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17184
diff
changeset
|
52 ## Build download string. |
15965
7ad3eea8a3af
use packages.octave.org instead of sourceforge in pkg.m
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
53 pkg_file = sprintf ("%s-%s.tar.gz", name, ver); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
15966
diff
changeset
|
54 url = ["http://packages.octave.org/download/" pkg_file]; |
15965
7ad3eea8a3af
use packages.octave.org instead of sourceforge in pkg.m
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
55 ## Verify that the package string exists on the page. |
7ad3eea8a3af
use packages.octave.org instead of sourceforge in pkg.m
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
56 if (isempty (strfind (html, pkg_file))) |
11588
d5bd2766c640
style fixes for warning and error messages in script files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
57 warning ("get_forge_pkg: download URL not verified"); |
10684 | 58 endif |
59 endif | |
60 endif | |
61 else | |
62 ## Try get the list of all packages. | |
15965
7ad3eea8a3af
use packages.octave.org instead of sourceforge in pkg.m
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
63 [html, succ] = urlread ("http://packages.octave.org/packages.php"); |
10684 | 64 if (succ) |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
10959
diff
changeset
|
65 t = regexp (html, "<div class=""package"" id=""(\\w+)"">", "tokens"); |
10684 | 66 t = horzcat (t{:}); |
67 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
|
68 error ("get_forge_pkg: package NAME exists, but index page not available"); |
10684 | 69 else |
70 ## Try a simplistic method to determine close names. | |
71 dist = cellfun (@(n) length (setdiff (name, n)), t); | |
72 [~, i] = min (dist); | |
73 error ("get_forge_pkg: package not found: ""%s"". Maybe you meant ""%s?""", name, t{i}); | |
74 endif | |
75 else | |
76 error ("get_forge_pkg: could not read URL, please verify internet connection"); | |
77 endif | |
78 endif | |
79 | |
80 endfunction |