Mercurial > hg > octave-lyh
annotate scripts/miscellaneous/private/__xzip__.m @ 17345:a31b54b5f84a
Use only 1 space between '%!' and start of test/demo code.
* libinterp/corefcn/besselj.cc, scripts/miscellaneous/private/__xzip__.m,
scripts/statistics/tests/kolmogorov_smirnov_test.m, scripts/ui/msgbox.m,
test/global.tst, test/jit.tst: Use only 1 space between '%!' and start of
test/demo code.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 28 Aug 2013 08:29:38 -0700 |
parents | abf384f5d243 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13952
diff
changeset
|
1 ## Copyright (C) 2008-2012 Thorsten Meyer |
8349 | 2 ## based on the original gzip function by David Bateman |
3 ## | |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
8 ## the Free Software Foundation; either version 3 of the License, or (at | |
9 ## your option) any later version. | |
10 ## | |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
17 ## along with Octave; see the file COPYING. If not, see | |
18 ## <http://www.gnu.org/licenses/>. | |
19 | |
20 ## -*- texinfo -*- | |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8443
diff
changeset
|
21 ## @deftypefn {Function File} {@var{entries} =} __xzip__ (@var{commandname}, @var{extension}, @var{commandtemplate}, @var{files}, @var{outdir}) |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8443
diff
changeset
|
22 ## Undocumented internal function. |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8443
diff
changeset
|
23 ## @end deftypefn |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8443
diff
changeset
|
24 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
25 ## Compress the list of files and/or directories specified in @var{files} |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
26 ## with the external compression command @var{commandname}. The template |
8349 | 27 ## @var{commandtemplate} is used to actually start the command. Each file |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
28 ## is compressed separately and a new file with the extension @var{extension} |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
29 ## is created and placed into the directory @var{outdir}. The original files |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
30 ## are not touched. Existing compressed files are silently overwritten. |
8349 | 31 ## This is an internal function. Do not use directly. |
32 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
33 function entries = __xzip__ (commandname, extension, |
8349 | 34 commandtemplate, files, outdir) |
35 | |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
36 if (nargin == 5 && ! exist (outdir, "dir")) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
37 error ("__xzip__: OUTDIR output directory does not exist"); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
38 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
39 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
40 if (ischar (files)) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
41 files = cellstr (files); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
42 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
43 if (! iscellstr (files)) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
44 error ("__xzip__: FILES must be a character array or cellstr"); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
45 endif |
8349 | 46 |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
47 if (nargin == 4) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
48 outdir = tmpnam (); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
49 mkdir (outdir); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
50 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
51 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
52 cwd = pwd (); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
53 unwind_protect |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
54 files = glob (files); |
8349 | 55 |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
56 ## Ignore any file with the compress extension |
16310
e7f6c479ce1c
* __xzip__.m: Use parens around anonymous function expression that spans multiple lines.
John W. Eaton <jwe@octave.org>
parents:
14868
diff
changeset
|
57 files(cellfun (@(x) (length (x) > length (extension) |
e7f6c479ce1c
* __xzip__.m: Use parens around anonymous function expression that spans multiple lines.
John W. Eaton <jwe@octave.org>
parents:
14868
diff
changeset
|
58 && strcmp (x((end - length (extension) + 1):end), |
e7f6c479ce1c
* __xzip__.m: Use parens around anonymous function expression that spans multiple lines.
John W. Eaton <jwe@octave.org>
parents:
14868
diff
changeset
|
59 extension)), |
e7f6c479ce1c
* __xzip__.m: Use parens around anonymous function expression that spans multiple lines.
John W. Eaton <jwe@octave.org>
parents:
14868
diff
changeset
|
60 files)) = []; |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
61 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
62 copyfile (files, outdir); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
63 |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
64 [d, f] = myfileparts (files); |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
65 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
66 cd (outdir); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
67 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
68 cmd = sprintf (commandtemplate, sprintf (" %s", f{:})); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
69 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
70 [status, output] = system (cmd); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
71 if (status) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
72 error ("__xzip__: %s command failed with exit status = %d", |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
73 commandname, status); |
8349 | 74 endif |
75 | |
12953
5cc3b7673d25
__xzip__: Fix regression about moving compressed files (bug #33993)
Orion Poplawski <orion@cora.nwra.com>
parents:
12499
diff
changeset
|
76 if (nargin == 5) |
5cc3b7673d25
__xzip__: Fix regression about moving compressed files (bug #33993)
Orion Poplawski <orion@cora.nwra.com>
parents:
12499
diff
changeset
|
77 if (nargout > 0) |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
78 entries = cellfun( |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
79 @(x) fullfile (outdir, sprintf ("%s.%s", x, extension)), |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
80 f, "uniformoutput", false); |
12953
5cc3b7673d25
__xzip__: Fix regression about moving compressed files (bug #33993)
Orion Poplawski <orion@cora.nwra.com>
parents:
12499
diff
changeset
|
81 endif |
5cc3b7673d25
__xzip__: Fix regression about moving compressed files (bug #33993)
Orion Poplawski <orion@cora.nwra.com>
parents:
12499
diff
changeset
|
82 else |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
83 movefile (cellfun (@(x) sprintf ("%s.%s", x, extension), f, |
12953
5cc3b7673d25
__xzip__: Fix regression about moving compressed files (bug #33993)
Orion Poplawski <orion@cora.nwra.com>
parents:
12499
diff
changeset
|
84 "uniformoutput", false), cwd); |
5cc3b7673d25
__xzip__: Fix regression about moving compressed files (bug #33993)
Orion Poplawski <orion@cora.nwra.com>
parents:
12499
diff
changeset
|
85 if (nargout > 0) |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
86 ## FIXME this does not work when you try to compress directories |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
87 entries = cellfun (@(x) sprintf ("%s.%s", x, extension), |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
88 files, "uniformoutput", false); |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
89 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
90 endif |
8349 | 91 |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
92 unwind_protect_cleanup |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
93 cd (cwd); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
94 if (nargin == 4) |
13952
acaf33ccc04f
Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents:
13141
diff
changeset
|
95 confirm_recursive_rmdir (false, "local"); |
acaf33ccc04f
Use "local" option to configuration variables to simplify code.
Rik <octave@nomad.inbox5.com>
parents:
13141
diff
changeset
|
96 rmdir (outdir, "s"); |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
97 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
98 end_unwind_protect |
8349 | 99 |
100 endfunction | |
101 | |
102 function [d, f] = myfileparts (files) | |
12931
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
12499
diff
changeset
|
103 [d, f, ext] = cellfun ("fileparts", files, "uniformoutput", false); |
8349 | 104 f = cellfun (@(x, y) sprintf ("%s%s", x, y), f, ext, |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
105 "uniformoutput", false); |
12931
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
12499
diff
changeset
|
106 idx = cellfun ("isdir", files); |
8349 | 107 d(idx) = ""; |
108 f(idx) = files(idx); | |
109 endfunction | |
8443
34c0acf11539
Fix error messages in __xzip__
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8362
diff
changeset
|
110 |
17345
a31b54b5f84a
Use only 1 space between '%!' and start of test/demo code.
Rik <rik@octave.org>
parents:
17184
diff
changeset
|
111 |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
112 ## FIXME -- reinstate these tests if we invent a way to test private |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
113 ## functions directly. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
114 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
115 ## %!error <extension has to be a string with finite length> |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
116 ## %! __xzip__ ("gzip", "", "gzip -r %s", "bla"); |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
117 ## %!error <no files to move> |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
118 ## %! __xzip__ ("gzip", ".gz", "gzip -r %s", tmpnam); |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
119 ## %!error <command failed with exit status> |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
120 ## %! # test __xzip__ with invalid compression command |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
121 ## %! unwind_protect |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
122 ## %! filename = tmpnam; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
123 ## %! dummy = 1; |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
124 ## %! save (filename, "dummy"); |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
125 ## %! dirname = tmpnam; |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
126 ## %! mkdir (dirname); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
127 ## %! entry = __xzip__ ("gzip", ".gz", "xxxzipxxx -r %s 2>/dev/null", |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
128 ## %! filename, dirname); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
129 ## %! unwind_protect_cleanup |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
130 ## %! delete (filename); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
131 ## %! rmdir (dirname); |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
132 ## %! end_unwind_protect |
17345
a31b54b5f84a
Use only 1 space between '%!' and start of test/demo code.
Rik <rik@octave.org>
parents:
17184
diff
changeset
|
133 |