[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[changeset] clean up __xzip__, gzip and bzip2, fix broken documentation
From: |
Thorsten Meyer |
Subject: |
[changeset] clean up __xzip__, gzip and bzip2, fix broken documentation |
Date: |
Sat, 29 Nov 2008 10:22:35 +0100 |
User-agent: |
Mozilla-Thunderbird 2.0.0.17 (X11/20081018) |
Hi,
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.
regards
Thorsten
# HG changeset patch
# User Thorsten Meyer <address@hidden>
# Date 1227949661 -3600
# Node ID d3be9049238596096c4b3d7693434205eef80548
# Parent 7918f4b499732ab390980fd27b67a82e8bc348cf
clean up bzip2, gzip and __xzip__
diff -r 7918f4b49973 -r d3be90492385 scripts/ChangeLog
--- a/scripts/ChangeLog Fri Nov 28 22:49:30 2008 +0100
+++ b/scripts/ChangeLog Sat Nov 29 10:07:41 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 7918f4b49973 -r d3be90492385 scripts/miscellaneous/__xzip__.m
--- a/scripts/miscellaneous/__xzip__.m Fri Nov 28 22:49:30 2008 +0100
+++ b/scripts/miscellaneous/__xzip__.m Sat Nov 29 10:07:41 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 7918f4b49973 -r d3be90492385 scripts/miscellaneous/bzip2.m
--- a/scripts/miscellaneous/bzip2.m Fri Nov 28 22:49:30 2008 +0100
+++ b/scripts/miscellaneous/bzip2.m Sat Nov 29 10:07:41 2008 +0100
@@ -25,15 +25,36 @@
## 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);
+%! delete([filename, ".bz2"]);
+%! end_unwind_protect
diff -r 7918f4b49973 -r d3be90492385 scripts/miscellaneous/gzip.m
--- a/scripts/miscellaneous/gzip.m Fri Nov 28 22:49:30 2008 +0100
+++ b/scripts/miscellaneous/gzip.m Sat Nov 29 10:07:41 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
- [changeset] clean up __xzip__, gzip and bzip2, fix broken documentation,
Thorsten Meyer <=