changeset 10685:81a43049dee2

support pkg list -forge
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 07 Jun 2010 13:45:21 +0200
parents 76aba4305f1f
children 8675858ba1e2
files scripts/ChangeLog scripts/pkg/pkg.m
diffstat 2 files changed, 43 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Mon Jun 07 09:57:54 2010 +0200
+++ b/scripts/ChangeLog	Mon Jun 07 13:45:21 2010 +0200
@@ -1,3 +1,7 @@
+2010-06-07  Jaroslav Hajek  <highegg@gmail.com>
+
+	* pkg/pkg.m: Support pkg list -forge.
+
 2010-06-07  Jaroslav Hajek  <highegg@gmail.com>
 
 	* pkg/get_forge_pkg.m: New function.
--- a/scripts/pkg/pkg.m	Mon Jun 07 09:57:54 2010 +0200
+++ b/scripts/pkg/pkg.m	Mon Jun 07 13:45:21 2010 +0200
@@ -270,22 +270,30 @@
     endswitch
   endfor
 
-  if (octave_forge && ! strcmp (action, "install"))
-    error ("-forge can only be used with install");
+  if (octave_forge && ! any (strcmp (action, {"install", "list"})))
+    error ("-forge can only be used with install or list");
   endif
 
   ## Take action
   switch (action)
     case "list"
-      if (nargout == 0)
-        installed_packages (local_list, global_list);
-      elseif (nargout == 1)
-        local_packages = installed_packages (local_list, global_list);
-      elseif (nargout == 2)
-        [local_packages, global_packages] = installed_packages (local_list,
-                                                                global_list);
+      if (octave_forge)
+        if (nargout > 0)
+          local_packages = list_forge_packages ();
+        else
+          list_forge_packages ();
+        endif
       else
-        error ("too many output arguments requested");
+        if (nargout == 0)
+          installed_packages (local_list, global_list);
+        elseif (nargout == 1)
+          local_packages = installed_packages (local_list, global_list);
+        elseif (nargout == 2)
+          [local_packages, global_packages] = installed_packages (local_list,
+                                                                  global_list);
+        else
+          error ("too many output arguments requested");
+        endif
       endif
 
     case "install"
@@ -2329,3 +2337,24 @@
   [ver, url] = get_forge_pkg (name);
   local_file = [name, "-", ver, ".tar.gz"];
 endfunction
+
+function list = list_forge_packages ()
+  [list, succ] = urlread ("http://octave.sourceforge.net/list_packages.php");
+  if (succ)
+    list = strsplit (list, " \n\t", true);
+  else
+    error ("pkg: could not read URL, please verify internet connection");
+  endif
+  if (nargout == 0)
+    page_screen_output (false, "local");
+    puts ("OctaveForge provides these packages:\n");
+    for i = 1:length (list)
+      try
+        ver = get_forge_pkg (list{i});
+      catch
+        ver = "unknown";
+      end_try_catch
+      printf ("  %s %s\n", list{i}, ver);
+    endfor
+  endif
+endfunction