changeset 6203:512d72ee321f

[project @ 2006-12-06 18:00:13 by jwe]
author jwe
date Wed, 06 Dec 2006 18:00:13 +0000
parents e5ed0d1edddc
children 9795a2091f7f
files scripts/ChangeLog scripts/pkg/pkg.m scripts/plot/__errplot__.m
diffstat 3 files changed, 60 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Tue Dec 05 21:49:45 2006 +0000
+++ b/scripts/ChangeLog	Wed Dec 06 18:00:13 2006 +0000
@@ -1,3 +1,10 @@
+2006-12-06  Søren Hauberg  <hauberg@gmail.com>
+
+	* pkg/pkg.m (unload_packages): New function.
+	(pkg): Handle unload action.
+
+	* __errplot__.m: Add missing semicolon.
+
 2006-11-30  John W. Eaton  <jwe@octave.org>
 
 	* miscellaneous/mexext.m: New file.
--- a/scripts/pkg/pkg.m	Tue Dec 05 21:49:45 2006 +0000
+++ b/scripts/pkg/pkg.m	Wed Dec 06 18:00:13 2006 +0000
@@ -54,6 +54,10 @@
 ## @example
 ## pkg load all
 ## @end example
+## @item unload
+## Removes named packages from the path. After unloading a package it is
+## no longer possible to use the functions provided by the package.
+## This command behaves like the @code{load} command.
 ## @item list
 ## Show a list of the currently installed packages. By requesting one or two
 ## output argument it is possible to get a list of the currently installed
@@ -137,7 +141,8 @@
         switch (varargin{i})
             case "-nodeps"
                 deps = false;
-            case {"list", "install", "uninstall", "load", "prefix", "local_list", "global_list"}
+            case {"list", "install", "uninstall", "load", "unload", ...
+                  "prefix", "local_list", "global_list"}
                 action = varargin{i};
             otherwise
                 files{end+1} = varargin{i};
@@ -171,6 +176,11 @@
                 error("You must specify at least one package or 'all' when calling 'pkg load'");
             endif
             load_packages(files, deps, local_list, global_list);
+        case "unload"
+            if (length(files) == 0)
+                error("You must specify at least one package or 'all' when calling 'pkg unload'");
+            endif
+            unload_packages(files, deps, local_list, global_list);
         case "prefix"
             if (length(files) == 0 && nargout == 0)
                 disp(prefix);
@@ -1168,6 +1178,47 @@
     endfor
 endfunction
 
+function unload_packages(files, handle_deps, local_list, global_list)
+    installed_packages = installed_packages(local_list, global_list);
+    num_packages = length(installed_packages);
+    
+    ## Read package names and installdirs into a more convenient format
+    pnames = pdirs = cell(1, num_packages);
+    for i = 1:num_packages
+        pnames{i} = installed_packages{i}.name;
+        pdirs{i} = installed_packages{i}.dir;
+        pdeps{i} = installed_packages{i}.depends;
+    endfor
+    
+    ## Get the current octave path
+    p = split_by(path(), pathsep());
+
+    ## unload all
+    if (length(files) == 1 && strcmp(files{1}, "all"))
+        dirs = pdirs;
+    ## unload package_name1 ...
+    else
+        dirs = {};
+        for i = 1:length(files)
+            idx = strcmp(pnames, files{i});
+            if (!any(idx))
+                error("Package %s is not installed", files{i});
+            endif
+            dirs{end+1} = pdirs{idx};
+        endfor
+    endif
+
+    ## Unload the packages
+    for i = 1:length(dirs)
+        d = dirs{i};
+        idx = strcmp(p, d);
+        if (any(idx))
+            rmpath(d);
+            # XXX: We should also check if we need to remove items from EXEC_PATH
+        endif
+    endfor
+endfunction
+
 function [status_out, msg_out] = rm_rf (dir)
   crr = confirm_recursive_rmdir ();
   unwind_protect
--- a/scripts/plot/__errplot__.m	Tue Dec 05 21:49:45 2006 +0000
+++ b/scripts/plot/__errplot__.m	Wed Dec 06 18:00:13 2006 +0000
@@ -54,7 +54,7 @@
   [len, nplots] = size (a1);
 
   for i = 1:nplots
-    ifmt = fmt{1+mod(i-1,numel(fmt))}
+    ifmt = fmt{1+mod(i-1,numel(fmt))};
     switch (nargin - 1)
       case 2
 	tmp = [(1:len)', a1(:,i), a2(:,i)];