#NEWLINE# def ingest( self , meta , local_path ) : #NEWLINE# #INDENT# with open ( local_path , 'rb' ) as fh : #NEWLINE# #INDENT# db = DBF ( fh ) #NEWLINE# document = self . create_document ( meta ) #NEWLINE# tabular = self . create_tabular ( 0 ) #NEWLINE# columns = [ tabular . add_column ( h ) for h in db . fields . keys ( ) ] #NEWLINE# if ( not len ( columns ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# columns = { c . label : c . name for c in columns } #NEWLINE# def generate_rows( ) : #NEWLINE# #INDENT# if ( db . numrec == 0 ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# text = [ ] #NEWLINE# for i in xrange ( 0 , db . numrec ) : #NEWLINE# #INDENT# for v in db . select ( i ) . values ( ) : #NEWLINE# #INDENT# if isinstance ( v , str ) : #NEWLINE# #INDENT# text . append ( v ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# encoding = guess_encoding ( ' ' . join ( text ) ) #NEWLINE# for i in xrange ( 0 , db . numrec ) : #NEWLINE# #INDENT# row = db . select ( i ) #NEWLINE# record = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( k , value ) in row . items ( ) : #NEWLINE# #INDENT# name = columns . get ( k ) #NEWLINE# record [ name ] = string_value ( value , encoding = encoding ) #NEWLINE# #UNINDENT# if len ( record ) : #NEWLINE# #INDENT# for name in columns . values ( ) : #NEWLINE# #INDENT# record [ name ] = record . get ( name , None ) #NEWLINE# #UNINDENT# ( yield record ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# document . insert_records ( 0 , generate_rows ( ) ) #NEWLINE# meta . tables = [ tabular ] #NEWLINE# document . meta = meta #NEWLINE# self . emit ( document )