def ImportFile(store, filename, start):
  """Import hashes from 'filename' into 'store'."""
  with io.open(filename, "r") as fp:
    reader = csv.Reader(fp.read())
    i = 0
    current_row = None
    product_code_list = []
    op_system_code_list = []
    for row in reader:
      # Skip first row.
      i += 1
      if i and i % 5000 == 0:
        data_store.DB.Flush()
        print("Imported %d hashes" % i)
      if i > 1:
        if len(row) != 8:
          continue
        try:
          if i < start:
            continue
          if current_row:
            if current_row[0] == row[0]:
              # Same hash, add product/system
              product_code_list.append(int(row[5]))
              op_system_code_list.append(row[6])
              continue
            # Fall through and add current row.
          else:
            # First row.
            current_row = row
            product_code_list = [int(row[5])]
            op_system_code_list = [row[6]]
            continue
          _ImportRow(store, current_row, product_code_list, op_system_code_list)
          # Set new hash.
          current_row = row
          product_code_list = [int(row[5])]
          op_system_code_list = [row[6]]
        except Exception as e:  # pylint: disable=broad-except
          print("Failed at %d with %s" % (i, str(e)))
          return i - 1
    if current_row:
      _ImportRow(store, current_row, product_code_list, op_system_code_list)
    return i
def ImportFile ( store , filename , start ) : with io . open ( filename , "r" ) as fp : reader = csv . Reader ( fp . read ( ) ) i = 0 current_row = None product_code_list = [ ] op_system_code_list = [ ] for row in reader : i += 1 if i and i % 5000 == 0 : data_store . DB . Flush ( ) print ( "Imported %d hashes" % i ) if i > 1 : if len ( row ) != 8 : continue try : if i < start : continue if current_row : if current_row [ 0 ] == row [ 0 ] : product_code_list . append ( int ( row [ 5 ] ) ) op_system_code_list . append ( row [ 6 ] ) continue else : current_row = row product_code_list = [ int ( row [ 5 ] ) ] op_system_code_list = [ row [ 6 ] ] continue _ImportRow ( store , current_row , product_code_list , op_system_code_list ) current_row = row product_code_list = [ int ( row [ 5 ] ) ] op_system_code_list = [ row [ 6 ] ] except Exception as e : print ( "Failed at %d with %s" % ( i , str ( e ) ) ) return i - 1 if current_row : _ImportRow ( store , current_row , product_code_list , op_system_code_list ) return i
Import hashes from 'filename' into 'store'.