<s> import argparse <EOL> import processor <EOL> import csv <EOL> import sys <EOL> import dsutil <EOL> import locale <EOL> import sqlite3 <EOL> class SQLProcessor ( processor . Processor ) : <EOL> def __init__ ( self , columns , kinds = [ ] ) : <EOL> super ( SQLProcessor , self ) . __init__ ( kinds ) <EOL> self . columns = columns <EOL> self . sql = '<STR_LIT>' ; <EOL> self . sql += '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT:id>' if str ( x ) == '<STR_LIT>' else str ( x ) for x in columns ] ) <EOL> self . sql += '<STR_LIT>' <EOL> self . sql += '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT:%s>' for x in columns ] ) <EOL> self . sql += '<STR_LIT>' <EOL> def resolve ( self ) : <EOL> print >> sys . stderr , '<STR_LIT>' , self . processed <EOL> for ent in self . block : <EOL> kind = dsutil . get_kind ( ent ) <EOL> line = [ ] <EOL> for column in self . columns : <EOL> name = column <EOL> value , t = dsutil . prop_value ( ent , column ) <EOL> if column == '<STR_LIT>' : <EOL> name = '<STR_LIT:id>' <EOL> last = value [ len ( value ) - <NUM_LIT:1> ] <EOL> value = last . get ( '<STR_LIT:name>' ) or last . get ( '<STR_LIT:id>' ) <EOL> if value : <EOL> value = value . encode ( '<STR_LIT>' ) <EOL> line . append ( value ) <EOL> values = [ ( "<STR_LIT>" % ( str ( x ) . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) ) ) for x in line ] <EOL> values = [ kind ] + values <EOL> print self . sql % tuple ( values ) <EOL> def argparse_prepare ( sub ) : <EOL> sub . add_argument ( '<STR_LIT>' , '<STR_LIT>' , nargs = '<STR_LIT:+>' , help = '<STR_LIT>' ) <EOL> sub . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , required = True , nargs = '<STR_LIT:+>' , help = '<STR_LIT>' ) <EOL> def argparse_exec ( args ) : <EOL> processor = SQLProcessor ( args . columns , args . kinds ) <EOL> processor . process ( ) </s>
