<s> import sqlalchemy as SA <EOL> import pushmanager . core . db as db <EOL> import pushmanager . core . util <EOL> from pushmanager . core . git import GitQueue <EOL> from pushmanager . core . git import GitTaskAction <EOL> from pushmanager . core . requesthandler import RequestHandler <EOL> class PickMeRequestServlet ( RequestHandler ) : <EOL> def post ( self ) : <EOL> if not self . current_user : <EOL> return self . send_error ( <NUM_LIT> ) <EOL> self . pushid = pushmanager . core . util . get_int_arg ( self . request , '<STR_LIT>' ) <EOL> self . request_ids = self . request . arguments . get ( '<STR_LIT>' , [ ] ) <EOL> db . execute_cb ( db . push_pushes . select ( ) . where ( db . push_pushes . c . id == self . pushid ) , self . on_push_select ) <EOL> def on_push_select ( self , success , db_results ) : <EOL> if not success or not db_results : <EOL> return self . send_error ( <NUM_LIT> ) <EOL> pushrow = db_results . fetchone ( ) <EOL> if not pushrow : <EOL> return self . send_error ( <NUM_LIT> ) <EOL> if pushrow [ db . push_pushes . c . state ] != '<STR_LIT>' : <EOL> return self . send_error ( <NUM_LIT> ) <EOL> insert_queries = [ <EOL> db . push_pushcontents . insert ( { <EOL> '<STR_LIT>' : int ( i ) , <EOL> '<STR_LIT>' : self . pushid <EOL> } ) for i in self . request_ids <EOL> ] <EOL> update_query = db . push_requests . update ( ) . where ( SA . and_ ( <EOL> db . push_requests . c . id . in_ ( self . request_ids ) , <EOL> db . push_requests . c . state == '<STR_LIT>' , <EOL> ) ) . values ( { '<STR_LIT:state>' : '<STR_LIT>' } ) <EOL> request_query = db . push_requests . select ( ) . where ( <EOL> db . push_requests . c . id . in_ ( self . request_ids ) ) <EOL> condition_query = SA . select ( <EOL> [ db . push_pushes , db . push_pushcontents ] , <EOL> SA . and_ ( <EOL> db . push_pushcontents . c . request . in_ ( self . request_ids ) , <EOL> db . push_pushes . c . id == db . push_pushcontents . c . push , <EOL> db . push_pushes . c . state != '<STR_LIT>' <EOL> ) <EOL> ) <EOL> def condition_fn ( db_results ) : <EOL> return db_results . fetchall ( ) == [ ] <EOL> db . execute_transaction_cb ( <EOL> insert_queries + [ update_query , request_query ] , <EOL> self . on_db_complete , <EOL> condition = ( condition_query , condition_fn ) <EOL> ) <EOL> get = post <EOL> def on_db_complete ( self , success , db_results ) : <EOL> self . check_db_results ( success , db_results ) <EOL> for request_id in self . request_ids : <EOL> GitQueue . enqueue_request ( <EOL> GitTaskAction . TEST_PICKME_CONFLICT , <EOL> request_id , <EOL> pushmanager_url = self . get_base_url ( ) <EOL> ) <EOL> class UnpickMeRequestServlet ( RequestHandler ) : <EOL> def post ( self ) : <EOL> if not self . current_user : <EOL> return self . send_error ( <NUM_LIT> ) <EOL> self . pushid = pushmanager . core . util . get_int_arg ( self . request , '<STR_LIT>' ) <EOL> self . request_id = self . request . arguments . get ( '<STR_LIT>' , [ None ] ) [ <NUM_LIT:0> ] <EOL> delete_query = db . push_pushcontents . delete ( ) . where ( <EOL> SA . exists ( [ <NUM_LIT:1> ] , SA . and_ ( <EOL> db . push_pushcontents . c . request == self . request_id , <EOL> db . push_pushcontents . c . push == self . pushid , <EOL> db . push_requests . c . id == db . push_pushcontents . c . request , <EOL> db . push_requests . c . state == '<STR_LIT>' , <EOL> ) ) ) <EOL> update_query = db . push_requests . update ( ) . where ( SA . and_ ( <EOL> db . push_requests . c . id == self . request_id , <EOL> db . push_requests . c . state == '<STR_LIT>' , <EOL> ) ) . values ( { '<STR_LIT:state>' : '<STR_LIT>' } ) <EOL> db . execute_transaction_cb ( [ delete_query , update_query ] , self . on_db_complete ) <EOL> get = post <EOL> def on_db_complete ( self , success , db_results ) : <EOL> self . check_db_results ( success , db_results ) <EOL> GitQueue . enqueue_request ( <EOL> GitTaskAction . TEST_CONFLICTING_PICKMES , <EOL> self . pushid , <EOL> pushmanager_url = self . get_base_url ( ) <EOL> ) </s>
