def readFromDB(self,set_name,key_obj): print 'DEBUG: In readFromDB' size = cl.new_intp() generation = cl.new_intp() # Declare a reference pointer for cl_bin * bins_get_all = cl.new_cl_bin_p() rv = cl.citrusleaf_get_all(self.asc, "test", set_name, key_obj, bins_get_all , size, 100, generation); # Number of bins returned number_bins = cl.intp_value(size) print 'DEBUG: number of bins read is ',number_bins # Use helper function get_bins to get the bins from pointer bins_get_all and the number of bins bins = pcl.get_bins (bins_get_all, number_bins) # Printing value received result = [] for i in xrange(number_bins): keyvalue = {} if(bins[i].object.type)==cl.CL_STR: print "Bin name: ",bins[i].bin_name,"Resulting string: ",bins[i].object.u.str keyvalue[bins[i].bin_name] = bins[i].object.u.str elif(bins[i].object.type)==cl.CL_INT: print "Bin name: ",bins[i].bin_name,"Resulting int: ",bins[i].object.u.i64 keyvalue[bins[i].bin_name] = bins[i].object.u.i64 elif bins[i].object.type == cl.CL_BLOB: binary_data = cl.cdata(bins[i].object.u.blob, bins[i].object.sz) print "Bin name: ",bins[i].bin_name,"Resulting decompressed blob: ",zlib.decompress(binary_data) keyvalue[bins[i].bin_name] = zlib.decompress(binary_data) else: print "Bin name: ",bins[i].bin_name,"Unknown bin type: ",bins[i].object.type keyvalue[bins[i].bin_name] = bins[i].object.type result.append(keyvalue) return result
def login (self, username, password): print "---> logging in:",username user_count = self.getCount("user_count") print user_count for j in xrange(user_count): rv = cl.citrusleaf_get_all(clu, "user", str(j+1), key_obj, bins_get_all , size, 100, generation); number_bins = cl.intp_value(size) # Use helper function get_bins to get the bins from pointer bins_get_all and the number of bins print "j : ", j bins = pcl.get_bins (bins_get_all, number_bins) for i in xrange(number_bins): if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "user_name"): uname = bins[i].object.u.str if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "password"): passwd = bins[i].object.u.str if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "name"): name = bins[i].object.u.str print "User values : ", uname, passwd, name print username, password if (uname == username) & (passwd == password) : user = {"_id": j+1, "username" : uname, "password" : password, "name" : name } print user return user print "final" return "error"
def getUser(self, id): print "---> getting user:"******"user_count") print user_count for j in xrange(user_count):''' rv = cl.citrusleaf_get_all(clu, "user", str(id), key_obj, bins_get_all , size, 100, generation); number_bins = cl.intp_value(size) # Use helper function get_bins to get the bins from pointer bins_get_all and the number of bins if number_bins > 0 : bins = pcl.get_bins (bins_get_all, number_bins) for i in xrange(number_bins): if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "user_name"): uname = bins[i].object.u.str '''if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "password"): passwd = bins[i].object.u.str''' if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "name"): name = bins[i].object.u.str print "User values : ", uname, name user = {"_id": id, "username" : uname, "name" : name } print user return user else: return "error"
def getCount(self, name): rv = cl.citrusleaf_get_all(clu, "count", name, key_obj, bins_get_all , size, 100, generation); # Number of bins returned number_bins = cl.intp_value(size) # Use helper function get_bins to get the bins from pointer bins_get_all and the number of bins bins = pcl.get_bins (bins_get_all, number_bins) for i in xrange(number_bins): if ((bins[i].object.type)==cl.CL_INT) & (bins[i].bin_name == "count") : return bins[i].object.u.i64 return 0
def register(self,u): print "---> registering user : "******"user_count") for j in xrange(user_count): rv = cl.citrusleaf_get_all(clu, "user", str(j+1), key_obj, bins_get_all , size, 100, generation); number_bins = cl.intp_value(size) # Use helper function get_bins to get the bins from pointer bins_get_all and the number of bins bins = pcl.get_bins (bins_get_all, number_bins) for i in xrange(number_bins): if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "user_name"): #print "comparing ", u["username"], " with database object ", bins[i].object.u.str if (bins[i].object.u.str) == u["username"] : return "duplicate" #Insert User into user namespace user_count+=1 self.createUser(u,user_count) self.setCount("user_count", user_count) return user_count
def getAllBoards(self): print "---> Listing boards:" board_count = self.getCount("board_count") print board_count boards = [] for j in xrange(board_count): rv = cl.citrusleaf_get_all(clu, "board", str(j+1), key_obj, bins_get_all , size, 100, generation); number_bins = cl.intp_value(size) # Use helper function get_bins to get the bins from pointer bins_get_all and the number of bins if number_bins>0: print "j : ", j bins = pcl.get_bins (bins_get_all, number_bins) for i in xrange(number_bins): if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "board_name"): bname = bins[i].object.u.str bId = j+1 b = {"board_id" : bId, "board_name" : bname} boards.append(b) return boards
def getComments(self, pId): comment_count = self.getCount("comment_count") pId = int(pId) comments = [] for j in xrange(comment_count): rv = cl.citrusleaf_get_all(clu, "comment", str(j+1), key_obj, bins_get_all , size, 100, generation); number_bins = cl.intp_value(size) # Use helper function get_bins to get the bins from pointer bins_get_all and the number of bins bins = pcl.get_bins (bins_get_all, number_bins) for i in xrange(number_bins): if ((bins[i].object.type)==cl.CL_INT): #print "comparing ", u["username"], " with database object ", bins[i].object.u.str if (bins[i].bin_name == "pin_id"): pin_id = bins[i].object.u.i64 if (bins[i].bin_name == "user_id"): user_id = bins[i].object.u.i64 if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "comment"): comment_string = bins[i].object.u.str if(pId == pin_id): c = {"user_id" : user_id, "comments":comment_string } comments.append(c) return comments
def getBoard(self, id): print "---> getting board:",id rv = cl.citrusleaf_get_all(clu, "board", str(id), key_obj, bins_get_all , size, 100, generation); number_bins = cl.intp_value(size) # Use helper function get_bins to get the bins from pointer bins_get_all and the number of bins if number_bins > 0 : bins = pcl.get_bins (bins_get_all, number_bins) for i in xrange(number_bins): if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "pin_list"): pin_list = bins[i].object.u.str print "Pin List : ", pin_list pins=[] if pin_list != "": pin_list = pin_list.split(",") for pin in pin_list: pins.append(self.getPin(pin)) print pins return pins else: return "error"
def updateBoard(self, user_id, board_id, pin): print "--> updating board:",board_id rv = cl.citrusleaf_get_all(clu, "board", str(board_id), key_obj, bins_get_all , size, 100, generation); number_bins = cl.intp_value(size) # Use helper function get_bins to get the bins from pointer bins_get_all and the number of bins if number_bins > 0 : bins = pcl.get_bins (bins_get_all, number_bins) for i in xrange(number_bins): if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "pin_list"): pin_list = bins[i].object.u.str if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "board_name"): board_name = bins[i].object.u.str print pin_list,board_name print "Pin List : ", pin_list if (pin_list == "") : pin_list = pin["pin_id"] else : pin_list = str(pin_list)+","+str(pin["pin_id"]) print "Updated pin list : ", pin_list b = {"boardname": board_name} print b #self.createBoard(user_id, b, pin_list) user_id = int(user_id) pin_list = str(pin_list) cl.citrusleaf_object_init_str(b1.object, pin_list) cl.citrusleaf_object_init_str(b0.object, board_name)#str(u["name"])); cl.citrusleaf_object_init_int(b2.object, user_id) # Assign the structure back to the "bins" variable board[0] = b0 board[1] = b1 board[2] = b2 return_value = cl.citrusleaf_put(clu, "board", str(board_id), key_obj, board, 3, None); print "here" return b return "error"
def getPin(self, id): print "---> getting pin:",id rv = cl.citrusleaf_get_all(clu, "pin", str(id), key_obj, bins_get_all , size, 100, generation); number_bins = cl.intp_value(size) # Use helper function get_bins to get the bins from pointer bins_get_all and the number of bins if number_bins > 0 : bins = pcl.get_bins (bins_get_all, number_bins) for i in xrange(number_bins): if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "pin_name"): pname = bins[i].object.u.str '''if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "password"): passwd = bins[i].object.u.str''' if ((bins[i].object.type)==cl.CL_STR) & (bins[i].bin_name == "pin_path"): ppath = bins[i].object.u.str print "User values : ", pname, ppath comments = self.getComments(id) user = {"_id": id, "pin_name" : pname, "pin_path" : ppath, "comments" : comments } print user return user else: return "error"
print "Success" return_value2 = cl.citrusleaf_put(asc, "user", "rajiv", key_obj, tins, 3, None ) if return_value2 !=cl.CITRUSLEAF_OK : print "3. Falied to set values %d", return_value2 #sys.exit(-1) else : print "Success"''' size = cl.new_intp() generation = cl.new_intp() # Declare a reference pointer for cl_bin * bins_get_all = cl.new_cl_bin_p() rv = cl.citrusleaf_get_all(asc, "user", "rajiv", key_obj, bins_get_all , size, 100, generation); # Number of bins returned number_bins = cl.intp_value(size) # Use helper function get_bins to get the bins from pointer bins_get_all and the number of bins bins = pcl.get_bins (bins_get_all, number_bins) if number_bins>0: print "something", number_bins else: print "nothing", number_bins # Printing value received for i in xrange(number_bins): if(bins[i].object.type)==cl.CL_STR: print "Bin name: ",bins[i].bin_name,"Resulting string: ",bins[i].object.u.str