def got_acct(new_acct): if new_acct == False: e = Exception("Permission Denied") failure = Failure(e) result_d.errback(failure) return if self.best_acct is None: self.best_acct = new_acct db_user, db_pass = new_acct def connected_cb(conn): logging.debug("Token get_raw_store connected, returning it.") self.connections.append(conn) def get_sync(): return database.connect_box_sync(self.boxid, db_user, db_pass) conns = {"conn": conn, "sync_conn": get_sync} raw_store = ObjectStoreAsync(conns, self.username, self.appid, self.clientip) result_d.callback(raw_store) def err_cb(failure): logging.error( "Token get_raw_store error on connection: {0}".format( failure)) result_d.errback(failure) database.connect_box_raw(self.boxid, db_user, db_pass).addCallbacks( connected_cb, err_cb)
def get_raw(): return_d = Deferred() database.connect_box_raw( self.boxid, db_user, db_pass).addCallbacks( lambda conn: conn_passthru(conn, return_d), return_d.errback) return return_d
def got_acct(new_acct): if new_acct == False: e = Exception("Permission Denied") failure = Failure(e) result_d.errback(failure) return if self.best_acct is None: self.best_acct = new_acct db_user, db_pass = new_acct def connected_cb(conn): logging.debug("Token get_raw_store connected, returning it.") self.connections.append(conn) def get_sync(): return database.connect_box_sync(self.boxid, db_user, db_pass) conns = {"conn": conn, "sync_conn": get_sync} raw_store = ObjectStoreAsync(conns, self.username, self.appid, self.clientip) result_d.callback(raw_store) def err_cb(failure): logging.error("Token get_raw_store error on connection: {0}".format(failure)) result_d.errback(failure) database.connect_box_raw(self.boxid, db_user, db_pass).addCallbacks(connected_cb, err_cb)
def listen(self): """ Listen to updates to the database (locally, not with HTTP) and print out the diff in realtime. """ self.check_args(['box', 'username', 'password']) def observer(notify): print "Version updated to: {0}".format(notify.payload) def err_cb(failure): logging.error("Error in test listen: {0}".format(failure)) reactor.stop() def connected_cb(conn): print "Listening..." conns = {"conn": conn} store = ObjectStoreAsync(conns, self.args['username'], self.appid, "127.0.0.1") # TODO get the IP a better way? does it matter here? store.listen(observer) d = database.connect_box_raw(self.args['box'], self.args['username'], self.args['password']) d.addCallbacks(connected_cb, err_cb) reactor.run()
def get_raw(): return_d = Deferred() database.connect_box_raw(self.boxid, db_user, db_pass).addCallbacks(lambda conn: conn_passthru(conn, return_d), return_d.errback) return return_d