annotate libervia/cli/cmd_input.py @ 4309:b56b1eae7994

component email gateway: add multicasting: XEP-0033 multicasting is now supported both for incoming and outgoing messages. XEP-0033 metadata are converted to suitable Email headers and vice versa. Email address and JID are both supported, and delivery is done by the gateway when suitable on incoming messages. rel 450
author Goffi <goffi@goffi.org>
date Thu, 26 Sep 2024 16:12:01 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
4 # Libervia CLI
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3407
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
21 import subprocess
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
22 import argparse
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
23 import sys
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
24 import shlex
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
25 import asyncio
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
26 from . import base
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
27 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
28 from libervia.backend.core import exceptions
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
29 from libervia.cli.constants import Const as C
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
30 from libervia.backend.tools.common.ansi import ANSI as A
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 __commands__ = ["Input"]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
33 OPT_STDIN = "stdin"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
34 OPT_SHORT = "short"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
35 OPT_LONG = "long"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36 OPT_POS = "positional"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
37 OPT_IGNORE = "ignore"
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 OPT_TYPES = (OPT_STDIN, OPT_SHORT, OPT_LONG, OPT_POS, OPT_IGNORE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 OPT_EMPTY_SKIP = "skip"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
40 OPT_EMPTY_IGNORE = "ignore"
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
41 OPT_EMPTY_CHOICES = (OPT_EMPTY_SKIP, OPT_EMPTY_IGNORE)
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 class InputCommon(base.CommandBase):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 def __init__(self, host, name, help):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
46 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
47 self, host, name, use_verbose=True, use_profile=False, help=help
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 )
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.idx = 0
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.reset()
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 def reset(self):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.args_idx = 0
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self._stdin = []
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self._opts = []
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self._pos = []
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
57 self._values_ori = []
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
61 "--encoding", default="utf-8", help=_("encoding of the input data")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 "-i",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 "--stdin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 action="append_const",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 const=(OPT_STDIN, None),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 dest="arguments",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
69 help=_("standard input"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 "-s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 "--short",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 type=self.opt(OPT_SHORT),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
75 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 dest="arguments",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
77 help=_("short option"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 "-l",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 "--long",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 type=self.opt(OPT_LONG),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 dest="arguments",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
85 help=_("long option"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 "-p",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 "--positional",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 type=self.opt(OPT_POS),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
92 dest="arguments",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
93 help=_("positional argument"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 "-x",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 "--ignore",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 action="append_const",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 const=(OPT_IGNORE, None),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 dest="arguments",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
101 help=_("ignore value"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 "-D",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
105 "--debug",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
106 action="store_true",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
107 help=_("don't actually run commands but echo what would be launched"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
108 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 self.parser.add_argument(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
110 "--log", type=argparse.FileType("w"), help=_("log stdout to FILE")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
111 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 self.parser.add_argument(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
113 "--log-err", type=argparse.FileType("w"), help=_("log stderr to FILE")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 )
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 self.parser.add_argument("command", nargs=argparse.REMAINDER)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 def opt(self, type_):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 return lambda s: (type_, s)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
120 def add_value(self, value):
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 """add a parsed value according to arguments sequence"""
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
122 self._values_ori.append(value)
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 arguments = self.args.arguments
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 try:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 arg_type, arg_name = arguments[self.args_idx]
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 except IndexError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
128 _("arguments in input data and in arguments sequence don't match"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 )
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 self.host.quit(C.EXIT_DATA_ERROR)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 self.args_idx += 1
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 while self.args_idx < len(arguments):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 next_arg = arguments[self.args_idx]
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 if next_arg[0] not in OPT_TYPES:
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
136 # value will not be used if False or None, so we skip filter
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
137 if value not in (False, None):
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
138 # we have a filter
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
139 filter_type, filter_arg = arguments[self.args_idx]
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
140 value = self.filter(filter_type, filter_arg, value)
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 else:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 break
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 self.args_idx += 1
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
145 if value is None:
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
146 # we ignore this argument
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
147 return
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
148
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
149 if value is False:
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
150 # we skip the whole row
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
151 if self.args.debug:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
152 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
153 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
154 C.A_SUBHEADER,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
155 _("values: "),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 A.RESET,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
157 ", ".join(self._values_ori),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
158 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
161 self.disp(A.color(A.BOLD, _("**SKIPPING**\n")))
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
162 self.reset()
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
163 self.idx += 1
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
164 raise exceptions.CancelError
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
165
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 if not isinstance(value, list):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 value = [value]
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
168
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 for v in value:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 if arg_type == OPT_STDIN:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
171 self._stdin.append(v)
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 elif arg_type == OPT_SHORT:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 self._opts.append("-{}".format(arg_name))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
174 self._opts.append(v)
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 elif arg_type == OPT_LONG:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 self._opts.append("--{}".format(arg_name))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
177 self._opts.append(v)
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 elif arg_type == OPT_POS:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
179 self._pos.append(v)
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 elif arg_type == OPT_IGNORE:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 pass
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
183 self.parser.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 _(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
185 "Invalid argument, an option type is expected, got {type_}:{name}"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
186 ).format(type_=arg_type, name=arg_name)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
187 )
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
188
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
189 async def runCommand(self):
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 """run requested command with parsed arguments"""
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 if self.args_idx != len(self.args.arguments):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
193 _("arguments in input data and in arguments sequence don't match"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
194 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
195 )
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 self.host.quit(C.EXIT_DATA_ERROR)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
197 end = "\n" if self.args.debug else " "
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
198 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
199 A.color(C.A_HEADER, _("command {idx}").format(idx=self.idx)),
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
200 end=end,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
201 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
202 stdin = "".join(self._stdin)
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 if self.args.debug:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
204 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
205 A.color(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
206 C.A_SUBHEADER,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
207 _("values: "),
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
208 A.RESET,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
209 ", ".join([shlex.quote(a) for a in self._values_ori]),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
210 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
212 )
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
213
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 if stdin:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
215 self.disp(A.color(C.A_SUBHEADER, "--- STDIN ---"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
216 self.disp(stdin)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
217 self.disp(A.color(C.A_SUBHEADER, "-------------"))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
218
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
219 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
220 "{indent}{prog} {static} {options} {positionals}".format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
221 indent=4 * " ",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
222 prog=sys.argv[0],
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
223 static=" ".join(self.args.command),
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
224 options=" ".join(shlex.quote(o) for o in self._opts),
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
225 positionals=" ".join(shlex.quote(p) for p in self._pos),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
226 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
227 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
228 self.disp("\n")
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
230 self.disp(" (" + ", ".join(self._values_ori) + ")", 2, end=" ")
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
231 args = [sys.argv[0]] + self.args.command + self._opts + self._pos
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
232 p = await asyncio.create_subprocess_exec(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
233 *args,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
234 stdin=subprocess.PIPE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
235 stdout=subprocess.PIPE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
236 stderr=subprocess.PIPE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
237 )
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
238 stdout, stderr = await p.communicate(stdin.encode("utf-8"))
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
239 log = self.args.log
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
240 log_err = self.args.log_err
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
241 log_tpl = "{command}\n{buff}\n\n"
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
242 if log:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
243 log.write(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
244 log_tpl.format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
245 command=" ".join(shlex.quote(a) for a in args),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
246 buff=stdout.decode("utf-8", "replace"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
247 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
248 )
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
249 if log_err:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
250 log_err.write(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
251 log_tpl.format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
252 command=" ".join(shlex.quote(a) for a in args),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
253 buff=stderr.decode("utf-8", "replace"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
254 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
255 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
256 ret = p.returncode
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 if ret == 0:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
258 self.disp(A.color(C.A_SUCCESS, _("OK")))
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
260 self.disp(A.color(C.A_FAILURE, _("FAILED")))
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
261
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 self.reset()
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 self.idx += 1
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
264
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 def filter(self, filter_type, filter_arg, value):
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
266 """change input value
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
267
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
268 @param filter_type(unicode): name of the filter
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
269 @param filter_arg(unicode, None): argument of the filter
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
270 @param value(unicode): value to filter
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
271 @return (unicode, False, None): modified value
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
272 False to skip the whole row
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
273 None to ignore this argument (but continue row with other ones)
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
274 """
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 raise NotImplementedError
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
276
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
277
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 class Csv(InputCommon):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
280 super(Csv, self).__init__(host, "csv", _("comma-separated values"))
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
281
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
282 def add_parser_options(self):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 InputCommon.add_parser_options(self)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
284 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
285 "-r",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
286 "--row",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
287 type=int,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
288 default=0,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
289 help=_("starting row (previous ones will be ignored)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
290 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
291 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
292 "-S",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
293 "--split",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
294 action="append_const",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
295 const=("split", None),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
296 dest="arguments",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
297 help=_("split value in several options"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
298 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
299 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
300 "-E",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
301 "--empty",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
302 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
303 type=self.opt("empty"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
304 dest="arguments",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
305 help=_("action to do on empty value ({choices})").format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
306 choices=", ".join(OPT_EMPTY_CHOICES)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
307 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
308 )
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
309
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
310 def filter(self, filter_type, filter_arg, value):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
311 if filter_type == "split":
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 return value.split()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
313 elif filter_type == "empty":
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
314 if filter_arg == OPT_EMPTY_IGNORE:
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
315 return value if value else None
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
316 elif filter_arg == OPT_EMPTY_SKIP:
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
317 return value if value else False
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
318 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
319 self.parser.error(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
320 _("--empty value must be one of {choices}").format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
321 choices=", ".join(OPT_EMPTY_CHOICES)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
322 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
323 )
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
324
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 super(Csv, self).filter(filter_type, filter_arg, value)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
326
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
327 async def start(self):
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
328 import csv
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
329
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
330 if self.args.encoding:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
331 sys.stdin.reconfigure(encoding=self.args.encoding, errors="replace")
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
332 reader = csv.reader(sys.stdin)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
333 for idx, row in enumerate(reader):
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
334 try:
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
335 if idx < self.args.row:
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
336 continue
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
337 for value in row:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
338 self.add_value(value)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
339 await self.runCommand()
2282
d8e48c850ad2 jp (input): log improvments + empty filter:
Goffi <goffi@goffi.org>
parents: 2278
diff changeset
340 except exceptions.CancelError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
341 #  this row has been cancelled, we skip it
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 continue
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
343
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
344 self.host.quit()
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
345
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
346
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 class Input(base.CommandBase):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 subcommands = (Csv,)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
349
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
351 super(Input, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
352 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
353 "input",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
354 use_profile=False,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
355 help=_("launch command with external input"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
356 )