comparison scripts/pkg/pkg.m @ 5971:9cc8149f81b0

[project @ 2006-08-25 21:14:20 by dbateman]
author dbateman
date Fri, 25 Aug 2006 21:15:41 +0000
parents fc46f9c99028
children 51684d05b4bf
comparison
equal deleted inserted replaced
5970:af3407589a89 5971:9cc8149f81b0
163 163
164 ## Read the DESCRIPTION file 164 ## Read the DESCRIPTION file
165 filename = [packdir "DESCRIPTION"]; 165 filename = [packdir "DESCRIPTION"];
166 desc = get_description(filename); 166 desc = get_description(filename);
167 167
168 ## Verify that package name corresponds with filename
169 [dummy, nm] = fileparts(tgz);
170 if ((length(nm) >= length(desc.name)) &&
171 ! strcmp(desc.name,nm(1:length(desc.name))))
172 error("Package name doesn't correspond to its filename");
173 endif
174
168 ## Set default installation directory 175 ## Set default installation directory
169 desc.dir = [prefix "/" desc.name "-" desc.version]; 176 desc.dir = [prefix "/" desc.name "-" desc.version];
170 177
171 ## Save desc 178 ## Save desc
172 descriptions{end+1} = desc; 179 descriptions{end+1} = desc;
181 endfor 188 endfor
182 endfor 189 endfor
183 catch 190 catch
184 ## Something went wrong, delete tmpdirs 191 ## Something went wrong, delete tmpdirs
185 for i = 1:length(tmpdirs) 192 for i = 1:length(tmpdirs)
186 tmpdirs{i}
187 rm_rf(tmpdirs{i}); 193 rm_rf(tmpdirs{i});
188 endfor 194 endfor
189 error(lasterr()(8:end)); 195 error(lasterr()(8:end));
190 end_try_catch 196 end_try_catch
191 197
249 ## Install each package 255 ## Install each package
250 try 256 try
251 for i = 1:length(descriptions) 257 for i = 1:length(descriptions)
252 desc = descriptions{i}; 258 desc = descriptions{i};
253 pdir = packdirs{i}; 259 pdir = packdirs{i};
254 copy_files(desc, pdir); 260 copy_files(desc, pdir);
255 create_pkgadd(desc, pdir); 261 create_pkgadddel(desc, pdir, "PKG_ADD");
262 create_pkgadddel(desc, pdir, "PKG_DEL");
256 finish_installation (desc, pdir) 263 finish_installation (desc, pdir)
257 endfor 264 endfor
258 catch 265 catch
259 ## Something went wrong, delete tmpdirs 266 ## Something went wrong, delete tmpdirs
260 for i = 1:length(tmpdirs) 267 for i = 1:length(tmpdirs)
261 rm_rf(tmpdirs{i}); 268 rm_rf(tmpdirs{i});
262 endfor 269 endfor
270 for i = 1:length(descriptions)
271 rm_rf(descriptions{i}.dir);
272 endfor
263 error(lasterr()(8:end)); 273 error(lasterr()(8:end));
264 end_try_catch 274 end_try_catch
265 275
266 ## Add the packages to the package list 276 ## Check if the installed directory is empty. If it is remove it
277 ## from the list
278 for i = length(descriptions):-1:1
279 if (dirempty(descriptions{i}.dir,{"packinfo","doc"}))
280 rm_rf(descriptions{i}.dir);
281 descriptions(i) = [];
282 endif
283 endfor
284
285 ## Add the packages to the package list
267 try 286 try
268 if (global_install) 287 if (global_install)
269 idx = complement(packages_to_uninstall, 1:length(global_packages)); 288 idx = complement(packages_to_uninstall, 1:length(global_packages));
270 global_packages = {global_packages{idx} descriptions{:}}; 289 global_packages = {global_packages{idx} descriptions{:}};
271 save(global_list, "global_packages"); 290 save(global_list, "global_packages");
296 warning("Couldn't clean up after my self: %s\n", msg); 315 warning("Couldn't clean up after my self: %s\n", msg);
297 endif 316 endif
298 endfor 317 endfor
299 318
300 ## Add the newly installed packages to the path, so the user 319 ## Add the newly installed packages to the path, so the user
301 ## can begin the using. 320 ## can begin usings them.
302 dirs = cell(1, length(descriptions)); 321 if (length(descriptions) > 0)
303 for i = 1:length(descriptions) 322 dirs = cell(1, length(descriptions));
323 for i = 1:length(descriptions)
304 dirs{i} = descriptions{i}.dir; 324 dirs{i} = descriptions{i}.dir;
305 endfor 325 endfor
306 addpath(dirs{:}); 326 addpath(dirs{:});
327 endif
307 endfunction 328 endfunction
308 329
309 function uninstall(pkgnames, handle_deps) 330 function uninstall(pkgnames, handle_deps)
310 local_list = tilde_expand("~/.octave_packages"); 331 local_list = tilde_expand("~/.octave_packages");
311 global_list = [OCTAVE_HOME "share/octave/octave_packages"]; 332 global_list = [OCTAVE_HOME "share/octave/octave_packages"];
497 error("Couldn't copy files from 'src' to 'inst': %s\n", output); 518 error("Couldn't copy files from 'src' to 'inst': %s\n", output);
498 endif 519 endif
499 endif 520 endif
500 endfunction 521 endfunction
501 522
502 function pkgadd = extract_pkgadd (nm, pat) 523 function pkg = extract_pkg (nm, pat)
503 fid = fopen (nm, "rt"); 524 fid = fopen (nm, "rt");
504 pkgadd = ""; 525 pkg = "";
505 if (fid >= 0) 526 if (fid >= 0)
506 while (! feof(fid)) 527 while (! feof(fid))
507 ln = fgetl (fid); 528 ln = fgetl (fid);
508 if (ln > 0) 529 if (ln > 0)
509 t = regexp(ln, pat, "tokens","dotexceptnewline"); 530 t = regexp(ln, pat, "tokens","dotexceptnewline");
510 if (!isempty(t)) 531 if (!isempty(t))
511 pkgadd = [pkgadd, "\n", t{1}{1}]; 532 pkg = [pkg, "\n", t{1}{1}];
512 endif 533 endif
513 endif 534 endif
514 endwhile 535 endwhile
515 if (!isempty(pkgadd)) 536 if (!isempty(pkg))
516 pkgadd = [pkgadd, "\n"]; 537 pkg = [pkg, "\n"];
517 endif 538 endif
518 fclose (fid); 539 fclose (fid);
519 endif 540 endif
520 endfunction 541 endfunction
521 542
522 function create_pkgadd (desc, packdir) 543 function create_pkgadddel (desc, packdir, nm)
523 pkgadd = [desc.dir "/PKG_ADD"]; 544 pkg = [desc.dir "/" nm];
524 fid = fopen(pkgadd, "wt"); 545 fid = fopen(pkg, "wt");
525 if (fid >= 0) 546 if (fid >= 0)
526 ## Search all dot-m files for PKG_ADD commands 547 ## Search all dot-m files for PKG commands
527 lst = dir ([packdir "inst/*.m"]); 548 lst = dir ([packdir "inst/*.m"]);
528 for i=1:length(lst) 549 for i=1:length(lst)
529 nm = lst(i).name; 550 nm = lst(i).name;
530 fwrite (fid, extract_pkgadd (nm, '^[#%][#%]* *PKG_ADD: *(.*)$')); 551 fwrite (fid, extract_pkg (nm, ['^[#%][#%]* *' nm ': *(.*)$']));
531 endfor 552 endfor
532 553
533 ## Search all C++ source files for PKG_ADD commands 554 ## Search all C++ source files for PKG commands
534 lst = dir ([packdir "src/*.cc"]); 555 lst = dir ([packdir "src/*.cc"]);
535 for i=1:length(lst) 556 for i=1:length(lst)
536 nm = lst(i).name; 557 nm = lst(i).name;
537 fwrite (fid, extract_pkgadd (nm, '^//* *PKG_ADD: *(.*)$')); 558 fwrite (fid, extract_pkg (nm, ['^//* *' nm ': *(.*)$']));
538 fwrite (fid, extract_pkgadd (nm, '^/\** *PKG_ADD: *(.*) *\*/$')); 559 fwrite (fid, extract_pkg (nm, ['^/\** *' nm ': *(.*) *\*/$']));
539 endfor 560 endfor
540 561
541 ## Add developer included PKG_ADD commands 562 ## Add developer included PKG commands
542 if (exist([packdir "PKG_ADD"],"file")) 563 if (exist([packdir nm],"file"))
543 fid2 = fopen([packdir "PKG_ADD"],"rt"); 564 fid2 = fopen([packdir nm],"rt");
544 if (fid2 >= 0) 565 if (fid2 >= 0)
545 while (! feof(fid2)) 566 while (! feof(fid2))
546 ln = fgets (fid2); 567 ln = fgets (fid2);
547 if (ln > 0) 568 if (ln > 0)
548 fwrite(fid, ln); 569 fwrite(fid, ln);
549 endif 570 endif
550 endwhile 571 endwhile
572 fclose(fid2);
551 endif 573 endif
552 endif 574 endif
553 fclose(fid); 575 fclose(fid);
576
577 ## If the file is empty remove it
578 t = dir (pkg);
579 if (t.bytes <= 0)
580 unlink (pkg);
581 endif
554 endif 582 endif
555 endfunction 583 endfunction
556 584
557 function copy_files (desc, packdir) 585 function copy_files (desc, packdir, bindir)
558 ## Copy the files from "inst" to installdir 586 ## Copy the files from "inst" to installdir
559 [status, output] = system(["cp -R " packdir "inst/* " desc.dir]); 587 if (! dirempty([packdir "inst"]))
560 if (status != 0) 588 [status, output] = system(["cp -R " packdir "inst/* " desc.dir]);
561 rm_rf(desc.dir); 589 if (status != 0)
562 error("Couldn't copy files to the installation directory\n"); 590 rm_rf(desc.dir);
591 error("Couldn't copy files to the installation directory\n");
592 endif
563 endif 593 endif
564 594
565 ## Create the "packinfo" directory 595 ## Create the "packinfo" directory
566 packinfo = [desc.dir "/packinfo/"]; 596 packinfo = [desc.dir "/packinfo/"];
567 [status, msg] = mkdir (packinfo); 597 [status, msg] = mkdir (packinfo);
598 [status, output] = system(["cp " packdir "on_uninstall.m " packinfo]); 628 [status, output] = system(["cp " packdir "on_uninstall.m " packinfo]);
599 if (status != 0) 629 if (status != 0)
600 rm_rf(desc.dir); 630 rm_rf(desc.dir);
601 error("Couldn't copy on_uninstall.m: %s\n", output); 631 error("Couldn't copy on_uninstall.m: %s\n", output);
602 endif 632 endif
633 endif
634
635 ## Is there a doc/ directory that needs to be installed
636 if (exist([packdir "doc"], "dir") && !dirempty([packdir "doc"]))
637 [status, output] = system(["cp -pR " packdir "doc " desc.dir]);
638 endif
639
640 ## Is there a bin/ directory that needs to be installed
641 if (exist([packdir "bin"], "dir") && !dirempty([packdir "bin"]))
642 [status, output] = system(["cp -pR " packdir "bin " desc.dir]);
603 endif 643 endif
604 endfunction 644 endfunction
605 645
606 function finish_installation (desc, packdir) 646 function finish_installation (desc, packdir)
607 ## Is there a post-install to call? 647 ## Is there a post-install to call?
985 dirs = cell(1, length(files)); 1025 dirs = cell(1, length(files));
986 for j = 1:length(files) 1026 for j = 1:length(files)
987 for i = 1:num_packages 1027 for i = 1:num_packages
988 if (strcmp(installed_packages{i}.name, files{j})) 1028 if (strcmp(installed_packages{i}.name, files{j}))
989 dirs{j} = installed_packages{i}.dir; 1029 dirs{j} = installed_packages{i}.dir;
1030 break;
990 endif 1031 endif
991 endfor 1032 endfor
992 error("Package %s is not installed\n", files{j}); 1033 if (isempty(dirs{j}))
1034 error("Package %s is not installed\n", files{j});
1035 endif
993 endfor 1036 endfor
994 endif 1037 endif
995 addpath(dirs{:}); 1038 addpath(dirs{:});
1039
1040 ## Add local binaries, if any, to the EXEC_PATH
1041 for i = 1:length(dirs)
1042 if (exist ([dirs{i} "/bin"],"dir"))
1043 EXEC_PATH ([dirs{i} "/bin:" EXEC_PATH()]);
1044 endif
1045 endfor
996 endfunction 1046 endfunction
997 1047
998 function [status_out, msg_out] = rm_rf (dir) 1048 function [status_out, msg_out] = rm_rf (dir)
999 crr = confirm_recursive_rmdir (); 1049 crr = confirm_recursive_rmdir ();
1000 unwind_protect 1050 unwind_protect
1008 endif 1058 endif
1009 if (nargout > 1) 1059 if (nargout > 1)
1010 msg_out = msg; 1060 msg_out = msg;
1011 endif 1061 endif
1012 endfunction 1062 endfunction
1063
1064 function emp = dirempty (nm, ign)
1065 if (nargin < 2)
1066 ign = {".",".."};
1067 else
1068 ign = [{".",".."},ign];
1069 endif
1070 l = dir (nm);
1071 for i=1:length(l)
1072 found = false;
1073 for j=1:length(ign)
1074 if (strcmp(l(i).name,ign{j}))
1075 found = true;
1076 break;
1077 endif
1078 endfor
1079 if (!found)
1080 emp = false;
1081 return
1082 endif
1083 endfor
1084 emp = true;
1085 return;
1086 endfunction