octave-maintainers
[Top][All Lists]
Advanced

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

Re: [changeset] clean up __xzip__, gzip and bzip2, fix broken documentat


From: Thorsten Meyer
Subject: Re: [changeset] clean up __xzip__, gzip and bzip2, fix broken documentation
Date: Sat, 29 Nov 2008 23:06:12 +0100
User-agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018)

Thorsten Meyer wrote:
> attached you will find a changeset that cleans up the functions __xzip__, 
> gzip and
> bzip2. In particular, it removes the @seealso references to __xzip__ which 
> led to
> a build failure of the documentation.
> 
oops, there was a little bug in the bzip2 test. Here a corrected version of the 
changeset:

Thorsten
# HG changeset patch
# User Thorsten Meyer <address@hidden>
# Date 1227996196 -3600
# Node ID 837027b45d3b3ccddb8ec0b9199da727a1a83d71
# Parent  1b1cf880c98d2f71cbce52889a41ad298c7b7197
clean up bzip2, gzip and __xzip__

diff -r 1b1cf880c98d -r 837027b45d3b scripts/ChangeLog
--- a/scripts/ChangeLog Sat Nov 29 22:34:08 2008 +0100
+++ b/scripts/ChangeLog Sat Nov 29 23:03:16 2008 +0100
@@ -1,3 +1,12 @@
+2008-11-29  Thorsten Meyer  <address@hidden>
+
+        * miscellaneous/gzip.m: Remove @seealso reference to __xzip__,
+          improve tests
+          miscellaneous/bzip2.m: Remove @seealso reference to __xzip__,
+          fix handling of output argument, add test
+          miscellaneous/__xzip__.m: Improve error messages, fix cleanup
+          of temporary directories, remove tab characters
+
 2008-11-24  Ben Abbott <address@hidden>
 
        * plot/legend.m: Correct ording of legend labels.
diff -r 1b1cf880c98d -r 837027b45d3b scripts/miscellaneous/__xzip__.m
--- a/scripts/miscellaneous/__xzip__.m  Sat Nov 29 22:34:08 2008 +0100
+++ b/scripts/miscellaneous/__xzip__.m  Sat Nov 29 23:03:16 2008 +0100
@@ -44,6 +44,8 @@
 
     if (ischar (files))
       files = cellstr (files);
+    else
+      error ("__xzip__: expecting FILES to be a character array");
     endif
 
     if (nargin == 4)
@@ -53,59 +55,54 @@
 
     cwd = pwd();
     unwind_protect
-      if (iscellstr (files))
-       files = glob (files);
+      files = glob (files);
 
-       ## Ignore any file with the compress extension
-       files (cellfun (@(x) length(x) > length(extension) 
-          && strcmp (x((end - length(extension) + 1):end), extension), 
-          files)) = [];
-        
-       copyfile (files, outdir);
+      ## Ignore any file with the compress extension
+      files (cellfun (@(x) length(x) > length(extension) 
+        && strcmp (x((end - length(extension) + 1):end), extension), 
+        files)) = [];
 
-       [d, f] = myfileparts(files);
-        
-       cd (outdir);
+      copyfile (files, outdir);
 
-       cmd = sprintf (commandtemplate, sprintf (" %s", f{:}));
+      [d, f] = myfileparts(files);
 
-       [status, output] = system (cmd);
-       if (status == 0)
+      cd (outdir);
 
-         if (nargin == 5)
-           compressed_files = cellfun(
-                @(x) fullfile (outdir, sprintf ("%s.%s", x, extension)), 
-                f, "UniformOutput", false);
-         else
-           movefile (cellfun(@(x) sprintf ("%s.%s", x, extension), f, 
-                             "UniformOutput", false), cwd);
-            ## FIXME this does not work when you try to compress directories
-                     
-           compressed_files  = cellfun(@(x) sprintf ("%s.%s", x, extension), 
-                             files, "UniformOutput", false);
-         endif
+      cmd = sprintf (commandtemplate, sprintf (" %s", f{:}));
 
-         if (nargout > 0)
-            entries = compressed_files;
-         endif
-       else
-         error (sprintf("%s command failed with exit status = %d", 
-                         commandname, status));
-       endif
-    
+      [status, output] = system (cmd);
+      if (status == 0)
+
+        if (nargin == 5)
+          compressed_files = cellfun(
+              @(x) fullfile (outdir, sprintf ("%s.%s", x, extension)), 
+              f, "UniformOutput", false);
+        else
+          movefile (cellfun(@(x) sprintf ("%s.%s", x, extension), f, 
+                            "UniformOutput", false), cwd);
+          ## FIXME this does not work when you try to compress directories
+
+          compressed_files  = cellfun(@(x) sprintf ("%s.%s", x, extension), 
+                            files, "UniformOutput", false);
+        endif
+
+        if (nargout > 0)
+          entries = compressed_files;
+        endif
       else
-       error ("__xzip__: expecting all arguments to be character strings");
+        error (sprintf("%s command failed with exit status = %d", 
+                       commandname, status));
       endif
     unwind_protect_cleanup
       cd(cwd);
