File: multiop.man

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (402 lines) | stat: -rw-r--r-- 10,909 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin fileutil::multi::op n 0.5.3]
[keywords copy]
[keywords {file utilities}]
[keywords move]
[keywords multi-file]
[keywords remove]
[moddesc   {file utilities}]
[titledesc {Multi-file operation, scatter/gather}]
[category  {Programming tools}]
[require Tcl 8.4]
[require fileutil::multi::op [opt 0.5.3]]
[require wip [opt 1.0]]
[description]
[para]

This package provides objects which are able to perform actions on
multiple files selected by glob patterns.

[para]

At the core is a domain specific language allowing the easy
specification of multi-file copy and/or move and/or deletion
operations. Alternate names would be scatter/gather processor, or
maybe even assembler.

[section {CLASS API}]

The main command of the package is:

[list_begin definitions]

[call [cmd ::fileutil::multi::op] [opt [arg opName]] [opt [arg word]...]]

The command creates a new multi-file operation object with an
associated global Tcl command whose name is [arg opName].  This
command can be used to invoke the various possible file operations.
It has the following general form:

[list_begin definitions]
[call [cmd opName] [arg option] [opt [arg "arg arg ..."]]]

[arg Option] and the [arg arg]s determine the exact behavior of the
command.

[list_end]
[para]

If the string [const %AUTO%] is used as the [arg opName] then the
package will generate a unique name on its own.

[para]

If one or more [arg word]s are specified they are interpreted as an
initial set of file commands to execute. I.e. the method [method do]
of the newly constructed object is implicitly invoked using the words
as its arguments.

[list_end]

[para]

[section {OBJECT API}]

The following methods are possible for multi-file operation objects:

[list_begin definitions]

[call [cmd \$opName] [method do] [opt [arg word]...]]

This method interprets the specified words as file commands to
execute. See the section [sectref {FILE API}] for the set of
acceptable commands, their syntax, and semantics.

[para]

The result of the method is the result generated by the last file
command it executed.

[list_end]

[section {FILE API}]

Both object constructor and method [method do] take a list of words
and interpret them as file commands to execute. The names were chosen
to allow the construction of operations as sentences in near-natural
language. Most of the commands influence just the state of the object,
i.e. are simply providing the configuration used by the command
triggering the actual action.

[list_begin definitions]
[call [cmd into] [arg directory]]

Specifies the destination directory for operations.

[call [cmd in] [arg directory]]

Alias for [cmd into].

[call [cmd to] [arg directory]]

Alias for [cmd into].

[call [cmd from] [arg directory]]

Specifies the source directory for operations.

[call [cmd not] [arg pattern]]

Specifies a glob pattern for paths to be excluded from the operation.

[call [cmd for] [arg pattern]]

Alias for [cmd not].

[call [cmd exclude] [arg pattern]]

Alias for [cmd not].

[call [cmd but]]

Has no arguments of its own, but looks ahead in the list of words and
executes all [cmd not] commands immediately following it. This allows the
construction of "but not" and "but exclude" clauses for a more natural
sounding specification of excluded paths.

[call [cmd except]]

A semi-alias for [cmd but]. Has no arguments of its own, but looks
ahead in the list of words and executes all [cmd for] commands
immediately following it. This allows the construction of "except for"
clauses for a more natural sounding specification of excluded paths.

[call [cmd as] [arg name]]

Specifies a new name for the first file handled by the current
operation. I.e. for the renaming of a single file during the
operation.

[call [cmd recursive]]

Signals that file expansion should happen in the whole directory
hierarchy and not just the directory itself.

[call [cmd recursively]]

An alias for [cmd recursive].

[call [cmd copy]]

Signals that the operation is the copying of files from source to
destination directory per the specified inclusion and exclusion
patterns.

[call [cmd move]]

Signals that the operation is the moving of files from source to
destination directory per the specified inclusion and exclusion
patterns.

[call [cmd remove]]

Signals that the operation is the removal of files in the destination
directory per the specified inclusion and exclusion patterns.

[call [cmd expand]]

Signals that there is no operation but the calculation of the set of
files from the include and exclude patterns. This operation is not
available if [cmd the-set] is used.

[call [cmd invoke] [arg cmdprefix]]

Signals that the user-specified command prefix [arg cmdprefix] is the
operation to perform. The command prefix is executed at the global
level and given the source directory, destination directory, and set
of files (as dictionary mapping from source to destination files), in
this order.

[call [cmd reset]]

Forces the object into the ground state where all parts of the
configuration have default values.

[call [cmd "("]]

Saves a copy of the current object state on a stack.

[call [cmd ")"]]

Takes the state at the top of the state stack and restores it,
i.e. makes it the new current object state.

[call [cmd cd] [arg directory]]

Changes the destination directory to the sub-directory [arg directory]
of the current destination.

[call [cmd up]]

Changes the destination directory to the parent directory of the
current destination.

