4040import pymongo
4141
4242import constants
43- from abstractdriver import AbstractDriver
43+ from . abstractdriver import AbstractDriver
4444
4545TABLE_COLUMNS = {
4646 constants .TABLENAME_ITEM : [
@@ -345,9 +345,9 @@ def loadConfig(self, config):
345345 logging .error ("ConnectionFailure %d (%s) when connected to %s: " ,
346346 exc .code , exc .details , display_uri )
347347 return
348- except pymongo .errors .PyMongoError , err :
348+ except pymongo .errors .PyMongoError as err :
349349 logging .error ("Some general error (%s) when connected to %s: " , str (err ), display_uri )
350- print "Got some other error: %s" % str (err )
350+ print ( "Got some other error: %s" % str (err ) )
351351 return
352352
353353 ## ----------------------------------------------
@@ -408,7 +408,7 @@ def loadTuples(self, tableName, tuples):
408408 tuple_dicts .append (dict ([(columns [i ], t [i ]) for i in num_columns ]))
409409 ## FOR
410410
411- self .database [tableName ].insert (tuple_dicts )
411+ self .database [tableName ].insert_many (tuple_dicts )
412412 ## IF
413413
414414 return
@@ -593,7 +593,7 @@ def _doNewOrderTxn(self, s, params):
593593 session = s )
594594 if not d :
595595 d1 = self .district .find_one ({"D_ID" : d_id , "D_W_ID" : w_id , "$comment" : "new order did not find district" })
596- print d1 , w_id , d_id , c_id , i_ids , i_w_ids , s_dist_col
596+ print ( d1 , w_id , d_id , c_id , i_ids , i_w_ids , s_dist_col )
597597 assert d , "Couldn't find district in new order w_id %d d_id %d" % (w_id , d_id )
598598 else :
599599 d = self .district .find_one ({"D_ID" : d_id , "D_W_ID" : w_id , "$comment" : comment },
@@ -621,7 +621,8 @@ def _doNewOrderTxn(self, s, params):
621621 #print constants.INVALID_ITEM_MESSAGE + ", Aborting transaction (ok for 1%)"
622622 return None
623623 ## IF
624- items = sorted (items , key = lambda x : i_ids .index (x ['I_ID' ]))
624+ xxi_ids = tuple (map (lambda o : o ['I_ID' ], items ))
625+ items = sorted (items , key = lambda x : xxi_ids .index (x ['I_ID' ]))
625626
626627 # getWarehouseTaxRate
627628 w = self .warehouse .find_one ({"W_ID" : w_id , "$comment" : comment }, {"_id" :0 , "W_TAX" : 1 }, session = s )
@@ -676,7 +677,8 @@ def _doNewOrderTxn(self, s, params):
676677 session = s ))
677678 ## IF
678679 assert len (all_stocks ) == ol_cnt , "all_stocks len %d != ol_cnt %d" % (len (all_stocks ), ol_cnt )
679- all_stocks = sorted (all_stocks , key = lambda x : item_w_list .index ((x ['S_I_ID' ], x ["S_W_ID" ])))
680+ xxxi_ids = tuple (map (lambda o : (o ['S_I_ID' ], o ['S_W_ID' ]), all_stocks ))
681+ all_stocks = sorted (all_stocks , key = lambda x : xxxi_ids .index ((x ['S_I_ID' ], x ["S_W_ID" ])))
680682
681683 ## ----------------
682684 ## Insert Order Line, Stock Item Information
@@ -820,7 +822,7 @@ def _doOrderStatusTxn(self, s, params):
820822 all_customers = list (self .customer .find (search_fields , return_fields , session = s ))
821823 namecnt = len (all_customers )
822824 assert namecnt > 0 , "No matching customer for last name %s!" % c_last
823- index = (namecnt - 1 )/ 2
825+ index = (namecnt - 1 )// 2
824826 c = all_customers [index ]
825827 c_id = c ["C_ID" ]
826828 ## IF
@@ -891,7 +893,7 @@ def _doPaymentTxn(self, s, params):
891893 session = s )
892894 if not d :
893895 d1 = self .district .find_one ({"D_ID" : d_id , "D_W_ID" : w_id , "$comment" : "payment did not find district" })
894- print d1 , w_id , d_id , h_amount , c_w_id , c_d_id , c_id , c_last , h_date
896+ print ( d1 , w_id , d_id , h_amount , c_w_id , c_d_id , c_id , c_last , h_date )
895897 assert d , "Couldn't find district in payment w_id %d d_id %d" % (w_id , d_id )
896898 else :
897899 d = self .district .find_one ({"D_W_ID" : w_id , "D_ID" : d_id , "$comment" : comment },
@@ -942,7 +944,7 @@ def _doPaymentTxn(self, s, params):
942944 all_customers = list (self .customer .find (search_fields , return_fields , session = s ))
943945 namecnt = len (all_customers )
944946 assert namecnt > 0 , "No matching customer w %d d %d clast %s" % (w_id , d_id , c_last )
945- index = (namecnt - 1 )/ 2
947+ index = (namecnt - 1 )// 2
946948 c = all_customers [index ]
947949 c_id = c ["C_ID" ]
948950 ## IF
@@ -1075,9 +1077,9 @@ def _doStockLevelTxn(self, s, params):
10751077 ol_ids .add (ol ["OL_I_ID" ])
10761078 ## FOR
10771079
1078- result = self .stock .find ({"S_W_ID" : w_id ,
1080+ result = self .stock .count_documents ({"S_W_ID" : w_id ,
10791081 "S_I_ID" : {"$in" : list (ol_ids )},
1080- "S_QUANTITY" : {"$lt" : threshold }, "$comment" : comment }). count ()
1082+ "S_QUANTITY" : {"$lt" : threshold }, "$comment" : comment })
10811083
10821084 return int (result )
10831085
@@ -1095,11 +1097,11 @@ def run_transaction(self, txn_callback, session, name, params):
10951097 exc .code , exc .details , name )
10961098 return (False , None )
10971099 logging .error ("Failed with unknown OperationFailure: %d" , exc .code )
1098- print "Failed with unknown OperationFailure: %d" % exc .code
1099- print exc .details
1100+ print ( "Failed with unknown OperationFailure: %d" % exc .code )
1101+ print ( exc .details )
11001102 raise
11011103 except pymongo .errors .ConnectionFailure :
1102- print "ConnectionFailure during %s: " % name
1104+ print ( "ConnectionFailure during %s: " % name )
11031105 return (False , None )
11041106 ## TRY
11051107
0 commit comments