5801
|
1 ## Copyright (C) 2005 S�ren Hauberg |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
|
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 ## -*- texinfo -*- |
6032
|
18 ## @deftypefn {Command} pkg @var{command} @var{pkg_name} |
|
19 ## @deftypefnx {Command} pkg @var{command} @var{option} @var{pkg_name} |
|
20 ## This command interacts with the package manager. Different actions will |
|
21 ## be taking depending on the value of @var{command}. |
|
22 ## |
|
23 ## @table @samp |
|
24 ## @item install |
6033
|
25 ## Install named packages. For example, |
6032
|
26 ## @example |
|
27 ## pkg install image-1.0.0.tar.gz |
|
28 ## @end example |
|
29 ## @noindent |
6033
|
30 ## installs the package found in the file @code{image-1.0.0.tar.gz}. |
6032
|
31 ## |
|
32 ## If @var{option} is @code{-nodeps} the package manager will disable the |
|
33 ## dependency checking. That way it is possible to install a package even |
|
34 ## if it depends on another package that's not installed on the system. |
|
35 ## @strong{Use this option with care.} |
|
36 ## @item uninstall |
6033
|
37 ## Uninstall named packages. For example, |
6032
|
38 ## @example |
|
39 ## pkg uninstall image |
|
40 ## @end example |
|
41 ## @noindent |
6033
|
42 ## removes the @code{image} package from the system. If another installed |
6032
|
43 ## package depends on the @code{image} package an error will be issued. |
|
44 ## The package can be uninstalled anyway by using the @code{-nodeps} option. |
|
45 ## @item load |
6033
|
46 ## Add named packages to the path. After loading a package it is |
|
47 ## possible to use the functions provided by the package. For example, |
6032
|
48 ## @example |
|
49 ## pkg load image |
|
50 ## @end example |
|
51 ## @noindent |
6033
|
52 ## adds the @code{image} package to the path. It is possible to load all |
|
53 ## installed packages at once with the command |
6032
|
54 ## @example |
|
55 ## pkg load all |
|
56 ## @end example |
|
57 ## @item list |
6033
|
58 ## Show a list of the currently installed packages. By requesting one or two |
6032
|
59 ## output argument it is possible to get a list of the currently installed |
6033
|
60 ## packages. For example, |
6032
|
61 ## @example |
|
62 ## installed_packages = pkg list; |
|
63 ## @end example |
|
64 ## @noindent |
6033
|
65 ## returns a cell array containing a structure for each installed package. |
6032
|
66 ## The command |
|
67 ## @example |
|
68 ## [@var{user_packages}, @var{system_packages}] = pkg list |
|
69 ## @end example |
|
70 ## @noindent |
6033
|
71 ## splits the list of installed packages into those who are installed by |
6032
|
72 ## the current user, and those installed by the system administrator. |
6034
|
73 ## @item prefix |
|
74 ## Set the installation prefix directory. For example, |
|
75 ## @example |
|
76 ## pkg prefix ~/my_octave_packages |
|
77 ## @end example |
|
78 ## @noindent |
|
79 ## sets the installation prefix to @code{~/my_octave_packages}. |
|
80 ## Packages will be installed in this directory. |
|
81 ## |
|
82 ## It is possible to get the current installation prefix by requesting an |
|
83 ## output argument. For example, |
|
84 ## @example |
|
85 ## p = pkg prefix |
|
86 ## @end example |
6032
|
87 ## @end table |
5801
|
88 ## @end deftypefn |
5947
|
89 |
|
90 ## PKG_ADD: mark_as_command pkg |
|
91 |
5801
|
92 function [local_packages, global_packages] = pkg(varargin) |
6034
|
93 ## Installation prefix |
|
94 persistent prefix = -1; |
|
95 if (prefix == -1) |
|
96 if (issuperuser()) |
|
97 ## XXX: Is this really needed? |
|
98 if (strcmp(OCTAVE_HOME()(end),"/")) |
|
99 prefix = [OCTAVE_HOME "share/octave/packages/"]; |
|
100 else |
|
101 prefix = [OCTAVE_HOME "/share/octave/packages/"]; |
|
102 endif |
|
103 else |
|
104 prefix = "~/octave/"; |
|
105 endif |
|
106 endif |
|
107 prefix = tilde_expand(prefix); |
|
108 |
5801
|
109 ## Handle input |
|
110 if (length(varargin) == 0 || !iscellstr(varargin)) |
5928
|
111 print_usage(); |
5801
|
112 endif |
|
113 files = {}; |
|
114 deps = true; |
|
115 action = "none"; |
|
116 for i = 1:length(varargin) |
|
117 switch (varargin{i}) |
|
118 case "-nodeps" |
|
119 deps = false; |
6034
|
120 case {"list", "install", "uninstall", "load", "prefix"} |
5801
|
121 action = varargin{i}; |
|
122 otherwise |
|
123 files{end+1} = varargin{i}; |
|
124 endswitch |
|
125 endfor |
|
126 |
|
127 ## Take action |
|
128 switch (action) |
|
129 case "list" |
|
130 if (nargout == 0) |
|
131 installed_packages(); |
|
132 elseif (nargout == 1) |
|
133 local_packages = installed_packages(); |
|
134 elseif (nargout == 2) |
|
135 [local_packages, global_packages] = installed_packages(); |
|
136 else |
|
137 error("Too many output arguments requested.\n"); |
|
138 endif |
|
139 case "install" |
|
140 if (length(files) == 0) |
|
141 error("You must specify at least one filename when calling 'pkg install'\n"); |
|
142 endif |
6034
|
143 install(files, deps, prefix); |
5801
|
144 case "uninstall" |
|
145 if (length(files) == 0) |
|
146 error("You must specify at least one package when calling 'pkg uninstall'\n"); |
|
147 endif |
|
148 uninstall(files, deps); |
|
149 case "load" |
|
150 if (length(files) == 0) |
|
151 error("You must specify at least one package or 'all' when calling 'pkg load'\n"); |
|
152 endif |
|
153 load_packages(files, deps); |
6034
|
154 case "prefix" |
|
155 if (length(files) == 0 && nargout == 0) |
6035
|
156 disp(prefix); |
6034
|
157 elseif (length(files) == 0 && nargout == 1) |
|
158 local_packages = prefix; |
|
159 elseif (length(files) == 1 && nargout == 0 && ischar(files{1})) |
|
160 prefix = files{1}; |
|
161 if (!strcmp(prefix(end), "/")) prefix(end+1) = "/"; endif |
|
162 else |
|
163 error("You must specify a prefix directory, or request an output arguement"); |
|
164 endif |
5801
|
165 otherwise |
|
166 error("You must specify a valid action for 'pkg'. See 'help pkg' for details\n"); |
|
167 endswitch |
|
168 endfunction |
|
169 |
6034
|
170 function install(files, handle_deps, prefix) |
5801
|
171 ## Set parameters depending on wether or not the installation |
|
172 ## is system-wide (global) or local. |
|
173 local_list = tilde_expand("~/.octave_packages"); |
5974
|
174 if (strcmp(OCTAVE_HOME()(end),"/")) |
6034
|
175 global_list = [OCTAVE_HOME "share/octave/octave_packages"]; |
5974
|
176 else |
6034
|
177 global_list = [OCTAVE_HOME "/share/octave/octave_packages"]; |
5974
|
178 endif |
6034
|
179 |
|
180 global_install = issuperuser(); |
5801
|
181 |
|
182 # Check that the directory in prefix exist. If it doesn't: create it! |
|
183 if (!exist(prefix, "dir")) |
|
184 warning("Creating installation directory %s", prefix); |
|
185 [status, msg] = mkdir(prefix); |
|
186 if (status != 1) |
|
187 error("Could not create installation directory: %s\n", msg); |
|
188 endif |
|
189 endif |
|
190 |
|
191 ## Get the list of installed packages |
|
192 [local_packages, global_packages] = installed_packages(); |
|
193 installed_packages = {local_packages{:} global_packages{:}}; |
|
194 |
|
195 if (global_install) |
|
196 packages = global_packages; |
|
197 else |
|
198 packages = local_packages; |
|
199 endif |
|
200 |
|
201 ## Uncompress the packages and read the DESCRIPTION files |
5947
|
202 tmpdirs = packdirs = descriptions = {}; |
5801
|
203 try |
|
204 ## Unpack the package files and read the DESCRIPTION files |
|
205 packages_to_uninstall = []; |
|
206 for i = 1:length(files) |
|
207 tgz = files{i}; |
|
208 |
|
209 ## Create a temporary directory |
|
210 tmpdir = tmpnam(); |
5947
|
211 tmpdirs{end+1} = tmpdir; |
5801
|
212 [status, msg] = mkdir(tmpdir); |
|
213 if (status != 1) |
|
214 error("Couldn't create temporary directory: %s\n", msg); |
|
215 endif |
|
216 |
|
217 ## Uncompress the package |
|
218 untar(tgz, tmpdir); |
5928
|
219 |
5947
|
220 ## Get the name of the directories produced by tar |
5801
|
221 [dirlist, err, msg] = readdir(tmpdir); |
|
222 if (err) |
|
223 error("Couldn't read directory produced by tar: %s\n", msg); |
|
224 endif |
5987
|
225 |
|
226 if (length(dirlist) > 3) |
|
227 error("Bundles of packages are not allowed") |
|
228 endif |
5947
|
229 |
|
230 for k = 3:length(dirlist) # the two first entries of dirlist are "." and ".." |
|
231 packdir = [tmpdir "/" dirlist{k} "/"]; |
|
232 packdirs{end+1} = packdir; |
5801
|
233 |
5947
|
234 ## Make sure the package contains necessary files |
|
235 verify_directory(packdir); |
5928
|
236 |
5947
|
237 ## Read the DESCRIPTION file |
|
238 filename = [packdir "DESCRIPTION"]; |
|
239 desc = get_description(filename); |
5928
|
240 |
5971
|
241 ## Verify that package name corresponds with filename |
|
242 [dummy, nm] = fileparts(tgz); |
|
243 if ((length(nm) >= length(desc.name)) && |
|
244 ! strcmp(desc.name,nm(1:length(desc.name)))) |
5987
|
245 error(["Package name '",desc.name,"' doesn't correspond", |
|
246 "to its filename '",nm,"'"]); |
5971
|
247 endif |
|
248 |
5947
|
249 ## Set default installation directory |
|
250 desc.dir = [prefix "/" desc.name "-" desc.version]; |
5801
|
251 |
5947
|
252 ## Save desc |
|
253 descriptions{end+1} = desc; |
5801
|
254 |
5947
|
255 ## Are any of the new packages already installed? |
|
256 ## If so we'll remove the old version. |
|
257 for j = 1:length(packages) |
|
258 if (strcmp(packages{j}.name, desc.name)) |
|
259 packages_to_uninstall(end+1) = j; |
|
260 endif |
|
261 endfor |
|
262 endfor |
5801
|
263 endfor |
|
264 catch |
|
265 ## Something went wrong, delete tmpdirs |
|
266 for i = 1:length(tmpdirs) |
5928
|
267 rm_rf(tmpdirs{i}); |
5801
|
268 endfor |
|
269 error(lasterr()(8:end)); |
|
270 end_try_catch |
|
271 |
|
272 ## Check dependencies |
|
273 if (handle_deps) |
|
274 ok = true; |
|
275 error_text = ""; |
|
276 for i = 1:length(descriptions) |
|
277 desc = descriptions{i}; |
|
278 idx1 = complement(packages_to_uninstall, 1:length(installed_packages)); |
|
279 idx2 = complement(i, 1:length(descriptions)); |
|
280 pseudo_installed_packages = {installed_packages{idx1} descriptions{idx2}}; |
|
281 bad_deps = get_unsatisfied_deps(desc, pseudo_installed_packages); |
|
282 ## Are there any unsatisfied dependencies? |
|
283 if (!isempty(bad_deps)) |
|
284 ok = false; |
|
285 for i = 1:length(bad_deps) |
|
286 dep = bad_deps{i}; |
|
287 error_text = [error_text " " desc.name " needs " ... |
|
288 dep.package " " dep.operator " " ... |
|
289 dep.version "\n"]; |
|
290 endfor |
|
291 endif |
|
292 endfor |
|
293 |
|
294 ## Did we find any unsatisfied dependencies? |
|
295 if (!ok) |
|
296 error("The following dependencies where unsatisfied:\n %s", error_text); |
|
297 endif |
|
298 endif |
|
299 |
|
300 ## Prepare each package for installation |
|
301 try |
|
302 for i = 1:length(descriptions) |
|
303 desc = descriptions{i}; |
|
304 pdir = packdirs{i}; |
|
305 prepare_installation (desc, pdir); |
|
306 configure_make (desc, pdir); |
|
307 endfor |
|
308 catch |
|
309 ## Something went wrong, delete tmpdirs |
|
310 for i = 1:length(tmpdirs) |
5928
|
311 rm_rf(tmpdirs{i}); |
5801
|
312 endfor |
|
313 error(lasterr()(8:end)); |
|
314 end_try_catch |
|
315 |
|
316 ## Uninstall the packages that will be replaced |
|
317 try |
|
318 for i = packages_to_uninstall |
|
319 uninstall({installed_packages{i}.name}, false); |
|
320 endfor |
|
321 catch |
|
322 ## Something went wrong, delete tmpdirs |
|
323 for i = 1:length(tmpdirs) |
5928
|
324 rm_rf(tmpdirs{i}); |
5801
|
325 endfor |
|
326 error(lasterr()(8:end)); |
|
327 end_try_catch |
|
328 |
|
329 ## Install each package |
|
330 try |
|
331 for i = 1:length(descriptions) |
|
332 desc = descriptions{i}; |
|
333 pdir = packdirs{i}; |
5971
|
334 copy_files(desc, pdir); |
|
335 create_pkgadddel(desc, pdir, "PKG_ADD"); |
|
336 create_pkgadddel(desc, pdir, "PKG_DEL"); |
5801
|
337 finish_installation (desc, pdir) |
|
338 endfor |
|
339 catch |
|
340 ## Something went wrong, delete tmpdirs |
|
341 for i = 1:length(tmpdirs) |
5928
|
342 rm_rf(tmpdirs{i}); |
5801
|
343 endfor |
5971
|
344 for i = 1:length(descriptions) |
|
345 rm_rf(descriptions{i}.dir); |
|
346 endfor |
5801
|
347 error(lasterr()(8:end)); |
|
348 end_try_catch |
|
349 |
5971
|
350 ## Check if the installed directory is empty. If it is remove it |
|
351 ## from the list |
|
352 for i = length(descriptions):-1:1 |
|
353 if (dirempty(descriptions{i}.dir,{"packinfo","doc"})) |
|
354 rm_rf(descriptions{i}.dir); |
|
355 descriptions(i) = []; |
|
356 endif |
|
357 endfor |
|
358 |
|
359 ## Add the packages to the package list |
5801
|
360 try |
|
361 if (global_install) |
|
362 idx = complement(packages_to_uninstall, 1:length(global_packages)); |
|
363 global_packages = {global_packages{idx} descriptions{:}}; |
|
364 save(global_list, "global_packages"); |
|
365 else |
|
366 idx = complement(packages_to_uninstall, 1:length(local_packages)); |
|
367 local_packages = {local_packages{idx} descriptions{:}}; |
|
368 save(local_list, "local_packages"); |
|
369 endif |
|
370 catch |
|
371 ## Something went wrong, delete tmpdirs |
|
372 for i = 1:length(tmpdirs) |
5928
|
373 rm_rf(tmpdirs{i}); |
5801
|
374 endfor |
|
375 for i = 1:length(descriptions) |
5928
|
376 rm_rf(descriptions{i}.dir); |
5801
|
377 endfor |
|
378 if (global_install) |
|
379 error("Couldn't append to %s: %s\n", global_list, lasterr()(8:end)); |
|
380 else |
|
381 error("Couldn't append to %s: %s\n", local_list, lasterr()(8:end)); |
|
382 endif |
|
383 end_try_catch |
|
384 |
|
385 ## All is well, let's clean up |
|
386 for i = 1:length(tmpdirs) |
5928
|
387 [status, msg] = rm_rf(tmpdirs{i}); |
5801
|
388 if (status != 1) |
|
389 warning("Couldn't clean up after my self: %s\n", msg); |
|
390 endif |
|
391 endfor |
|
392 |
|
393 ## Add the newly installed packages to the path, so the user |
5971
|
394 ## can begin usings them. |
|
395 if (length(descriptions) > 0) |
|
396 dirs = cell(1, length(descriptions)); |
|
397 for i = 1:length(descriptions) |
5801
|
398 dirs{i} = descriptions{i}.dir; |
5971
|
399 endfor |
|
400 addpath(dirs{:}); |
|
401 endif |
5801
|
402 endfunction |
|
403 |
|
404 function uninstall(pkgnames, handle_deps) |
|
405 local_list = tilde_expand("~/.octave_packages"); |
5974
|
406 if (strcmp(OCTAVE_HOME()(end),"/")) |
|
407 global_list = [OCTAVE_HOME "share/octave/octave_packages"]; |
|
408 else |
|
409 global_list = [OCTAVE_HOME "/share/octave/octave_packages"]; |
|
410 endif |
5801
|
411 ## Get the list of installed packages |
|
412 [local_packages, global_packages] = installed_packages(); |
|
413 if (issuperuser()) |
|
414 installed_packages = global_packages; |
|
415 else |
|
416 installed_packages = local_packages; |
|
417 endif |
|
418 |
|
419 num_packages = length(installed_packages); |
|
420 delete_idx = []; |
|
421 for i = 1:num_packages |
|
422 cur_name = installed_packages{i}.name; |
|
423 if (any(strcmp(cur_name, pkgnames))) |
|
424 delete_idx(end+1) = i; |
|
425 endif |
|
426 endfor |
|
427 |
|
428 ## Are all the packages that should be uninstalled already installed? |
|
429 if (length(delete_idx) != length(pkgnames)) |
|
430 # XXX: We should have a better error message |
|
431 error("Some of the packages you want to uninstall are not installed.\n"); |
|
432 endif |
|
433 |
|
434 ## Compute the packages that will remain installed |
|
435 idx = complement(delete_idx, 1:num_packages); |
|
436 remaining_packages = {installed_packages{idx}}; |
|
437 |
|
438 ## Check dependencies |
|
439 if (handle_deps) |
|
440 ok = true; |
|
441 error_text = ""; |
|
442 for i = 1:length(remaining_packages) |
|
443 desc = remaining_packages{i}; |
|
444 bad_deps = get_unsatisfied_deps(desc, remaining_packages); |
|
445 |
|
446 ## Will the uninstallation break any dependencies? |
|
447 if (!isempty(bad_deps)) |
|
448 ok = false; |
|
449 for i = 1:length(bad_deps) |
|
450 dep = bad_deps{i}; |
|
451 error_text = [error_text " " desc.name " needs " ... |
|
452 dep.package " " dep.operator " " ... |
|
453 dep.version "\n"]; |
|
454 endfor |
|
455 endif |
|
456 endfor |
|
457 |
|
458 if (!ok) |
|
459 error("The following dependencies where unsatisfied:\n %s", error_text); |
|
460 endif |
|
461 endif |
|
462 |
|
463 ## Delete the directories containing the packages |
|
464 for i = delete_idx |
|
465 desc = installed_packages{i}; |
|
466 ## If an 'on_uninstall.m' exist, call it! |
|
467 if (exist([desc.dir "/packinfo/on_uninstall.m"], "file")) |
|
468 try |
|
469 wd = pwd(); |
|
470 cd([desc.dir "/packinfo"]); |
|
471 on_uninstall(desc); |
|
472 cd(wd); |
|
473 catch |
|
474 # XXX: Should this rather be an error? |
|
475 warning("The 'on_uninstall' script returned the following error: %s", lasterr); |
|
476 cd(wd); |
|
477 end_try_catch |
|
478 endif |
|
479 ## Do the actual deletion |
5928
|
480 rmpath(desc.dir); |
|
481 [status, msg] = rm_rf(desc.dir); |
5801
|
482 if (status != 1) |
|
483 error("Couldn't delete directory %s: %s\n", desc.dir, msg); |
|
484 endif |
|
485 endfor |
|
486 |
|
487 ## Write a new ~/.octave_packages |
|
488 if (issuperuser()) |
|
489 if (length(remaining_packages) == 0) |
|
490 unlink(global_list); |
|
491 else |
|
492 global_packages = remaining_packages; |
|
493 save(global_list, "global_packages"); |
|
494 endif |
|
495 else |
|
496 if (length(remaining_packages) == 0) |
|
497 unlink(local_list); |
|
498 else |
|
499 local_packages = remaining_packages; |
|
500 save(local_list, "local_packages"); |
|
501 endif |
|
502 endif |
|
503 |
|
504 endfunction |
|
505 |
|
506 ########################################################## |
|
507 ## A U X I L A R Y F U N C T I O N S ## |
|
508 ########################################################## |
|
509 |
|
510 function prepare_installation(desc, packdir) |
|
511 ## Is there a pre_install to call? |
|
512 if (exist([packdir "pre_install.m"], "file")) |
|
513 wd = pwd(); |
|
514 try |
|
515 cd(packdir); |
|
516 pre_install(desc); |
|
517 cd(wd); |
|
518 catch |
|
519 cd(wd); |
|
520 error("The pre-install function returned the following error: %s\n", lasterr); |
|
521 end_try_catch |
|
522 endif |
|
523 |
5993
|
524 ## If the directory "inst" doesn't exist, we create it |
|
525 if (!exist([packdir "inst"], "dir")) |
5801
|
526 [status, msg] = mkdir([packdir "inst"]); |
|
527 if (status != 1) |
5928
|
528 rm_rf(desc.dir); |
5801
|
529 error("The 'inst' directory did not exist and could not be created: %s\n", msg); |
|
530 endif |
|
531 endif |
|
532 endfunction |
|
533 |
|
534 function configure_make (desc, packdir) |
|
535 ## Perform ./configure, make, make install in "src" |
|
536 if (exist([packdir "src"], "dir")) |
|
537 src = [packdir "src/"]; |
|
538 ## configure |
|
539 if (exist([src "configure"], "file")) |
5928
|
540 [status, output] = system(["cd " src " ;./configure --prefix=" desc.dir]); |
5801
|
541 if (status != 0) |
5928
|
542 rm_rf(desc.dir); |
5801
|
543 error("The configure script returned the following error: %s\n", output); |
|
544 endif |
|
545 endif |
|
546 |
|
547 ## make |
|
548 if (exist([src "Makefile"], "file")) |
5928
|
549 [status, output] = system(["export INSTALLDIR=" desc.dir "; make -C " src]); |
5801
|
550 if (status != 0) |
5928
|
551 rm_rf(desc.dir); |
5801
|
552 error("'make' returned the following error: %s\n", output); |
|
553 endif |
|
554 %# make install |
5928
|
555 %[status, output] = system(["export INSTALLDIR=" desc.dir "; make install -C " src]); |
5801
|
556 %if (status != 0) |
5928
|
557 % rm_rf(desc.dir); |
5801
|
558 % error("'make install' returned the following error: %s\n", output); |
|
559 %endif |
|
560 endif |
|
561 |
|
562 ## Copy files to "inst" (this is instead of 'make install') |
|
563 files = [src "FILES"]; |
|
564 if (exist(files, "file")) |
|
565 [fid, msg] = fopen(files, "r"); |
|
566 if (fid < 0) |
|
567 error("Couldn't open %s: %s\n", files, msg); |
|
568 endif |
5928
|
569 filenames = char(fread(fid))'; |
5801
|
570 filenames = strrep(filenames, "\n", " "); |
5928
|
571 [status, output] = system(["cd " src "; cp " filenames " " packdir "inst/"]); |
5801
|
572 fclose(fid); |
|
573 else |
|
574 m = dir([src "*.m"]); |
|
575 oct = dir([src "*.oct"]); |
|
576 f = ""; |
|
577 if (length(m) > 0) |
5928
|
578 f = sprintf([src "%s "], m.name); |
5801
|
579 endif |
|
580 if (length(oct) > 0) |
5928
|
581 f = [f " " sprintf([src "%s "], oct.name)]; |
5801
|
582 endif |
5928
|
583 |
|
584 if (!all(isspace(f))) |
|
585 [status, output] = system(["cp -R " f " " packdir "inst/"]); |
|
586 endif |
5801
|
587 endif |
|
588 if (status != 0) |
5928
|
589 rm_rf(desc.dir); |
5801
|
590 error("Couldn't copy files from 'src' to 'inst': %s\n", output); |
|
591 endif |
|
592 endif |
|
593 endfunction |
|
594 |
5971
|
595 function pkg = extract_pkg (nm, pat) |
5955
|
596 fid = fopen (nm, "rt"); |
5971
|
597 pkg = ""; |
5955
|
598 if (fid >= 0) |
|
599 while (! feof(fid)) |
|
600 ln = fgetl (fid); |
|
601 if (ln > 0) |
|
602 t = regexp(ln, pat, "tokens","dotexceptnewline"); |
|
603 if (!isempty(t)) |
5971
|
604 pkg = [pkg, "\n", t{1}{1}]; |
5955
|
605 endif |
|
606 endif |
|
607 endwhile |
5971
|
608 if (!isempty(pkg)) |
|
609 pkg = [pkg, "\n"]; |
5955
|
610 endif |
|
611 fclose (fid); |
|
612 endif |
|
613 endfunction |
|
614 |
5971
|
615 function create_pkgadddel (desc, packdir, nm) |
|
616 pkg = [desc.dir "/" nm]; |
|
617 fid = fopen(pkg, "wt"); |
5976
|
618 |
5955
|
619 if (fid >= 0) |
5971
|
620 ## Search all dot-m files for PKG commands |
5955
|
621 lst = dir ([packdir "inst/*.m"]); |
|
622 for i=1:length(lst) |
5976
|
623 nam = [packdir "inst/" lst(i).name]; |
|
624 fwrite (fid, extract_pkg (nam, ['^[#%][#%]* *' nm ': *(.*)$'])); |
5955
|
625 endfor |
|
626 |
5971
|
627 ## Search all C++ source files for PKG commands |
5955
|
628 lst = dir ([packdir "src/*.cc"]); |
|
629 for i=1:length(lst) |
5976
|
630 nam = [packdir "src/" lst(i).name]; |
|
631 fwrite (fid, extract_pkg (nam, ['^//* *' nm ': *(.*)$'])); |
|
632 fwrite (fid, extract_pkg (nam, ['^/\** *' nm ': *(.*) *\*/$'])); |
5955
|
633 endfor |
|
634 |
5971
|
635 ## Add developer included PKG commands |
|
636 if (exist([packdir nm],"file")) |
|
637 fid2 = fopen([packdir nm],"rt"); |
5955
|
638 if (fid2 >= 0) |
|
639 while (! feof(fid2)) |
|
640 ln = fgets (fid2); |
|
641 if (ln > 0) |
|
642 fwrite(fid, ln); |
|
643 endif |
|
644 endwhile |
5971
|
645 fclose(fid2); |
5955
|
646 endif |
|
647 endif |
|
648 fclose(fid); |
5971
|
649 |
|
650 ## If the file is empty remove it |
|
651 t = dir (pkg); |
|
652 if (t.bytes <= 0) |
|
653 unlink (pkg); |
|
654 endif |
5955
|
655 endif |
|
656 endfunction |
|
657 |
5971
|
658 function copy_files (desc, packdir, bindir) |
6020
|
659 ## Create the installation directory |
|
660 if (! exist (desc.dir, "dir")) |
|
661 [status, output] = mkdir (desc.dir); |
|
662 if (status != 1) |
|
663 error("Couldn't create installation directory %s : %s\n", |
|
664 desc.dir, output); |
|
665 endif |
|
666 endif |
|
667 |
5801
|
668 ## Copy the files from "inst" to installdir |
5971
|
669 if (! dirempty([packdir "inst"])) |
|
670 [status, output] = system(["cp -R " packdir "inst/* " desc.dir]); |
|
671 if (status != 0) |
|
672 rm_rf(desc.dir); |
|
673 error("Couldn't copy files to the installation directory\n"); |
|
674 endif |
5801
|
675 endif |
|
676 |
|
677 ## Create the "packinfo" directory |
|
678 packinfo = [desc.dir "/packinfo/"]; |
|
679 [status, msg] = mkdir (packinfo); |
|
680 if (status != 1) |
5928
|
681 rm_rf(desc.dir); |
5801
|
682 error("Couldn't create packinfo directory: %s\n", msg); |
|
683 endif |
|
684 |
|
685 ## Copy DESCRIPTION |
5928
|
686 [status, output] = system(["cp " packdir "DESCRIPTION " packinfo]); |
5801
|
687 if (status != 0) |
5928
|
688 rm_rf(desc.dir); |
5801
|
689 error("Couldn't copy DESCRIPTION: %s\n", output); |
|
690 endif |
|
691 |
5993
|
692 ## Copy COPYING |
|
693 [status, output] = system(["cp " packdir "COPYING " packinfo]); |
|
694 if (status != 0) |
|
695 rm_rf(desc.dir); |
|
696 error("Couldn't copy COPYING: %s\n", output); |
|
697 endif |
|
698 |
5801
|
699 ## Is there an INDEX file to copy or should we generate one? |
|
700 if (exist([packdir "INDEX"], "file")) |
5928
|
701 [status, output] = system(["cp " packdir "INDEX " packinfo]); |
5801
|
702 if (status != 0) |
5928
|
703 rm_rf(desc.dir); |
5801
|
704 error("Couldn't copy INDEX file: %s\n", output); |
|
705 endif |
|
706 else |
|
707 try |
|
708 write_INDEX(desc, [packdir "inst"], [packinfo "INDEX"]); |
|
709 catch |
5928
|
710 rm_rf(desc.dir); |
5801
|
711 error(lasterr); |
|
712 end_try_catch |
|
713 endif |
|
714 |
|
715 ## Is there an 'on_uninstall.m' to install? |
|
716 if (exist([packdir "on_uninstall.m"], "file")) |
5928
|
717 [status, output] = system(["cp " packdir "on_uninstall.m " packinfo]); |
5801
|
718 if (status != 0) |
5928
|
719 rm_rf(desc.dir); |
5801
|
720 error("Couldn't copy on_uninstall.m: %s\n", output); |
|
721 endif |
|
722 endif |
5971
|
723 |
|
724 ## Is there a doc/ directory that needs to be installed |
|
725 if (exist([packdir "doc"], "dir") && !dirempty([packdir "doc"])) |
|
726 [status, output] = system(["cp -pR " packdir "doc " desc.dir]); |
|
727 endif |
|
728 |
|
729 ## Is there a bin/ directory that needs to be installed |
|
730 if (exist([packdir "bin"], "dir") && !dirempty([packdir "bin"])) |
|
731 [status, output] = system(["cp -pR " packdir "bin " desc.dir]); |
|
732 endif |
5801
|
733 endfunction |
|
734 |
|
735 function finish_installation (desc, packdir) |
|
736 ## Is there a post-install to call? |
|
737 if (exist([packdir "post_install.m"], "file")) |
|
738 wd = pwd(); |
|
739 try |
|
740 cd(packdir); |
|
741 post_install(desc); |
|
742 cd(wd); |
|
743 catch |
|
744 cd(wd); |
5928
|
745 rm_rf(desc.dir); |
5801
|
746 error("The post_install function returned the following error: %s\n", lasterr); |
|
747 end_try_catch |
|
748 endif |
|
749 endfunction |
|
750 |
|
751 function out = issuperuser() |
|
752 out = strcmp(getenv("USER"), "root"); |
|
753 endfunction |
|
754 |
|
755 ## This function makes sure the package contains the |
|
756 ## essential files. |
|
757 function verify_directory(dir) |
|
758 needed_files = {"COPYING", "DESCRIPTION"}; |
|
759 for f = needed_files |
|
760 if (!exist([dir "/" f{1}], "file")) |
|
761 error("Package is missing file: %s", f{1}); |
|
762 endif |
|
763 endfor |
|
764 endfunction |
|
765 |
|
766 ## This function parses the DESCRIPTION file |
|
767 function desc = get_description(filename) |
|
768 fid = fopen(filename, "r"); |
|
769 if (fid == -1) |
|
770 error("The DESCRIPTION file %s could not be read\n", filename); |
|
771 endif |
|
772 |
|
773 desc = struct(); |
|
774 |
|
775 line = fgetl(fid); |
|
776 while (line != -1) |
|
777 ## Comments |
|
778 if (line(1) == "#") |
|
779 # Do nothing |
|
780 ## Continuation lines |
|
781 elseif (isspace(line(1))) |
|
782 if (exist("keyword", "var") && isfield(desc, keyword)) |
|
783 desc.(keyword) = [desc.(keyword) " " rstrip(line)]; |
|
784 endif |
|
785 ## Keyword/value pair |
|
786 else |
|
787 colon = find(line == ":"); |
|
788 if (length(colon) == 0) |
|
789 disp("Skipping line."); |
|
790 else |
|
791 colon = colon(1); |
|
792 keyword = tolower(strip(line(1:colon-1))); |
|
793 value = strip(line(colon+1:end)); |
|
794 if (length(value) == 0) |
|
795 fclose(fid); |
|
796 error("The keyword %s have empty value\n", desc.keywords{end}); |
|
797 endif |
|
798 desc.(keyword) = value; |
|
799 endif |
|
800 endif |
|
801 line = fgetl(fid); |
|
802 endwhile |
|
803 fclose(fid); |
|
804 |
|
805 ## Make sure all is okay |
|
806 needed_fields = {"name", "version", "date", "title", ... |
|
807 "author", "maintainer", "description"}; |
|
808 for f = needed_fields |
|
809 if (!isfield(desc, f{1})) |
|
810 error("Description is missing needed field %s\n", f{1}); |
|
811 endif |
|
812 endfor |
|
813 desc.version = fix_version(desc.version); |
|
814 if (isfield(desc, "depends")) |
|
815 desc.depends = fix_depends(desc.depends); |
|
816 else |
|
817 desc.depends = ""; |
|
818 endif |
|
819 desc.name = tolower(desc.name); |
|
820 endfunction |
|
821 |
|
822 ## Makes sure the version string v is a valid x.y.z version string |
|
823 ## Examples: "0.1" => "0.1.0", "monkey" => error(...) |
|
824 function out = fix_version(v) |
|
825 dots = find(v == "."); |
|
826 if (length(dots) == 1) |
|
827 major = str2num(v(1:dots-1)); |
|
828 minor = str2num(v(dots+1:end)); |
|
829 if (length(major) != 0 && length(minor) != 0) |
|
830 out = sprintf("%d.%d.0", major, minor); |
|
831 return |
|
832 endif |
|
833 elseif (length(dots) == 2) |
|
834 major = str2num(v(1:dots(1)-1)); |
|
835 minor = str2num(v(dots(1)+1:dots(2)-1)); |
|
836 rev = str2num(v(dots(2)+1:end)); |
|
837 if (length(major) != 0 && length(minor) != 0 && length(rev) != 0) |
|
838 out = sprintf("%d.%d.%d", major, minor, rev); |
|
839 return |
|
840 endif |
|
841 endif |
|
842 error("Bad version string: %s\n", v); |
|
843 endfunction |
|
844 |
|
845 ## Makes sure the depends field is of the right format. |
|
846 ## This function returns a cell of structures with the following fields: |
|
847 ## package, version, operator |
|
848 function deps_cell = fix_depends(depends) |
|
849 deps = split_by(tolower(depends), ","); |
|
850 deps_cell = cell(1, length(deps)); |
|
851 |
|
852 ## For each dependency |
|
853 for i = 1:length(deps) |
|
854 dep = deps{i}; |
|
855 lpar = find(dep == "("); |
|
856 rpar = find(dep == ")"); |
|
857 ## Does the dependency specify a version |
|
858 ## Example: package(>= version) |
|
859 if (length(lpar) == 1 && length(rpar) == 1) |
|
860 package = tolower(strip(dep(1:lpar-1))); |
|
861 sub = dep( lpar(1)+1:rpar(1)-1 ); |
|
862 parts = split_by(sub, " "); |
|
863 idx = []; |
|
864 for r = 1:size(parts,1) |
|
865 if (length(parts{r}) > 0) |
|
866 idx(end+1) = r; |
|
867 endif |
|
868 endfor |
|
869 |
|
870 if (length(idx) != 2) |
|
871 error(["There's something wrong with the DESCRIPTION file. " ... |
|
872 "The dependency %s has the wrong syntax.\n"], dep); |
|
873 endif |
|
874 operator = parts{idx(1)}; |
|
875 if (!any(strcmp(operator, {">=", "<=", "=="}))) ## XXX: I belive we also support ">" and "<" |
|
876 error("Unsupported operator: %s\n", operator); |
|
877 endif |
|
878 version = fix_version(parts{idx(2)}); |
|
879 |
|
880 ## If no version is specified for the dependency |
|
881 ## we say that the version should be greater than |
|
882 ## or equal to 0.0.0 |
|
883 else |
|
884 package = tolower(strip(dep)); |
|
885 operator = ">="; |
|
886 version = "0.0.0"; |
|
887 endif |
|
888 deps_cell{i} = struct("package", package, "operator", operator, "version", version); |
|
889 endfor |
|
890 endfunction |
|
891 |
|
892 ## Strips the text of spaces from the right |
|
893 ## Example: " hello world " => " hello world" (XXX: is this the same as deblank?) |
|
894 function text = rstrip(text) |
|
895 chars = find(!isspace(text)); |
|
896 if (length(chars) > 0) |
|
897 text = text(chars(1):end); # XXX: shouldn't it be text = text(1:chars(end)); |
|
898 else |
|
899 text = ""; |
|
900 endif |
|
901 endfunction |
|
902 |
|
903 ## Strips the text of spaces from the left and the right |
|
904 ## Example: " hello world " => "hello world" |
|
905 function text = strip(text) |
|
906 chars = find(!isspace(text)); |
|
907 if (length(chars) > 0) |
|
908 text = text(chars(1):chars(end)); |
|
909 else |
|
910 text = ""; |
|
911 endif |
|
912 endfunction |
|
913 |
|
914 ## Splits the text into a cell array of strings by sep |
|
915 ## Example: "A, B" => {"A", "B"} (with sep = ",") |
|
916 function out = split_by(text, sep) |
|
917 text_matrix = split(text, sep); |
|
918 num_words = size(text_matrix,1); |
|
919 out = cell(num_words, 1); |
|
920 for i = 1:num_words |
|
921 out{i} = strip(text_matrix(i, :)); |
|
922 endfor |
|
923 endfunction |
|
924 |
|
925 ## Creates an INDEX file for a package that doesn't provide one. |
|
926 ## 'desc' describes the package. |
|
927 ## 'dir' is the 'inst' direcotyr in temporary directory. |
|
928 ## 'INDEX' is the name (including path) of resulting INDEX file. |
|
929 function write_INDEX(desc, dir, INDEX) |
|
930 ## Get names of functions in dir |
|
931 [files, err, msg] = readdir(dir); |
|
932 if (err) |
|
933 error("Couldn't read directory %s: %s\n", dir, msg); |
|
934 endif |
|
935 |
|
936 functions = {}; |
|
937 for i = 1:length(files) |
|
938 file = files{i}; |
|
939 lf = length(file); |
|
940 if (lf > 2 && strcmp( file(end-1:end), ".m" )) |
|
941 functions{end+1} = file(1:end-2); |
|
942 elseif (lf > 4 && strcmp( file(end-3:end), ".oct" )) |
|
943 functions{end+1} = file(1:end-4); |
|
944 endif |
|
945 endfor |
|
946 |
|
947 ## Does desc have a categories field? |
|
948 if (!isfield(desc, "categories")) |
|
949 error("The DESCRIPTION file must have a Categories field, when no INDEX file is given.\n"); |
|
950 endif |
|
951 categories = split_by(desc.categories, ","); |
|
952 if (length(categories) < 1) |
|
953 error("The Category field is empty.\n"); |
|
954 endif |
|
955 |
|
956 ## Write INDEX |
|
957 fid = fopen(INDEX, "w"); |
|
958 if (fid == -1) |
|
959 error("Couldn't open %s for writing.\n", INDEX); |
|
960 endif |
|
961 fprintf(fid, "%s >> %s\n", desc.name, desc.title); |
|
962 fprintf(fid, "%s\n", categories{1}); |
|
963 fprintf(fid, " %s\n", functions{:}); |
|
964 fclose(fid); |
|
965 endfunction |
|
966 |
|
967 function bad_deps = get_unsatisfied_deps(desc, installed_packages) |
|
968 bad_deps = {}; |
|
969 |
|
970 ## For each dependency |
|
971 for i = 1:length(desc.depends) |
|
972 dep = desc.depends{i}; |
|
973 |
|
974 ## Is the current dependency Octave? |
|
975 if (strcmp(dep.package, "octave")) |
|
976 if (!compare_versions(OCTAVE_VERSION, dep.version, dep.operator)) |
|
977 bad_deps{end+1} = dep; |
|
978 endif |
|
979 ## Is the current dependency not Octave? |
|
980 else |
|
981 ok = false; |
|
982 for i = 1:length(installed_packages) |
|
983 cur_name = installed_packages{i}.name; |
|
984 cur_version = installed_packages{i}.version; |
|
985 if (strcmp(dep.package, cur_name) && compare_versions(cur_version, dep.version, dep.operator)) |
|
986 ok = true; |
|
987 break; |
|
988 endif |
|
989 endfor |
|
990 if (!ok) |
|
991 bad_deps{end+1} = dep; |
|
992 endif |
|
993 endif |
|
994 endfor |
|
995 endfunction |
|
996 |
|
997 ## Compares to version string using the given operator |
|
998 ## Example: v1="0.1.0", v2="0.0.9", operator=">=" => true |
|
999 ## TODO: This function is very long and complex! Can't it be simplified? |
|
1000 function out = compare_versions(v1, v2, operator) |
|
1001 dot1 = find(v1 == "."); |
|
1002 dot2 = find(v2 == "."); |
|
1003 if (length(dot1) != 2 || length(dot2) != 2) |
|
1004 error("Given version strings are not valid: %s %s", v1, v2); |
|
1005 endif |
|
1006 |
|
1007 major1 = str2num( v1( 1:dot1(1)-1 ) ); |
|
1008 minor1 = str2num( v1( dot1(1)+1:dot1(2)-1 ) ); |
|
1009 rev1 = str2num( v1( dot1(2)+1:end ) ); |
|
1010 major2 = str2num( v2( 1:dot2(1)-1 ) ); |
|
1011 minor2 = str2num( v2( dot2(1)+1:dot2(2)-1 ) ); |
|
1012 rev2 = str2num( v2( dot2(2)+1:end) ); |
|
1013 mmr = [sign(major1-major2), sign(minor1-minor2), sign(rev1-rev2)]; |
|
1014 |
|
1015 if (length(operator) > 1 && operator(2) == "=" && !any(mmr)) |
|
1016 out = 1; |
|
1017 return; |
|
1018 elseif (operator(1) == "<") |
|
1019 mmr = -mmr; |
|
1020 endif |
|
1021 |
|
1022 ## Now we ony need to decide if v1 > v2 |
|
1023 if (mmr(1) == 1) |
|
1024 out = 1; |
|
1025 elseif (mmr(1) == -1) |
|
1026 out = 0; |
|
1027 elseif (mmr(2) == 1) |
|
1028 out = 1; |
|
1029 elseif (mmr(2) == -1) |
|
1030 out = 0; |
|
1031 elseif (mmr(3) == 1) |
|
1032 out = 1; |
|
1033 else |
|
1034 out = 0; |
|
1035 endif |
|
1036 endfunction |
|
1037 |
|
1038 function [out1, out2] = installed_packages() |
|
1039 local_list = tilde_expand("~/.octave_packages"); |
5974
|
1040 if (strcmp(OCTAVE_HOME()(end),"/")) |
|
1041 global_list = [OCTAVE_HOME "share/octave/octave_packages"]; |
|
1042 else |
|
1043 global_list = [OCTAVE_HOME "/share/octave/octave_packages"]; |
|
1044 endif |
5801
|
1045 ## Get the list of installed packages |
|
1046 try |
|
1047 local_packages = load(local_list).local_packages; |
|
1048 catch |
|
1049 local_packages = {}; |
|
1050 end_try_catch |
|
1051 try |
|
1052 global_packages = load(global_list).global_packages; |
|
1053 catch |
|
1054 global_packages = {}; |
|
1055 end_try_catch |
|
1056 installed_packages = {local_packages{:} global_packages{:}}; |
|
1057 |
|
1058 ## Should we return something? |
|
1059 if (nargout == 2) |
|
1060 out1 = local_packages; |
|
1061 out2 = global_packages; |
|
1062 return; |
|
1063 elseif (nargout == 1) |
|
1064 out1 = installed_packages; |
|
1065 return; |
|
1066 endif |
|
1067 |
|
1068 ## We shouldn't return something, so we'll print something |
|
1069 num_packages = length(installed_packages); |
|
1070 if (num_packages == 0) |
|
1071 printf("No packages installed.\n"); |
|
1072 return; |
|
1073 endif |
|
1074 |
5987
|
1075 ## Compute the maximal lengths of name, version, and dir |
5801
|
1076 h1 = "Package Name"; |
|
1077 h2 = "Version"; |
|
1078 h3 = "Installation directory"; |
5987
|
1079 max_name_length = length(h1); |
|
1080 max_version_length = length(h2); |
|
1081 names = cell(num_packages,1); |
|
1082 for i = 1:num_packages |
|
1083 max_name_length = max(max_name_length, |
|
1084 length(installed_packages{i}.name)); |
|
1085 max_version_length = max(max_version_length, |
|
1086 length(installed_packages{i}.version)); |
|
1087 names{i} = installed_packages{i}.name; |
|
1088 endfor |
|
1089 h1 = postpad (h1, max_name_length,' '); |
|
1090 h2 = postpad (h2, max_version_length, ' ');; |
|
1091 |
|
1092 ## Print a header |
5801
|
1093 header = sprintf("%s | %s | %s\n", h1, h2, h3); |
|
1094 printf(header); |
|
1095 tmp = sprintf(repmat("-", 1, length(header)-1)); |
|
1096 tmp(length(h1)+2) = "+"; tmp(length(h1)+length(h2)+5) = "+"; |
|
1097 printf("%s\n", tmp); |
|
1098 |
|
1099 ## Print the packages |
|
1100 format = sprintf("%%%ds | %%%ds | %%s\n", max_name_length, max_version_length); |
5987
|
1101 [dummy, idx] = sort(names); |
5801
|
1102 for i = 1:num_packages |
5987
|
1103 cur_name = installed_packages{idx(i)}.name; |
|
1104 cur_version = installed_packages{idx(i)}.version; |
|
1105 cur_dir = installed_packages{idx(i)}.dir; |
5801
|
1106 printf(format, cur_name, cur_version, cur_dir); |
|
1107 endfor |
|
1108 endfunction |
|
1109 |
|
1110 function load_packages(files, handle_deps) |
|
1111 installed_packages = installed_packages(); |
|
1112 num_packages = length(installed_packages); |
|
1113 |
|
1114 if (length(files) == 1 && strcmp(files{1}, "all")) |
|
1115 dirs = cell(1, num_packages); |
|
1116 for i = 1:num_packages |
|
1117 dirs{i} = installed_packages{i}.dir; |
|
1118 endfor |
|
1119 elseif (handle_deps) |
|
1120 # XXX: implement this |
|
1121 error("Currently you need to call load_packages with 'all' or '-nodeps'. This is a bug!\n"); |
|
1122 else |
|
1123 dirs = cell(1, length(files)); |
|
1124 for j = 1:length(files) |
|
1125 for i = 1:num_packages |
|
1126 if (strcmp(installed_packages{i}.name, files{j})) |
|
1127 dirs{j} = installed_packages{i}.dir; |
5971
|
1128 break; |
5801
|
1129 endif |
|
1130 endfor |
5971
|
1131 if (isempty(dirs{j})) |
|
1132 error("Package %s is not installed\n", files{j}); |
|
1133 endif |
5801
|
1134 endfor |
|
1135 endif |
6025
|
1136 if (length(dirs) > 0) |
|
1137 addpath(dirs{:}); |
|
1138 endif |
5971
|
1139 |
|
1140 ## Add local binaries, if any, to the EXEC_PATH |
|
1141 for i = 1:length(dirs) |
|
1142 if (exist ([dirs{i} "/bin"],"dir")) |
|
1143 EXEC_PATH ([dirs{i} "/bin:" EXEC_PATH()]); |
|
1144 endif |
|
1145 endfor |
5801
|
1146 endfunction |
5928
|
1147 |
|
1148 function [status_out, msg_out] = rm_rf (dir) |
|
1149 crr = confirm_recursive_rmdir (); |
|
1150 unwind_protect |
|
1151 confirm_recursive_rmdir (false); |
|
1152 [status, msg] = rmdir (dir, "s"); |
|
1153 unwind_protect_cleanup |
|
1154 confirm_recursive_rmdir (crr); |
|
1155 end_unwind_protect |
|
1156 if (nargout > 0) |
|
1157 status_out = status; |
|
1158 endif |
|
1159 if (nargout > 1) |
|
1160 msg_out = msg; |
|
1161 endif |
|
1162 endfunction |
5971
|
1163 |
|
1164 function emp = dirempty (nm, ign) |
|
1165 if (nargin < 2) |
|
1166 ign = {".",".."}; |
|
1167 else |
|
1168 ign = [{".",".."},ign]; |
|
1169 endif |
|
1170 l = dir (nm); |
|
1171 for i=1:length(l) |
|
1172 found = false; |
|
1173 for j=1:length(ign) |
|
1174 if (strcmp(l(i).name,ign{j})) |
|
1175 found = true; |
|
1176 break; |
|
1177 endif |
|
1178 endfor |
|
1179 if (!found) |
|
1180 emp = false; |
|
1181 return |
|
1182 endif |
|
1183 endfor |
|
1184 emp = true; |
|
1185 return; |
|
1186 endfunction |