[call [cmd for-windows]]

Checks that Windows is the current platform. Aborts processing if not.

[call [cmd for-win]]

An alias for [cmd for-windows].

[call [cmd for-unix]]

Checks that Unix is the current platform. Aborts processing if not.

[call [cmd the] [arg pattern]]

This command specifies the files to operate on per a glob pattern, and
is also the active element, i.e. the command which actually performs
the specified operation. All the other commands only modified the
object state to set the operation up, but di nothing else.

[para]

To allow for a more natural sounding syntax this command also looks
ahead in the list of words looks and executes several commands
immediately following it before performing its own actions.

These commands are [cmd as], [cmd but], [cmd exclude], [cmd except],
[cmd from], and [cmd into] (and aliases). That way these commands act
like qualifiers, and still take effect as if they had been written
before this command.

[para]

After the operation has been performed the object state the exclude
patterns and the alias name, if specified, are reset to their default
values (i.e. empty), but nothing else.

[call [cmd the-set] [arg varname]]

Like [cmd the], however the set of files to use is not specified
implicitly per a glob pattern, but contained and loaded from the
specified variable. The operation [cmd expand] is not available
if this command is used.

[call [cmd ->] [arg varname]]

Saves the set of files from the last expansion into the specified
variable.

[call [cmd strict]]

Make file expansion and definition of destination directory ([cmd in]
and aliases) strict, i.e. report errors for missing directories, and
empty expansion.

[call [cmd !strict]]

Complement of [cmd strict]. A missing destination directory or empty
expansion are not reported as errors.

[call [cmd files]]

Limit the search to files. Default is to accept every type of path.

[call [cmd links]]

Limit the search to symbolic links. Default is to accept every type of path.

[call [cmd directories]]

Limit the search to directories. Default is to accept every type of path.

[call [cmd dirs]]

An alias for [cmd directories].

[call [cmd all]]

Accept all types of paths (default).

[call [cmd state?]]

Returns the current state of the object as dictionary. The dictionary keys and their meanings are:

[list_begin definitions]
[def [const as]]
Last setting made by [cmd as].
[def [const excluded]]
List of currently known exclusion patterns.
[def [const from]]
Current source directory, set by [cmd from].
[def [const into]]
Current destination directory, set by [cmd into] (and aliases).
[def [const operation]]
Current operation to perform, set by [cmd copy], [cmd move], [cmd remove], [cmd expand], or [cmd invoke].
[def [const recursive]]
Current recursion status. Set/unset by [cmd recursive] and [cmd !recursive].
[def [const strict]]
Current strictness. Set/unset by [cmd strict] and [cmd !strict].
[def [const type]]
Current path type limiter. Set by either [cmd files], [cmd directories], [cmd links], or [cmd all].
[list_end]

[call [cmd as?]]
Returns the current alias name.
[call [cmd excluded?]]
Returns the current set of exclusion patterns.
[call [cmd from?]]
Returns the current source directory.
[call [cmd into?]]
Returns the current destination directory.
[call [cmd operation?]]
Returns the current operation to perform.
[call [cmd recursive?]]
Returns the current recursion status.
[call [cmd strict?]]
Returns the current strictness.
[call [cmd type?]]
Returns the current path type limiter.
[list_end]

[section EXAMPLES]

The following examples assume that the variable [var F] contains a
reference to a multi-file operation object.

[example {
    $F do copy                       \\
	the  *.dll                    \\
	from c:/TDK/PrivateOpenSSL/bin \\
	to   [installdir_of tls]
}]

[example {
    $F do move      \\
	the  *       \\
	from /sources \\
	into /scratch  \\
	but not *.html

    # Alternatively use 'except for *.html'.
}]

[example {
    $F do           \\
	move         \\
	the  index    \\
	from /sources  \\
	into /scratch   \\
	as   pkgIndex.tcl
}]

[example {
    $F do         \\
	remove     \\
	the *.txt  \\
	in /scratch
}]

Note that the fact that most commands just modify the object state
allows us to use more off forms as specifications instead of just
nearly-natural language sentences.

For example the second example in this section can re-arranged into:

[example {
    $F do            \\
	from /sources \\
	into /scratch  \\
	but not *.html \\
	move           \\
	the  *
}]

and the result is not only still a valid specification, but even stays
relatively readable.

[para]

Further note that the information collected by the commands [cmd but],
[cmd except], and [cmd as] is automatically reset after the associated
[cmd the] was executed. However no other state is reset in that
manner, allowing the user to avoid repetitions of unchanging
information. For example the second and third examples of this section
can be merged and rewritten into the equivalent:

[example {
$F do                   \\
    move                 \\
    the  *                \\
    from /sources          \\
    into /scratch           \\
    but not *.html not index \\
    the  index               \\
    as   pkgIndex.tcl
}]

[vset CATEGORY fileutil]
[include ../common-text/feedback.inc]
[manpage_end]