Mercurial > octave
annotate scripts/pkg/private/get_forge_pkg.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 2005-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
5 ## |
10684 | 6 ## |
11104 | 7 ## This file is part of Octave. |
10684 | 8 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
11104 | 10 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## (at your option) any later version. |
11104 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
10684 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
11104 | 20 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
10684 | 22 |
23 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
24 ## @deftypefn {} {[@var{ver}, @var{url}] =} get_forge_pkg (@var{name}) |
25841
0d4b88086f36
doc: use "Octave Forge" spelling in a few more instances
Mike Miller <mtmiller@octave.org>
parents:
25054
diff
changeset
|
25 ## Try to discover the current version of an Octave Forge package from the web, |
10684 | 26 ## 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
|
27 ## 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
|
28 ## to download the file. |
10684 | 29 ## @end deftypefn |
30 | |
31 function [ver, url] = get_forge_pkg (name) | |
17176
abf384f5d243
maint: Remove unneeded input validation from internal fcns in private/ directories.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
32 |
10684 | 33 ## Verify that name is valid. |
34 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
|
35 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
|
36 elseif (! all (isalnum (name) | name == "-" | name == "." | name == "_")) |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
37 error ("get_forge_pkg: invalid package NAME: %s", name); |
10684 | 38 endif |
39 | |
40 name = tolower (name); | |
41 | |
42 ## Try to download package's index page. | |
25024
3c817af70eed
maint: use https for all Octave project URLs
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
43 [html, succ] = urlread (sprintf ("https://packages.octave.org/%s/index.html", |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
44 name)); |
10684 | 45 if (succ) |
46 ## Remove blanks for simpler matching. | |
47 html(isspace(html)) = []; | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21246
diff
changeset
|
48 ## 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
|
49 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
|
50 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
|
51 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
|
52 error ("get_forge_pkg: could not read version number from package's page"); |
10684 | 53 else |
54 ver = t{1}{1}; | |
55 if (nargout > 1) | |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17176
diff
changeset
|
56 ## 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
|
57 pkg_file = sprintf ("%s-%s.tar.gz", name, ver); |
25024
3c817af70eed
maint: use https for all Octave project URLs
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
58 url = ["https://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
|
59 ## 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
|
60 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
|
61 warning ("get_forge_pkg: download URL not verified"); |
10684 | 62 endif |
63 endif | |
64 endif | |
65 else | |
66 ## Try get the list of all packages. | |
25024
3c817af70eed
maint: use https for all Octave project URLs
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
67 [html, succ] = urlread ("https://packages.octave.org/list_packages.php"); |
21246
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
68 if (! succ) |
10684 | 69 error ("get_forge_pkg: could not read URL, please verify internet connection"); |
70 endif | |
21246
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
71 t = strsplit (html); |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
72 if (any (strcmp (t, name))) |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
73 error ("get_forge_pkg: package NAME exists, but index page not available"); |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
74 endif |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
75 ## Try a simplistic method to determine similar names. |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
76 function d = fdist (x) |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
77 len1 = length (name); |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
78 len2 = length (x); |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
79 if (len1 <= len2) |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
80 d = sum (abs (name(1:len1) - x(1:len1))) + sum (x(len1+1:end)); |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
81 else |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
82 d = sum (abs (name(1:len2) - x(1:len2))) + sum (name(len2+1:end)); |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
83 endif |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
84 endfunction |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
85 dist = cellfun ("fdist", t); |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
86 [~, i] = min (dist); |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
87 error ("get_forge_pkg: package not found: ""%s"". Maybe you meant ""%s?""", |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
88 name, t{i}); |
10684 | 89 endif |
90 | |
91 endfunction |