octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Modifications to pkg.m


From: David Bateman
Subject: Modifications to pkg.m
Date: Fri, 25 Aug 2006 14:49:30 +0200
User-agent: Thunderbird 1.5.0.5 (X11/20060817)

I'd like to propose the following modifications to the package manager
in 2.9.8. Basically the changes are

1) Treat both PKG_ADD and PKG_DEL files. If the created PKG_* file is
empty remove it

2) If for some reason the directory for the package that is created is
empty, then remove the package. This allows system specific packages (eg
MacOSX) to attempt to be installed on other architecture fail gracefully.

3) Treat bin/ directories in the package, copying them the the package
directory, and adding them to the EXEC_PATH when the package is loaded

4) Install any doc/ directory with the package itself.

Basically with these changes the only package that is still causing me
issue in octave-forge is graceplot, due to the alternatives installation
directory. This while probably be easy enough to fix though.

Regards
David

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

*** pkg.m~      2006-08-25 10:52:28.587020272 +0200
--- pkg.m       2006-08-25 14:45:17.837043192 +0200
***************
*** 251,258 ****
          for i = 1:length(descriptions)
              desc = descriptions{i};
              pdir = packdirs{i};
!             copy_files(desc, pdir);
!           create_pkgadd(desc, pdir);
              finish_installation (desc, pdir)
          endfor
      catch
--- 251,259 ----
          for i = 1:length(descriptions)
              desc = descriptions{i};
              pdir = packdirs{i};
!           copy_files(desc, pdir);
!           create_pkgadddel(desc, pdir, "PKG_ADD");
!           create_pkgadddel(desc, pdir, "PKG_DEL");
              finish_installation (desc, pdir)
          endfor
      catch
***************
*** 260,269 ****
          for i = 1:length(tmpdirs)
              rm_rf(tmpdirs{i});
          endfor
          error(lasterr()(8:end));
      end_try_catch
  
!       ## Add the packages to the package list
      try
            if (global_install)
              idx = complement(packages_to_uninstall, 
1:length(global_packages));
--- 261,282 ----
          for i = 1:length(tmpdirs)
              rm_rf(tmpdirs{i});
          endfor
+         for i = 1:length(descriptions)
+             rm_rf(descriptions{i}.dir);
+         endfor
          error(lasterr()(8:end));
      end_try_catch
  
!     ## Check if the installed directory is empty. If it is remove it
!     ## from the list
!     for i = length(descriptions):-1:1
!       if (dirempty(descriptions{i}.dir,{".","..","packinfo"}))
!       rm_rf(descriptions{i}.dir);
!       descriptions(i) = [];
!       endif
!     endfor
! 
!     ## Add the packages to the package list
      try
            if (global_install)
              idx = complement(packages_to_uninstall, 
1:length(global_packages));
***************
*** 298,304 ****
      endfor
  
      ## Add the newly installed packages to the path, so the user
!     ## can begin the using.
      dirs = cell(1, length(descriptions));
      for i = 1:length(descriptions)
          dirs{i} = descriptions{i}.dir;
--- 311,317 ----
      endfor
  
      ## Add the newly installed packages to the path, so the user
!     ## can begin usings them.
      dirs = cell(1, length(descriptions));
      for i = 1:length(descriptions)
          dirs{i} = descriptions{i}.dir;
***************
*** 499,546 ****
      endif
  endfunction
  
! function pkgadd = extract_pkgadd (nm, pat)
    fid = fopen (nm, "rt");
!   pkgadd = "";
    if (fid >= 0)
      while (! feof(fid))
        ln = fgetl (fid);
        if (ln > 0)
        t = regexp(ln, pat, "tokens","dotexceptnewline");
        if (!isempty(t))
!           pkgadd = [pkgadd, "\n", t{1}{1}];
        endif
        endif
      endwhile
!     if (!isempty(pkgadd))
!       pkgadd = [pkgadd, "\n"];
      endif
      fclose (fid);
    endif
  endfunction
  
! function create_pkgadd (desc, packdir)
!   pkgadd = [desc.dir "/PKG_ADD"];
!   fid = fopen(pkgadd, "wt");
    if (fid >= 0)
!     ## Search all dot-m files for PKG_ADD commands
      lst = dir ([packdir "inst/*.m"]);
      for i=1:length(lst)
        nm = lst(i).name;
!       fwrite (fid, extract_pkgadd (nm, '^[#%][#%]* *PKG_ADD: *(.*)$'));
      endfor
  
!     ## Search all C++ source files for PKG_ADD commands
      lst = dir ([packdir "src/*.cc"]);
      for i=1:length(lst)
        nm = lst(i).name;
!       fwrite (fid, extract_pkgadd (nm, '^//* *PKG_ADD: *(.*)$'));
!       fwrite (fid, extract_pkgadd (nm, '^/\** *PKG_ADD: *(.*) *\*/$'));
      endfor
  
!     ## Add developer included PKG_ADD commands
!     if (exist([packdir "PKG_ADD"],"file"))
!       fid2 = fopen([packdir "PKG_ADD"],"rt");
        if (fid2 >= 0)
          while (! feof(fid2))
            ln = fgets (fid2);