-      if (nargin == 1)
-       crr = confirm_recursive_rmdir ();
-       unwind_protect
-         confirm_recursive_rmdir (false);
-         rmdir (outdir, "s");
-       unwind_protect_cleanup
-         confirm_recursive_rmdir (crr);
-       end_unwind_protect
+      if (nargin == 4)
+        crr = confirm_recursive_rmdir ();
+        unwind_protect
+          confirm_recursive_rmdir (false);
+          rmdir (outdir, "s");
+        unwind_protect_cleanup
+          confirm_recursive_rmdir (crr);
+        end_unwind_protect
       endif
     end_unwind_protect
   else
@@ -117,7 +114,7 @@
 function [d, f] = myfileparts (files)
   [d, f, ext] = cellfun (@(x) fileparts (x), files, "UniformOutput", false);
   f = cellfun (@(x, y) sprintf ("%s%s", x, y), f, ext,
-              "UniformOutput", false); 
+               "UniformOutput", false); 
   idx = cellfun (@(x) isdir (x), files);
   d(idx) = "";
   f(idx) = files(idx);
diff -r 1b1cf880c98d -r 837027b45d3b scripts/miscellaneous/bzip2.m
--- a/scripts/miscellaneous/bzip2.m     Sat Nov 29 22:34:08 2008 +0100
+++ b/scripts/miscellaneous/bzip2.m     Sat Nov 29 23:03:16 2008 +0100
@@ -25,15 +25,37 @@
 ## is created. The original files are not touched.  Existing compressed files 
 ## are silently overwritten.If @var{outdir} is defined the compressed versions 
 ## of the files are placed in this directory.
-## @seealso{bunzip2, gzip, zip, tar, __xzip__}
+## @seealso{bunzip2, gzip, zip, tar}
 ## @end deftypefn
 
 function entries = bzip2 (varargin)
 
   if (nargin == 1 || nargin == 2)
-    __xzip__ ("bzip2", "bz2", "bzip2 %s", varargin{:});
+    if nargout == 0
+      __xzip__ ("bzip2", "bz2", "bzip2 %s", varargin{:});
+    else
+      entries = __xzip__ ("bzip2", "bz2", "bzip2 %s", varargin{:});
+    endif      
   else
     print_usage ();
   endif
 
 endfunction
+
+%!xtest
+%!  # test for correct cleanup of temporary files
+%!  unwind_protect
+%!    filename = tmpnam;
+%!    dummy    = 1;
+%!    save(filename, "dummy");
+%!    n_tmpfiles_before = length(find(strncmp("oct-", cellstr(ls(P_tmpdir)), 
4)));
+%!    entry = bzip2(filename);
+%!    n_tmpfiles_after = length(find(strncmp("oct-", cellstr(ls(P_tmpdir)), 
4)));
+%!    if (n_tmpfiles_before != n_tmpfiles_after)
+%!      error("bzip2 has not cleaned up temporary files correctly!");
+%!    endif
+%!  unwind_protect_cleanup
+%!    delete(filename);
+%!    [path, basename, extension] = fileparts(filename);
+%!    delete([basename, extension, ".bz2"]);
+%!  end_unwind_protect
diff -r 1b1cf880c98d -r 837027b45d3b scripts/miscellaneous/gzip.m
--- a/scripts/miscellaneous/gzip.m      Sat Nov 29 22:34:08 2008 +0100
+++ b/scripts/miscellaneous/gzip.m      Sat Nov 29 23:03:16 2008 +0100
@@ -24,7 +24,7 @@
 ## is created. The original files are not touched. Existing compressed
 ## files are silently overwritten. If @var{outdir} is defined the compressed 
 ## versions of the files are placed in this directory.
-## @seealso{gunzip, bzip2, zip, tar, __xzip__}
+## @seealso{gunzip, bzip2, zip, tar}
 ## @end deftypefn
 
 function entries = gzip (varargin)
@@ -42,8 +42,9 @@
 %!error <Invalid call to gzip.  Correct usage is> gzip("1", "2", "3");
 %!error <Invalid call to gzip.  Correct usage is> gzip();
 %!error <output directory does not exist> gzip("1", tmpnam);
-%!error <expecting all arguments to be character strings> gzip(1);
+%!error <expecting FILES to be a character array> gzip(1);
 %!xtest
+%!  # test gzip together with gunzip
 %!  unwind_protect
 %!    filename = tmpnam;
 %!    dummy    = 1;
@@ -58,8 +59,13 @@
 %!    if ! exist(entry, "file")
 %!      error("gzipped file cannot be found!");
 %!    endif 
+%!    gunzip(entry);
+%!    if (system(sprintf("diff %s %s/%s%s", filename, dirname, 
+%!                                          basename, extension)))
+%!      error("unzipped file not equal to original file!");
+%!    end
 %!  unwind_protect_cleanup
 %!    delete(filename);
-%!    delete(entry{:});
+%!    delete([dirname, "/", basename, extension]);
 %!    rmdir(dirname);
 %!  end_unwind_protect

reply via email to

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