46 lines
1022 B
Python
46 lines
1022 B
Python
|
|
||
|
def tsv( *fields ):
|
||
|
print( *fields, sep='\t' )
|
||
|
|
||
|
def csv( *fields ):
|
||
|
print( *[ '"' + f.replace('"','\\"') + '"' for f in fields ], sep=',' )
|
||
|
|
||
|
def render_tsv( model, list ):
|
||
|
|
||
|
if model in cols:
|
||
|
_cols = cols[model]
|
||
|
else:
|
||
|
_cols = cols['']
|
||
|
|
||
|
tsv( *_cols )
|
||
|
|
||
|
for obj in list:
|
||
|
tsv( *[ obj[col] for col in _cols] )
|
||
|
|
||
|
def render_csv( model, list ):
|
||
|
|
||
|
if model in cols:
|
||
|
_cols = cols[model]
|
||
|
else:
|
||
|
_cols = cols['']
|
||
|
|
||
|
csv( *_cols )
|
||
|
|
||
|
for obj in list:
|
||
|
csv( *[ obj[col] for col in _cols] )
|
||
|
|
||
|
def render_json( model, list ):
|
||
|
jlog( list )
|
||
|
|
||
|
#def render_json( model, obj ):
|
||
|
def render( model, list ): # +format=json,xml,csv +json +tsv
|
||
|
print( 'OPTS dans module : ', OPTS )
|
||
|
if opts.json or ( opts.format and 'json' in opts.format ):
|
||
|
render_json( model, list )
|
||
|
if opts.tsv or ( opts.format and 'tsv' in opts.format ):
|
||
|
render_tsv( model, list )
|
||
|
if opts.csv or ( opts.format and 'csv' in opts.format ):
|
||
|
render_csv( model, list )
|
||
|
# if opts.xml or ( opts.format and 'xml' in opts.format ):
|
||
|
# render_xml( model, list )
|