Mercurial > octave
annotate scripts/pkg/private/get_forge_pkg.m @ 29358:0a5b15007766 stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2021 09:52:15 -0500 |
parents | bd51beb6205e |
children | 7854d5752dd2 d3298a58049e |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 ## Copyright (C) 2005-2021 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
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
10684 | 7 ## |
11104 | 8 ## This file is part of Octave. |
10684 | 9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
11104 | 11 ## 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
|
12 ## 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
|
13 ## (at your option) any later version. |
11104 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
10684 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
11104 | 21 ## 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
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
10684 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
27 ## @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
|
28 ## Try to discover the current version of an Octave Forge package from the web, |
10684 | 29 ## 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
|
30 ## 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
|
31 ## to download the file. |
10684 | 32 ## @end deftypefn |
33 | |
34 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
|
35 |
10684 | 36 ## Verify that name is valid. |
37 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
|
38 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
|
39 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
|
40 error ("get_forge_pkg: invalid package NAME: %s", name); |
10684 | 41 endif |
42 | |
43 name = tolower (name); | |
44 | |
45 ## 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
|
46 [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
|
47 name)); |
10684 | 48 if (succ) |
49 ## Remove blanks for simpler matching. | |
50 html(isspace(html)) = []; | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21246
diff
changeset
|
51 ## 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
|
52 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
|
53 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
|
54 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
|
55 error ("get_forge_pkg: could not read version number from package's page"); |
10684 | 56 else |
57 ver = t{1}{1}; | |
58 if (nargout > 1) | |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17176
diff
changeset
|
59 ## 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
|
60 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
|
61 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
|
62 ## 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
|
63 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
|
64 warning ("get_forge_pkg: download URL not verified"); |
10684 | 65 endif |
66 endif | |
67 endif | |
68 else | |
69 ## 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
|
70 [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
|
71 if (! succ) |
10684 | 72 error ("get_forge_pkg: could not read URL, please verify internet connection"); |
73 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
|
74 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
|
75 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
|
76 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
|
77 endif |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
78 ## 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 else |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
85 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
|
86 endif |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
87 endfunction |
101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
88 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
|
89 [~, 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
|
90 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
|
91 name, t{i}); |
10684 | 92 endif |
93 | |
94 endfunction |