octave-maintainers
[Top][All Lists]
Advanced

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

Re: pkg manager improvement?


From: David Bateman
Subject: Re: pkg manager improvement?
Date: Sun, 20 May 2007 23:11:02 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

Michael Goffioul wrote:
> On 5/20/07, David Bateman <address@hidden> wrote:
>> Yes that isn't a bad feature to have. It might need a new pkg target
>> though.. I'd though to add an install option to force local/global
>> installation as well as there seems to be issues with the issuperuser
>> function
>>
>>
>> >
>> > 2) from a packaging point of view, it would be nice to be able to
>> install
>> > a pre-compiled package into the right location and simply tell the
>> package
>> > manager to update its internal data structure, without any
>> compilation step
>>
>> Create a binary package with everything in the inst/ directory.. That is
>> what I do with the srpms in octave-forge..
> 
> I also thought about a useful (IMO) feature: the ability to recreate
> the global_list
> data structure from the packages directory (I guess that loading
> packinfo/DESCRIPTION and checking for packinfo/.autoload is enough).
> In the
> context of the Windows installer, this would ease my work as I would
> just have
> to install the selected packages (selected in the installer) and in a
> final step
> to run "pkg admin -rebuild" (for instance) to create the global_list.
> This could also
> be used to recover from any damaged global_list file.
> 
> Michael.
> 


Then what about something like the attached, that takes your patch and
adds a "rebuild" target for pkg..

Regards
David
Index: scripts/miscellaneous/copyfile.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/miscellaneous/copyfile.m,v
retrieving revision 1.6
diff -u -r1.6 copyfile.m
--- scripts/miscellaneous/copyfile.m    8 Mar 2007 19:40:01 -0000       1.6
+++ scripts/miscellaneous/copyfile.m    20 May 2007 20:59:54 -0000
@@ -40,7 +40,7 @@
   ## FIXME -- maybe use the same method as in ls to allow users control
   ## over the command that is executed.
 
-  if (ispc () && ! isunix () && isempty (file_in_path (EXEC_PATH, "cp")))
+  if (ispc () && ! isunix () && isempty (file_in_path (EXEC_PATH, "cp.exe")))
     ## Windows.
     cmd = "cmd /C xcopy /E";
     cmd_force_flag = "/Y";
@@ -73,6 +73,11 @@
     f1 = sprintf ("\"%s\" ", f1{:});
 
     f2 = tilde_expand (f2);
+  
+    if (ispc () && ! isunix () && ! isempty (file_in_path (EXEC_PATH, 
"cp.exe")))
+      f1 = strrep (f1, "\\", "/");
+      f2 = strrep (f2, "\\", "/");
+    endif
 
     ## Copy the files.
     [err, msg] = system (sprintf ("%s %s \"%s\"", cmd, f1, f2));
Index: scripts/pkg/pkg.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/pkg/pkg.m,v
retrieving revision 1.44
diff -u -r1.44 pkg.m
--- scripts/pkg/pkg.m   18 May 2007 21:38:13 -0000      1.44
+++ scripts/pkg/pkg.m   20 May 2007 20:59:54 -0000
@@ -124,6 +124,9 @@
 ## @example
 ## pkg global_list
 ## @end example
+## @item rebuild
+## Rebuilds the package database from the installed directories. This can 
+## be used in cases where for some reason the package database is corrupted
 ## @end table
 ## @end deftypefn
 
@@ -167,7 +170,7 @@
       case "-verbose"
        verbose = true;
       case {"list", "install", "uninstall", "load", "unload", ...
-           "prefix", "local_list", "global_list"}
+           "prefix", "local_list", "global_list", "rebuild"}
        action = varargin{i};
       otherwise
        files{end+1} = varargin{i};
