author | František Kučera <franta-hg@frantovo.cz> |
Fri, 13 May 2022 21:35:30 +0200 | |
branch | v_0 |
changeset 96 | c34106244a54 |
parent 70 | 018e2609f5bb |
permissions | -rwxr-xr-x |
33
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
#!/bin/bash |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
|
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
# Relational pipes |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
# Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
# |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
# This program is free software: you can redistribute it and/or modify |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
# it under the terms of the GNU General Public License as published by |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
# the Free Software Foundation, version 3 of the License. |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
# |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
# This program is distributed in the hope that it will be useful, |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
# GNU General Public License for more details. |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
# |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
# You should have received a copy of the GNU General Public License |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
|
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
# This streamlet provides a single attribute: number of lines of given file |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
# Standard wc -l is used to count the lines. |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
# Directories are reported a 0 lines and with a null flag (will be supported in further Relational pipes versions). |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
|
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
|
50
22ed5647b235
streamlets: include streamlet-common.sh from the directory where the actual streamlet resides (not where is the symlink, if any)
František Kučera <franta-hg@frantovo.cz>
parents:
49
diff
changeset
|
24 |
. "$(dirname "$(realpath "$0")")/streamlet-common.sh" |
33
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
|
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
processMessage_WAITING_FOR_OUTPUT_ATTRIBUTES_METADATA() { |
44
dc5c210295d0
do not force the name as the alias (allow different default in the finder/streamlet)
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
27 |
send OUTPUT_ATTRIBUTE_METADATA "${outputAttributeAliases[0]-lines_count}" "integer" |
33
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
send WAITING_FOR_INPUT_ATTRIBUTES |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
} |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
|
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
processMessage_WAITING_FOR_OUTPUT_ATTRIBUTES() { |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
if [[ -d "$currentFile" ]]; then |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
isNull="true"; |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
else |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
value=$(wc -l "$currentFile" | cut -d" " -f1); |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
isNull="false"; |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
fi |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
|
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
send OUTPUT_ATTRIBUTE "$value" "$isNull"; |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
send WAITING_FOR_INPUT_ATTRIBUTES; |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
} |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
|
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
initialize |
f9cada1d46a4
streamlet examples: common functions + inode, lines_count, mime_type
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
processMessages |