Mercurial > octave
comparison scripts/pkg/pkg.m @ 6203:512d72ee321f
[project @ 2006-12-06 18:00:13 by jwe]
author | jwe |
---|---|
date | Wed, 06 Dec 2006 18:00:13 +0000 |
parents | 0d23b0c0ce1a |
children | a299c8a6d96e |
comparison
equal
deleted
inserted
replaced
6202:e5ed0d1edddc | 6203:512d72ee321f |
---|---|
52 ## adds the @code{image} package to the path. It is possible to load all | 52 ## adds the @code{image} package to the path. It is possible to load all |
53 ## installed packages at once with the command | 53 ## installed packages at once with the command |
54 ## @example | 54 ## @example |
55 ## pkg load all | 55 ## pkg load all |
56 ## @end example | 56 ## @end example |
57 ## @item unload | |
58 ## Removes named packages from the path. After unloading a package it is | |
59 ## no longer possible to use the functions provided by the package. | |
60 ## This command behaves like the @code{load} command. | |
57 ## @item list | 61 ## @item list |
58 ## Show a list of the currently installed packages. By requesting one or two | 62 ## Show a list of the currently installed packages. By requesting one or two |
59 ## output argument it is possible to get a list of the currently installed | 63 ## output argument it is possible to get a list of the currently installed |
60 ## packages. For example, | 64 ## packages. For example, |
61 ## @example | 65 ## @example |
135 action = "none"; | 139 action = "none"; |
136 for i = 1:length(varargin) | 140 for i = 1:length(varargin) |
137 switch (varargin{i}) | 141 switch (varargin{i}) |
138 case "-nodeps" | 142 case "-nodeps" |
139 deps = false; | 143 deps = false; |
140 case {"list", "install", "uninstall", "load", "prefix", "local_list", "global_list"} | 144 case {"list", "install", "uninstall", "load", "unload", ... |
145 "prefix", "local_list", "global_list"} | |
141 action = varargin{i}; | 146 action = varargin{i}; |
142 otherwise | 147 otherwise |
143 files{end+1} = varargin{i}; | 148 files{end+1} = varargin{i}; |
144 endswitch | 149 endswitch |
145 endfor | 150 endfor |
169 case "load" | 174 case "load" |
170 if (length(files) == 0) | 175 if (length(files) == 0) |
171 error("You must specify at least one package or 'all' when calling 'pkg load'"); | 176 error("You must specify at least one package or 'all' when calling 'pkg load'"); |
172 endif | 177 endif |
173 load_packages(files, deps, local_list, global_list); | 178 load_packages(files, deps, local_list, global_list); |
179 case "unload" | |
180 if (length(files) == 0) | |
181 error("You must specify at least one package or 'all' when calling 'pkg unload'"); | |
182 endif | |
183 unload_packages(files, deps, local_list, global_list); | |
174 case "prefix" | 184 case "prefix" |
175 if (length(files) == 0 && nargout == 0) | 185 if (length(files) == 0 && nargout == 0) |
176 disp(prefix); | 186 disp(prefix); |
177 elseif (length(files) == 0 && nargout == 1) | 187 elseif (length(files) == 0 && nargout == 1) |
178 local_packages = prefix; | 188 local_packages = prefix; |
1166 EXEC_PATH ([dirs{i} "/bin:" EXEC_PATH()]); | 1176 EXEC_PATH ([dirs{i} "/bin:" EXEC_PATH()]); |
1167 endif | 1177 endif |
1168 endfor | 1178 endfor |
1169 endfunction | 1179 endfunction |
1170 | 1180 |
1181 function unload_packages(files, handle_deps, local_list, global_list) | |
1182 installed_packages = installed_packages(local_list, global_list); | |
1183 num_packages = length(installed_packages); | |
1184 | |
1185 ## Read package names and installdirs into a more convenient format | |
1186 pnames = pdirs = cell(1, num_packages); | |
1187 for i = 1:num_packages | |
1188 pnames{i} = installed_packages{i}.name; | |
1189 pdirs{i} = installed_packages{i}.dir; | |
1190 pdeps{i} = installed_packages{i}.depends; | |
1191 endfor | |
1192 | |
1193 ## Get the current octave path | |
1194 p = split_by(path(), pathsep()); | |
1195 | |
1196 ## unload all | |
1197 if (length(files) == 1 && strcmp(files{1}, "all")) | |
1198 dirs = pdirs; | |
1199 ## unload package_name1 ... | |
1200 else | |
1201 dirs = {}; | |
1202 for i = 1:length(files) | |
1203 idx = strcmp(pnames, files{i}); | |
1204 if (!any(idx)) | |
1205 error("Package %s is not installed", files{i}); | |
1206 endif | |
1207 dirs{end+1} = pdirs{idx}; | |
1208 endfor | |
1209 endif | |
1210 | |
1211 ## Unload the packages | |
1212 for i = 1:length(dirs) | |
1213 d = dirs{i}; | |
1214 idx = strcmp(p, d); | |
1215 if (any(idx)) | |
1216 rmpath(d); | |
1217 # XXX: We should also check if we need to remove items from EXEC_PATH | |
1218 endif | |
1219 endfor | |
1220 endfunction | |
1221 | |
1171 function [status_out, msg_out] = rm_rf (dir) | 1222 function [status_out, msg_out] = rm_rf (dir) |
1172 crr = confirm_recursive_rmdir (); | 1223 crr = confirm_recursive_rmdir (); |
1173 unwind_protect | 1224 unwind_protect |
1174 confirm_recursive_rmdir (false); | 1225 confirm_recursive_rmdir (false); |
1175 [status, msg] = rmdir (dir, "s"); | 1226 [status, msg] = rmdir (dir, "s"); |