Mercurial > hg > octave-shane
changeset 10684:76aba4305f1f
support pkg install -forge
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 07 Jun 2010 09:57:54 +0200 |
parents | 4fdb36ffa066 |
children | 81a43049dee2 |
files | scripts/ChangeLog scripts/pkg/get_forge_pkg.m scripts/pkg/module.mk scripts/pkg/pkg.m |
diffstat | 4 files changed, 120 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,10 @@ +2010-06-07 Jaroslav Hajek <highegg@gmail.com> + + * pkg/get_forge_pkg.m: New function. + * pkg/module.mk: Add it here. + * pkg/pkg.m: Support -forge switch for auto-downloading OctaveForge + packages. + 2010-06-03 Alois Schlögl * signal/arch_test.m, statistics/tests/bartlett_test.m,
new file mode 100644 --- /dev/null +++ b/scripts/pkg/get_forge_pkg.m @@ -0,0 +1,78 @@ +## Copyright (C) 2010 VZLU Prague, a.s. +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn{Function File} {[@var{ver}, @var{url}] =} get_forge_pkg (@var{name}) +## Tries to discover the current version of an OctaveForge package from the web, +## using a working internet connection and the urlread function. +## If two output arguments are requested, returns also an address to download the file. +## @end deftypefn + +function [ver, url] = get_forge_pkg (name) + if (nargin != 1) + print_usage (); + endif + ## Verify that name is valid. + if (! (ischar (name) && rows (name) == 1 && ndims (name) == 2)) + error ("get_forge_pkg: package name must be a string"); + elseif (! all (isalnum (name) | name == "-" | name == ".")) + error ("get_forge_pkg: invalid package name: %s", name); + endif + + name = tolower (name); + + ## Try to download package's index page. + [html, succ] = urlread (sprintf ("http://octave.sourceforge.net/%s/index.html", name)); + if (succ) + ## Remove blanks for simpler matching. + html(isspace(html)) = []; + ## Good. Let's grep for the version. + pat = "<tdclass=""package_table"">PackageVersion:</td><td>([0-9\\.]*)</td>"; + [~, ~, ~, ~, t] = regexp (html, pat); + if (isempty (t) || isempty(t{1})) + error ("get_forge_pkg: could not read version number from package's page."); + else + ver = t{1}{1}; + if (nargout > 1) + # Build download string. + urlbase = "http://downloads.sourceforge.net/octave/%s-%s.tar.gz?download"; + url = sprintf (urlbase, name, ver); + ## Verify that the string exists on the page. + if (isempty (strfind (html, url))) + warning ("get_forge_pkg: download URL not verified."); + endif + endif + endif + else + ## Try get the list of all packages. + [html, succ] = urlread ("http://octave.sourceforge.net/packages.php"); + if (succ) + [~, ~, ~, ~, t] = regexp (html, "<div class=""package"" id=""(\\w+)"">"); + t = horzcat (t{:}); + if (any (strcmp (t, name))) + error ("get_forge_pkg: package name exists, but index page not available"); + else + ## Try a simplistic method to determine close names. + dist = cellfun (@(n) length (setdiff (name, n)), t); + [~, i] = min (dist); + error ("get_forge_pkg: package not found: ""%s"". Maybe you meant ""%s?""", name, t{i}); + endif + else + error ("get_forge_pkg: could not read URL, please verify internet connection"); + endif + endif + +endfunction
--- a/scripts/pkg/module.mk +++ b/scripts/pkg/module.mk @@ -1,7 +1,8 @@ FCN_FILE_DIRS += pkg pkg_FCN_FILES = \ - pkg/pkg.m + pkg/pkg.m \ + pkg/get_forge_pkg.m FCN_FILES += $(pkg_FCN_FILES)
--- a/scripts/pkg/pkg.m +++ b/scripts/pkg/pkg.m @@ -1,4 +1,5 @@ ## Copyright (C) 2005, 2006, 2007, 2008, 2009 S�ren Hauberg +## Copyright (C) 2010 VZLU Prague, a.s. ## ## This file is part of Octave. ## @@ -232,6 +233,7 @@ auto = 0; action = "none"; verbose = false; + octave_forge = false; for i = 1:length (varargin) switch (varargin{i}) case "-nodeps" @@ -242,6 +244,8 @@ auto = 1; case "-verbose" verbose = true; + case "-forge" + octave_forge = true; case "-local" global_install = false; if (! user_prefix) @@ -266,6 +270,10 @@ endswitch endfor + if (octave_forge && ! strcmp (action, "install")) + error ("-forge can only be used with install"); + endif + ## Take action switch (action) case "list" @@ -284,8 +292,26 @@ if (length (files) == 0) error ("you must specify at least one filename when calling 'pkg install'"); endif - install (files, deps, auto, prefix, archprefix, verbose, local_list, - global_list, global_install); + + local_files = {}; + unwind_protect + + if (octave_forge) + [urls, local_files] = cellfun (@get_forge_download, files, "uniformoutput", false); + [files, succ] = cellfun (@urlwrite, urls, local_files, "uniformoutput", false); + succ = [succ{:}]; + if (! all (succ)) + i = find (! succ, 1); + error ("could not download file %s from url %s", local_files{i}, urls{i}); + endif + endif + + install (files, deps, auto, prefix, archprefix, verbose, local_list, + global_list, global_install); + + unwind_protect_cleanup + cellfun (@unlink, local_files); + end_unwind_protect case "uninstall" if (length (files) == 0) @@ -2298,3 +2324,8 @@ endif endfor endfunction + +function [url, local_file] = get_forge_download (name) + [ver, url] = get_forge_pkg (name); + local_file = [name, "-", ver, ".tar.gz"]; +endfunction