annotate frontends/src/jp/cmd_input.py @ 2278:489efbda377c

jp (input): input command first draft: this is an experimental command to use external data as input arguments. A series of data is used (only CSV is implemented so far), and it is used to fill argument of a command according to a sequence. The sequence is given using input arguments, with types corresponding to the data found (short option, long option, stdin). e.g. if a CSV file has row with 3 columns, we can say that column 1 is subject (long option), column 2 is body (stdin), and column 3 is language (short option -l). A filter can be used after each option type, to transform read value. Finally a static part is used to have the main command and non dynamic arguments to use.
author Goffi <goffi@goffi.org>
date Wed, 28 Jun 2017 01:28:41 +0200
parents
children d8e48c850ad2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2278
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # jp: a SàT command line tool
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
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
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import base
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.i18n import _
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat_frontends.jp.constants import Const as C
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.tools.common.ansi import ANSI as A
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 import subprocess
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 import argparse
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 import os
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 import sys
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 __commands__ = ["Input"]
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 OPT_STDIN = 'stdin'
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 OPT_SHORT = 'short'
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 OPT_LONG = 'long'
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 OPT_POS = 'positional'
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 OPT_IGNORE = 'ignore'
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 OPT_TYPES = (OPT_STDIN, OPT_SHORT, OPT_LONG, OPT_POS, OPT_IGNORE)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 class InputCommon(base.CommandBase):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 def __init__(self, host, name, help):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 base.CommandBase.__init__(self, host, name, use_verbose=True, use_profile=False, help=help)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 self.idx = 0
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.reset()
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 def reset(self):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.args_idx = 0
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self._stdin = []
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self._opts = []
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self._pos = []
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 add_parser_options(self):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.parser.add_argument("--encoding", default='utf-8', help=_(u"encoding of the input data"))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.parser.add_argument("-i", "--stdin", action='append_const', const=(OPT_STDIN, None), dest='arguments', help=_(u"standard input"))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.parser.add_argument("-s", "--short", type=self.opt(OPT_SHORT), action='append', dest='arguments', help=_(u"short option"))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.parser.add_argument("-l", "--long", type=self.opt(OPT_LONG), action='append', dest='arguments', help=_(u"long option"))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.parser.add_argument("-p", "--positional", type=self.opt(OPT_POS), action='append', dest='arguments', help=_(u"positional argument"))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.parser.add_argument("-x", "--ignore", action='append_const', const=(OPT_IGNORE, None), dest='arguments', help=_(u"ignore value"))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.parser.add_argument("-D", "--debug", action='store_true', help=_(u"don't actually run commands but echo what would be launched"))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self.parser.add_argument("command", nargs=argparse.REMAINDER)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 def opt(self, type_):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 return lambda s: (type_, s)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 def addValue(self, value):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 """add a parsed value according to arguments sequence"""
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 arguments = self.args.arguments
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 try:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 arg_type, arg_name = arguments[self.args_idx]
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 except IndexError:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.disp(_(u"arguments in input data and in arguments sequence don't match"), error=True)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self.host.quit(C.EXIT_DATA_ERROR)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self.args_idx += 1
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 while self.args_idx < len(arguments):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 next_arg = arguments[self.args_idx]
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 if next_arg[0] not in OPT_TYPES:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 # we have a filter
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 filter_type, filter_arg = arguments[self.args_idx]
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 value = self.filter(filter_type, filter_arg, value)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 else:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 break
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 self.args_idx += 1
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 if not isinstance(value, list):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 value = [value]
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 for v in value:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 if arg_type == OPT_STDIN:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self._stdin.append(v.encode('utf-8'))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 elif arg_type == OPT_SHORT:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 self._opts.append('-{}'.format(arg_name))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self._opts.append(v.encode('utf-8'))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 elif arg_type == OPT_LONG:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 self._opts.append('--{}'.format(arg_name))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 self._opts.append(v.encode('utf-8'))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 elif arg_type == OPT_POS:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 self._pos.append(v.encode('utf-8'))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 elif arg_type == OPT_IGNORE:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 pass
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 else:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 self.parser.error(_(u"Invalid argument, an option type is expected, got {type_}:{name}").format(
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 type_=arg_type, name=arg_name))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
103
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 def runCommand(self):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 """run requested command with parsed arguments"""
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 if self.args_idx != len(self.args.arguments):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 self.disp(_(u"arguments in input data and in arguments sequence don't match"), error=True)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self.host.quit(C.EXIT_DATA_ERROR)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 stdin = ''.join(self._stdin)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 if self.args.debug:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 self.disp(_(u'command {idx}').format(idx=self.idx))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 if stdin:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 self.disp(u'--- STDIN ---')
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 self.disp(stdin.decode('utf-8'))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 self.disp(u'-------------')
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 self.disp(u'{indent}{prog} {static} {options} {positionals}'.format(
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 indent = 4*u' ',
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 prog=sys.argv[0],
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 static = ' '.join(self.args.command).encode('utf-8'),
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 options = u' '.join([o.encode('utf-8') for o in self._opts]),
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 positionals = u' '.join([p.encode('utf-8') for p in self._pos])
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 ))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 self.disp(u'')
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 else:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 self.disp(_(u'command {idx}').format(idx=self.idx), no_lf=True)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 with open(os.devnull, 'wb') as DEVNULL:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 p = subprocess.Popen([sys.argv[0]] + self.args.command + self._opts + self._pos,
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 stdin=subprocess.PIPE, stdout=DEVNULL, stderr=DEVNULL)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 p.communicate(stdin)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 ret = p.wait()
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 if ret == 0:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 self.disp(A.color(C.A_SUCCESS, _(u'OK')))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 else:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 self.disp(A.color(C.A_FAILURE, _(u'FAILED')))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 self.reset()
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 self.idx += 1
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
138
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 def filter(self, filter_type, filter_arg, value):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 raise NotImplementedError
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
141
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 class Csv(InputCommon):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 def __init__(self, host):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 super(Csv, self).__init__(host, 'csv', _(u'comma-separated values'))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
147
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 def add_parser_options(self):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 InputCommon.add_parser_options(self)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 self.parser.add_argument("-r", "--row", type=int, default=0, help=_(u"starting row (previous ones will be ignored)"))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 self.parser.add_argument("-S", "--split", action='append_const', const=('split', None), dest='arguments', help=_(u"split value in several options"))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
152
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 def filter(self, arg_type, filter_type, filter_arg, value):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 if filter_type == 'split':
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 return value.split()
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
156
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 super(Csv, self).filter(filter_type, filter_arg, value)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
158
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 def start(self):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 import csv
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 reader = csv.reader(sys.stdin)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 for idx, row in enumerate(reader):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 if idx < self.args.row:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 continue
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 for value in row:
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 self.addValue(value.decode(self.args.encoding))
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 self.runCommand()
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
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 class Input(base.CommandBase):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 subcommands = (Csv,)
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
172
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 def __init__(self, host):
489efbda377c jp (input): input command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 super(Input, self).__init__(host, 'input', use_profile=False, help=_(u'launch command with external input'))