--- 512,559 ----
      endif
  endfunction
  
! function pkg = extract_pkg (nm, pat)
    fid = fopen (nm, "rt");
!   pkg = "";
    if (fid >= 0)
      while (! feof(fid))
        ln = fgetl (fid);
        if (ln > 0)
        t = regexp(ln, pat, "tokens","dotexceptnewline");
        if (!isempty(t))
!           pkg = [pkg, "\n", t{1}{1}];
        endif
        endif
      endwhile
!     if (!isempty(pkg))
!       pkg = [pkg, "\n"];
      endif
      fclose (fid);
    endif
  endfunction
  
! function create_pkgadddel (desc, packdir, nm)
!   pkg = [desc.dir "/" nm];
!   fid = fopen(pkg, "wt");
    if (fid >= 0)
!     ## Search all dot-m files for PKG commands
      lst = dir ([packdir "inst/*.m"]);
      for i=1:length(lst)
        nm = lst(i).name;
!       fwrite (fid, extract_pkg (nm, ['^[#%][#%]* *' nm ': *(.*)$']));
      endfor
  
!     ## Search all C++ source files for PKG commands
      lst = dir ([packdir "src/*.cc"]);
      for i=1:length(lst)
        nm = lst(i).name;
!       fwrite (fid, extract_pkg (nm, ['^//* *' nm ': *(.*)$']));
!       fwrite (fid, extract_pkg (nm, ['^/\** *' nm ': *(.*) *\*/$']));
      endfor
  
!     ## Add developer included PKG commands
!     if (exist([packdir nm],"file"))
!       fid2 = fopen([packdir nm],"rt");
        if (fid2 >= 0)
          while (! feof(fid2))
            ln = fgets (fid2);
***************
*** 548,560 ****
              fwrite(fid, ln);
            endif
          endwhile
        endif
      endif
      fclose(fid);
    endif
  endfunction
  
! function copy_files (desc, packdir)
      ## Copy the files from "inst" to installdir
      [status, output] = system(["cp -R " packdir "inst/* " desc.dir]);
      if (status != 0)
--- 561,580 ----
              fwrite(fid, ln);
            endif
          endwhile
+         fclose(fid2);
        endif
      endif
      fclose(fid);
+ 
+     ## If the file is empty remove it
+     t = dir (pkg);
+     if (t.bytes <= 0)
+       unlink (pkg);
+     endif
    endif
  endfunction
  
! function copy_files (desc, packdir, bindir)
      ## Copy the files from "inst" to installdir
      [status, output] = system(["cp -R " packdir "inst/* " desc.dir]);
      if (status != 0)
***************
*** 601,606 ****
--- 621,636 ----
              error("Couldn't copy on_uninstall.m: %s\n", output);
          endif
      endif
+ 
+     ## Is there a doc/ directory that needs to be installed
+     if (exist([packdir "doc"], "dir") && !dirempty([packdir 
"doc"],{".",".."}))
+        [status, output] = system(["cp -pR " packdir "doc " desc.dir]);
+     endif
+ 
+     ## Is there a bin/ directory that needs to be installed
+     if (exist([packdir "bin"], "dir") && !dirempty([packdir 
"bin"],{".",".."}))
+        [status, output] = system(["cp -pR " packdir "bin " desc.dir]);
+     endif
  endfunction
  
  function finish_installation (desc, packdir)
***************
*** 987,998 ****
              for i = 1:num_packages
                  if (strcmp(installed_packages{i}.name, files{j}))
                      dirs{j} = installed_packages{i}.dir;
                  endif
              endfor
!             error("Package %s is not installed\n", files{j});
          endfor
      endif
      addpath(dirs{:});
  endfunction
  
  function [status_out, msg_out] = rm_rf (dir)
--- 1017,1038 ----
              for i = 1:num_packages
                  if (strcmp(installed_packages{i}.name, files{j}))
                      dirs{j} = installed_packages{i}.dir;
+                   break;
                  endif
              endfor
!           if (isempty(dirs{j}))
!               error("Package %s is not installed\n", files{j});
!             endif
          endfor
      endif
      addpath(dirs{:});
+ 
+     ## Add local binaries, if any, to the EXEC_PATH
+     for i = 1:length(dirs)
+        if (exist ([dirs{i} "/bin"],"dir"))
+          EXEC_PATH ([dirs{i} "/bin:" EXEC_PATH()]);
+        endif
+     endfor
  endfunction
  
  function [status_out, msg_out] = rm_rf (dir)
***************
*** 1010,1012 ****
--- 1050,1066 ----
      msg_out = msg;
    endif
  endfunction
+ 
+ function emp = dirempty (nm, ign)
+   l = dir (nm);
+   for i=1:length(l)
+     for j=1:length(ign)
+       if (!strcmp(l(i).name,ign{j}))
+         emp = false;
+         return;
+       endif
+     endfor
+   endfor
+   emp = true;
+   return;
+ endfunction

reply via email to

[Prev in Thread] Current Thread [Next in Thread]