@@ -247,11 +250,44 @@
       else
        error ("you must specify a global_list file, or request an output 
argument");
       endif
+
+    case "rebuild"
+      if (issuperuser ())
+       global_packages = rebuild (prefix, global_list, verbose);
+       save (global_list, "global_packages");
+       local_packages = global_packages;
+      else
+       local_packages = rebuild (prefix, local_list, verbose);
+       save (local_list, "local_packages");
+      endif
+
     otherwise
       error ("you must specify a valid action for 'pkg'. See 'help pkg' for 
details");
   endswitch
 endfunction
 
+function descriptions = rebuild (prefix, list, verbose)
+  [dirlist, err, msg] = readdir (prefix);
+  if (err)
+    error ("couldn't read directory %s: %s", prefix, msg);
+  endif
+  descriptions = {};
+  ## the two first entries of dirlist are "." and ".."
+  for k = 3:length (dirlist)
+    descfile = fullfile (prefix, dirlist{k}, "packinfo", "DESCRIPTION");
+    if (verbose)
+      printf ("recreating package description from %s\n", dirlist{k});
+    endif
+    if (exist (descfile, "file"))
+      desc = get_description (descfile);
+      desc.dir = fullfile (prefix, dirlist{k});
+      descriptions{end + 1} = desc;
+    elseif (verbose)
+      warning ("directory %s is not a valid package", dirlist{k});
+    endif
+  endfor
+endfunction
+
 function auto = isautoload (desc)
 auto = false;
 if (isfield (desc{1}, "autoload"))
@@ -299,66 +335,70 @@
     for i = 1:length (files)
       tgz = files{i};
 
-      ## Create a temporary directory 
-      tmpdir = tmpnam ();
-      tmpdirs{end+1} = tmpdir;
-      if (verbose)
-       printf ("mkdir (%s)\n", tmpdir);
-      endif
-      [status, msg] = mkdir (tmpdir);
-      if (status != 1)
-       error ("couldn't create temporary directory: %s", msg);
-      endif
-
-      ## Uncompress the package
-      if (verbose)
-       printf ("untar (%s, %s)\n", tgz, tmpdir);
-      endif
-      untar (tgz, tmpdir);
-
-      ## Get the name of the directories produced by tar
-      [dirlist, err, msg] = readdir (tmpdir);
-      if (err)
-       error ("couldn't read directory produced by tar: %s", msg);
-      endif
-
-      if (length (dirlist) > 3)
-       error ("bundles of packages are not allowed")
-      endif
-
-      ## the two first entries of dirlist are "." and ".."
-      for k = 3:length (dirlist)
-       packdir = fullfile (tmpdir, dirlist{k});
-       packdirs{end+1} = packdir;
+      if (exist (tgz, "file"))
+       ## Create a temporary directory 
+       tmpdir = tmpnam ();
+       tmpdirs{end+1} = tmpdir;
+        if (verbose)
+         printf ("mkdir (%s)\n", tmpdir);
+       endif
+       [status, msg] = mkdir (tmpdir);
+       if (status != 1)
+         error ("couldn't create temporary directory: %s", msg);
+       endif
 
-       ## Make sure the package contains necessary files
-       verify_directory (packdir);
+       ## Uncompress the package
+       if (verbose)
+         printf ("untar (%s, %s)\n", tgz, tmpdir);
+       endif
+       untar (tgz, tmpdir);
 
-       ## Read the DESCRIPTION file
-       filename = fullfile (packdir, "DESCRIPTION");
-       desc = get_description (filename);
+       ## Get the name of the directories produced by tar
+       [dirlist, err, msg] = readdir (tmpdir);
+       if (err)
+         error ("couldn't read directory produced by tar: %s", msg);
+       endif
 
-       ## Verify that package name corresponds with filename
-       [dummy, nm] = fileparts (tgz); 
-       if ((length (nm) >= length (desc.name))
-           && ! strcmp (desc.name, nm(1:length(desc.name))))
-         error ("package name '%s' doesn't correspond to its filename '%s'", 
desc.name, nm);
+       if (length (dirlist) > 3)
+         error ("bundles of packages are not allowed")
        endif
 
-       ## Set default installation directory
-       desc.dir = fullfile (prefix, strcat (desc.name, "-", desc.version));
+       ## the two first entries of dirlist are "." and ".."
+       for k = 3:length (dirlist)
+         packdir = fullfile (tmpdir, dirlist{k});
+         packdirs{end+1} = packdir;
+
+         ## Make sure the package contains necessary files
+         verify_directory (packdir);
+
+         ## Read the DESCRIPTION file
+         filename = fullfile (packdir, "DESCRIPTION");
+         desc = get_description (filename);
+
+         ## Verify that package name corresponds with filename
+         [dummy, nm] = fileparts (tgz); 
+         if ((length (nm) >= length (desc.name))
+             && ! strcmp (desc.name, nm(1:length(desc.name))))
+           error ("package name '%s' doesn't correspond to its filename '%s'", 
desc.name, nm);
+         endif
 
-       ## Save desc
-       descriptions{end+1} = desc;
+         ## Set default installation directory
+         desc.dir = fullfile (prefix, strcat (desc.name, "-", desc.version));
 
-       ## Are any of the new packages already installed?
-       ## If so we'll remove the old version.
-       for j = 1:length (packages)
-         if (strcmp (packages{j}.name, desc.name))
-           packages_to_uninstall(end+1) = j;
-         endif
-       endfor
-      endfor        
+         ## Save desc
+         descriptions{end+1} = desc;
+
+         ## Are any of the new packages already installed?
+         ## If so we'll remove the old version.
+         for j = 1:length (packages)
+           if (strcmp (packages{j}.name, desc.name))
+             packages_to_uninstall(end+1) = j;
+           endif
+         endfor
+       endfor        
+      else
+       warning ("file %s does not exist", tgz);
+      endif
     endfor
   catch
     ## Something went wrong, delete tmpdirs
@@ -665,8 +705,12 @@
     src = fullfile (packdir, "src");
     ## configure
     if (exist (fullfile (src, "configure"), "file"))
-      [status, output] = system (strcat ("cd ", src, "; ./configure --prefix=",
-                                        desc.dir));
+      [status, output] = shell (strcat ("cd ", src, "; ./configure 
--prefix=\"",
+                                        desc.dir, "\"",
+                                        " CC=", octave_config_info ("CC"),
+                                        " CXX=", octave_config_info ("CXX"),
+                                        " AR=", octave_config_info ("AR"),
+                                        " RANLIB=", octave_config_info 
("RANLIB")));
       if (verbose)
        printf("%s", output);
       endif
@@ -678,8 +722,8 @@
 
     ## make
     if (exist (fullfile (src, "Makefile"), "file"))
-      [status, output] = system (strcat ("export INSTALLDIR=", desc.dir,
-                                        "; make -C ", src));
+      [status, output] = shell (strcat ("export INSTALLDIR=\"", desc.dir,
+                                        "\"; make -C ", src));
       if (verbose)
        printf("%s", output);
       endif
@@ -978,7 +1022,12 @@
 endfunction
 
 function out = issuperuser ()
-  out = strcmp (getenv("USER"), "root");
+  if (ispc () && ! isunix ())
+    out = 1;
+  else
+    ## Need to be a bit presistent in probing superuser
+    out = (geteuid() == 0);
+  endif
 endfunction
 
 ## This function makes sure the package contains the
@@ -1275,9 +1324,9 @@
   endif  
 
   ## Now check if the package is loaded
-  tmppath = path();
+  tmppath = strrep (path(), "\\", "/");
   for i = 1:length (installed_packages)
-    if (regexp (tmppath, installed_packages{i}.dir))
+    if (regexp (tmppath, strrep (installed_packages{i}.dir, "\\", "/")))
       installed_packages{i}.loaded = true;
     else
       installed_packages{i}.loaded = false;
@@ -1520,3 +1569,29 @@
    octave_config_info("api_version")];
   arch = _arch;
 endfunction
+
+function [status, output] = shell (cmd)
+
+  persistent have_sh;
+
+  cmd = strrep (cmd, "\\", "/");
+  disp (cmd);
+  if (ispc () && ! isunix ())
+    if (isempty(have_sh))
+      if (system("sh.exe -c \"exit\""))
+        have_sh = false;
+      else
+        have_sh = true;
+      endif
+    endif
+    if (have_sh)
+      [status, output] = system (["sh.exe -c \"", cmd, "\""]);
+    else
+      error ("Can not find the command shell")
+    endif
+  else
+    [status, output] = system (cmd);
+  endif
+  disp(output);
+
+endfunction
2007-05-20  David Bateman  <address@hidden>

        * miscellaneous/copyfile.m: check for cp.exe on Windows platforms
        and replace "\" characters with "/".
        * pkg/pkg.m: Add rebuild target. Use shell rather than system
        throughout. Replace "\" characters with "/" throughout.
        (shell): New subfunction that wraps system and is careful with the
        shell on windows platforms.
        (rebuild): New subfunction to rebuild package database from
        installed packages.
        (install): Warn use if attempting to install from non existent
        file. 
        (configure_make): Explictly pass complier etc to configure
        process.
        (issuperuser): Use 'geteuid() == 0' instead of 'strcmp (getenv(
        "USER", "root"))' for root test.

reply via email to

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