comparison scripts/miscellaneous/private/__xzip__.m @ 11587:c792872f8942

all script files: untabify and strip trailing whitespace
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:35:29 -0500
parents fd0a3ac60b0e
children a3019189ac51
comparison
equal deleted inserted replaced
11586:12df7854fa7c 11587:c792872f8942
20 ## -*- texinfo -*- 20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {@var{entries} =} __xzip__ (@var{commandname}, @var{extension}, @var{commandtemplate}, @var{files}, @var{outdir}) 21 ## @deftypefn {Function File} {@var{entries} =} __xzip__ (@var{commandname}, @var{extension}, @var{commandtemplate}, @var{files}, @var{outdir})
22 ## Undocumented internal function. 22 ## Undocumented internal function.
23 ## @end deftypefn 23 ## @end deftypefn
24 24
25 ## Compress the list of files and/or directories specified in @var{files} 25 ## Compress the list of files and/or directories specified in @var{files}
26 ## with the external compression command @var{commandname}. The template 26 ## with the external compression command @var{commandname}. The template
27 ## @var{commandtemplate} is used to actually start the command. Each file 27 ## @var{commandtemplate} is used to actually start the command. Each file
28 ## is compressed separately and a new file with the extension @var{extension} 28 ## is compressed separately and a new file with the extension @var{extension}
29 ## is created and placed into the directory @var{outdir}. The original files 29 ## is created and placed into the directory @var{outdir}. The original files
30 ## are not touched. Existing compressed files are silently overwritten. 30 ## are not touched. Existing compressed files are silently overwritten.
31 ## This is an internal function. Do not use directly. 31 ## This is an internal function. Do not use directly.
32 32
33 function entries = __xzip__ (commandname, extension, 33 function entries = __xzip__ (commandname, extension,
34 commandtemplate, files, outdir) 34 commandtemplate, files, outdir)
35 35
36 if (nargin == 4 || nargin == 5) 36 if (nargin == 4 || nargin == 5)
37 if (! ischar (extension) || length (extension) == 0) 37 if (! ischar (extension) || length (extension) == 0)
38 error ("__xzip__: EXTENSION has to be a string with finite length"); 38 error ("__xzip__: EXTENSION has to be a string with finite length");
39 endif 39 endif
40 40
41 if (nargin == 5 && ! exist (outdir, "dir")) 41 if (nargin == 5 && ! exist (outdir, "dir"))
42 error ("__xzip__: output directory does not exist"); 42 error ("__xzip__: output directory does not exist");
43 endif 43 endif
44 44
45 if (ischar (files)) 45 if (ischar (files))
56 cwd = pwd(); 56 cwd = pwd();
57 unwind_protect 57 unwind_protect
58 files = glob (files); 58 files = glob (files);
59 59
60 ## Ignore any file with the compress extension 60 ## Ignore any file with the compress extension
61 files (cellfun (@(x) length(x) > length(extension) 61 files (cellfun (@(x) length(x) > length(extension)
62 && strcmp (x((end - length(extension) + 1):end), extension), 62 && strcmp (x((end - length(extension) + 1):end), extension),
63 files)) = []; 63 files)) = [];
64 64
65 copyfile (files, outdir); 65 copyfile (files, outdir);
66 66
67 [d, f] = myfileparts(files); 67 [d, f] = myfileparts(files);
73 [status, output] = system (cmd); 73 [status, output] = system (cmd);
74 if (status == 0) 74 if (status == 0)
75 75
76 if (nargin == 5) 76 if (nargin == 5)
77 compressed_files = cellfun( 77 compressed_files = cellfun(
78 @(x) fullfile (outdir, sprintf ("%s.%s", x, extension)), 78 @(x) fullfile (outdir, sprintf ("%s.%s", x, extension)),
79 f, "uniformoutput", false); 79 f, "uniformoutput", false);
80 else 80 else
81 movefile (cellfun(@(x) sprintf ("%s.%s", x, extension), f, 81 movefile (cellfun(@(x) sprintf ("%s.%s", x, extension), f,
82 "uniformoutput", false), cwd); 82 "uniformoutput", false), cwd);
83 ## FIXME this does not work when you try to compress directories 83 ## FIXME this does not work when you try to compress directories
84 84
85 compressed_files = cellfun(@(x) sprintf ("%s.%s", x, extension), 85 compressed_files = cellfun(@(x) sprintf ("%s.%s", x, extension),
86 files, "uniformoutput", false); 86 files, "uniformoutput", false);
87 endif 87 endif
88 88
89 if (nargout > 0) 89 if (nargout > 0)
90 entries = compressed_files; 90 entries = compressed_files;
112 endfunction 112 endfunction
113 113
114 function [d, f] = myfileparts (files) 114 function [d, f] = myfileparts (files)
115 [d, f, ext] = cellfun (@(x) fileparts (x), files, "uniformoutput", false); 115 [d, f, ext] = cellfun (@(x) fileparts (x), files, "uniformoutput", false);
116 f = cellfun (@(x, y) sprintf ("%s%s", x, y), f, ext, 116 f = cellfun (@(x, y) sprintf ("%s%s", x, y), f, ext,
117 "uniformoutput", false); 117 "uniformoutput", false);
118 idx = cellfun (@isdir, files); 118 idx = cellfun (@isdir, files);
119 d(idx) = ""; 119 d(idx) = "";
120 f(idx) = files(idx); 120 f(idx) = files(idx);
121 endfunction 121 endfunction
122 122
123 ## FIXME -- reinstate these tests if we invent a way to test private 123 ## FIXME -- reinstate these tests if we invent a way to test private
124 ## functions directly. 124 ## functions directly.
125 ## 125 ##
126 ## %!error <extension has to be a string with finite length> 126 ## %!error <extension has to be a string with finite length>
127 ## %! __xzip__("gzip", "", "gzip -r %s", "bla"); 127 ## %! __xzip__("gzip", "", "gzip -r %s", "bla");
128 ## %!error <no files to move> 128 ## %!error <no files to move>
129 ## %! __xzip__("gzip", ".gz", "gzip -r %s", tmpnam); 129 ## %! __xzip__("gzip", ".gz", "gzip -r %s", tmpnam);
130 ## %!error <command failed with exit status> 130 ## %!error <command failed with exit status>
131 ## %! # test __xzip__ with invalid compression command 131 ## %! # test __xzip__ with invalid compression command
133 ## %! filename = tmpnam; 133 ## %! filename = tmpnam;
134 ## %! dummy = 1; 134 ## %! dummy = 1;
135 ## %! save(filename, "dummy"); 135 ## %! save(filename, "dummy");
136 ## %! dirname = tmpnam; 136 ## %! dirname = tmpnam;
137 ## %! mkdir(dirname); 137 ## %! mkdir(dirname);
138 ## %! entry = __xzip__("gzip", ".gz", "xxxzipxxx -r %s 2>/dev/null", 138 ## %! entry = __xzip__("gzip", ".gz", "xxxzipxxx -r %s 2>/dev/null",
139 ## %! filename, dirname); 139 ## %! filename, dirname);
140 ## %! unwind_protect_cleanup 140 ## %! unwind_protect_cleanup
141 ## %! delete(filename); 141 ## %! delete(filename);
142 ## %! rmdir(dirname); 142 ## %! rmdir(dirname);
143 ## %! end_unwind_protect 143 ## %! end_unwind_protect