@@ -50,9 +50,10 @@ def cli(version):
5050 '"2" (CERT_REQUIRED)' , type = int )
5151@click .option ('--check_hostname' , help = 'Verify cert hostname. Default: True' ,
5252 type = bool )
53- @click .option ('--multiline/--no-multiline' , help = 'Flag for multiline (With '
54- 'break-line in msg). '
55- 'Default False' , default = False )
53+ @click .option ('--multiline/--no-multiline' ,
54+ help = 'Flag for multiline (With '
55+ 'break-line in msg). '
56+ 'Default False' , default = False )
5657@click .option ('--type' , help = 'Connection type: SSL or TCP' , default = "SSL" )
5758@click .option ('--tag' , '-t' , help = 'Tag / Table to which the data will be sent '
5859 'in Devo.' , default = "test.drop.ltsender" )
@@ -168,18 +169,31 @@ def data(**kwargs):
168169 default = False )
169170@click .option ('--delimiter' , '-d' , help = 'CSV Delimiter char.' , default = "," )
170171@click .option ('--quotechar' , '-qc' , help = 'CSV Quote char.' , default = '"' )
172+ @click .option ('--escapequotes' , '-eq' , is_flag = True ,
173+ help = 'Escape Quotes. Default: False' ,
174+ default = False )
171175@click .option ('--debug/--no-debug' , help = 'For testing purposes' , default = False )
172176def lookup (** kwargs ):
173177 """Send csv lookups to devo"""
174178 config = configure_lookup (kwargs )
179+ warning_st = 0
180+
181+ # Exit errors by https://tldp.org/LDP/abs/html/exitcodes.html
182+ status_msg = {
183+ 64 : "Some field contains double quotes in this file."
184+ "If you do not use -eq or --escapequotes it might not work."
185+ }
186+
175187 con = Sender (config = config )
176188
177- lookup = Lookup (name = config ['name' ], historic_tag = None , con = con )
189+ lookup = Lookup (name = config ['name' ], historic_tag = None ,
190+ con = con , escape_quotes = config ['escapequotes' ])
178191
179- # with open (config['file']) as file :
180- # line = file.readline()
192+ if lookup . check_quotes (config ['file' ]):
193+ warning_st = 64
181194
182- lookup .send_csv (config ['file' ], delimiter = config ['delimiter' ],
195+ lookup .send_csv (config ['file' ],
196+ delimiter = config ['delimiter' ],
183197 quotechar = config ['quotechar' ],
184198 has_header = True ,
185199 # headers=line.rstrip().split(config['delimiter']),
@@ -191,6 +205,10 @@ def lookup(**kwargs):
191205 ),
192206 detect_types = config .get ("detect_types" , False ))
193207
208+ if warning_st != 0 :
209+ print_warning (status_msg [warning_st ])
210+ exit (warning_st )
211+
194212
195213def configure (args ):
196214 """ Configuration of Sender CLI """
@@ -237,3 +255,11 @@ def print_error(error, show_help=False):
237255 click .echo ("" )
238256 click .echo (click .get_current_context ().get_help ())
239257 click .echo (click .style (error , fg = 'red' ), err = True )
258+
259+
260+ def print_warning (warning , show_help = False ):
261+ """Class for print warning in shell"""
262+ if show_help :
263+ click .echo ("" )
264+ click .echo (click .get_current_context ().get_help ())
265+ click .echo (click .style (warning , fg = 'yellow' ), err = True )
0 commit comments