Ejemplo n.º 1
0
    def setComment(self, uId, pId, c):
        print "----> User ", uId," commenting ", c["comment"], " on pin ", pId
        comment_count = self.getCount("comment_count")
        comment_count +=1
        print "1"
        comment_string = str(c["comment"])
        
        user_id = int(uId)
        pin_id = int(pId)
        print "2"
        
        cl.citrusleaf_object_init_str(c0.object, comment_string)#str(u["name"]));
        cl.citrusleaf_object_init_int(c1.object, pin_id)
        cl.citrusleaf_object_init_int(c2.object, user_id)

        print "user id : ", user_id
        # Assign the structure back to the "bins" variable
        comment[0] = c0
        comment[1] = c1
        comment[2] = c2
                
        print "name ",c["comment"]
        print "reading from object " , comment[0].object.u.str
        return_value = cl.citrusleaf_put(clu, "comment", str(comment_count), key_obj, comment, 3, None);
        self.setCount("comment_count", comment_count)
        
        return self.getPin(pin_id)
Ejemplo n.º 2
0
    def createBoard(self,user_id,b, pin_list=""):
        print "---> creating board:",b
        
        board_count = self.getCount("board_count")
        board_count +=1
        print "1"
        board_name = str(b["boardname"])
        
        user_id = int(user_id)
        print "2"
        cl.citrusleaf_object_init_str(b0.object, board_name)#str(u["name"]));
        cl.citrusleaf_object_init_str(b1.object, pin_list)
        cl.citrusleaf_object_init_int(b2.object, user_id)

        print "user id : ", user_id
        # Assign the structure back to the "bins" variable
        board[0] = b0
        board[1] = b1
        board[2] = b2
                
        print "name ",b["boardname"]
        print "reading from object " , board[0].object.u.str
        return_value = cl.citrusleaf_put(clu, "board", str(board_count), key_obj, board, 3, None);
        self.setCount("board_count", board_count)
        return board_count
Ejemplo n.º 3
0
 def createBins(self):
     # Declaring an array in this interface
     bins = cl.cl_bin_arr(4)
     # Provide values for those bins and then initialize them.
     # Initializing bin of type string
     b0 = bins[0]
     b0.bin_name = "boardName"
     cl.citrusleaf_object_init_str(b0.object, "Board Name");
     # Initializing bin of type string
     b1 = bins[1]
     b1.bin_name = "boardDesc"
     cl.citrusleaf_object_init_str(b1.object, "Board Description");
     # Initializing bin of type string
     b2 = bins[2]
     b2.bin_name = "category"
     cl.citrusleaf_object_init_str(b2.object, "Board category");
     # Initializing bin of type string
     b3 = bins[3]
     b3.bin_name = "isPrivate"
     cl.citrusleaf_object_init_str(b3.object, "Board isPrivate");
     # Assign the structure back to the "bins" variable
     bins[0] = b0
     bins[1] = b1
     bins[2] = b2
     bins[3] = b3
     return bins
Ejemplo n.º 4
0
    def createPin(self, user_id, pname, img):
        print "---> creating pin:",pname
        pin_count = self.getCount("pin_count")
        pin_count +=1
        print "1"
        pin_name = pname
        pin_path = str(img.filename)
        print pin_name, pin_path
        user_id = int(user_id)
        print "2"

        dir = '/home/rajiv/workspace/python/cmpe273-project2/'+str(user_id)
        print dir

        if not os.path.exists(dir):
            os.mkdir(dir)
        fname = str(datetime.datetime.now())+'_'+str(img.filename)
        filepath = dir + '/'+fname
        imageUrl = 'http://localhost:8080'+str(user_id)+fname
        
        img.save(filepath)
        print(imageUrl)
        
        cl.citrusleaf_object_init_str(p0.object, pin_name)#str(u["name"]));
        cl.citrusleaf_object_init_str(p1.object, filepath)
        cl.citrusleaf_object_init_int(p2.object, user_id)
        #img = zlib.compress(img)
        print "here"
        #cl.citrusleaf_object_init_blob(p3.object, img, "102400")
        print "here too"
        

        print "user id : ", user_id
        # Assign the structure back to the "bins" variable
        pin[0] = p0
        pin[1] = p1
        pin[2] = p2
        #pin[3] = p3
                
        print "name ",pin_name
        print "reading from object " , pin[0].object.u.str
        return_value = cl.citrusleaf_put(clu, "pin", str(pin_count), key_obj, pin, 3, None);
        self.setCount("pin_count", pin_count)
        return pin_count
Ejemplo n.º 5
0
 def createBins_general(self,bin_name,values,types,num):
     print 'DEBUG: In createBins_general for length:',num
     bins = cl.cl_bin_arr(num)
     print 'DEBUG Bins array created'
     for i in xrange(num):
         print 'DEBUG: creating bin for index: ',i
         b = bins[i]
         print 'DEBUG: bin name: ',bin_name[i] , ' value: ',values[i] , ' type: ',types[i]
         b.bin_name = bin_name[i]
         print 'DEBUG: bin name: ',bin_name[i] , ' value: ',values[i] , ' type: ',types[i]
         if types[i] == "string":
             cl.citrusleaf_object_init_str(b.object, values[i]);
             print 'DEBUG: string bin created'
         elif types[i] == "int":
             cl.citrusleaf_object_init_int(b.object, values[i]);
             print 'DEBUG: int bin created'
         else:
             print 'Wrong Type, use type as "string" or "int"'
         bins[i] = b
     return bins
Ejemplo n.º 6
0
 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"
Ejemplo n.º 7
0
 def createUser(self, u, user_count):
     name = str(u["name"])
     uname = str(u["username"])
     passwd = str (u["password"])
     print
     cl.citrusleaf_object_init_str(u0.object, name)#str(u["name"]));
     cl.citrusleaf_object_init_str(u1.object, uname)#str(u["username"]));
     cl.citrusleaf_object_init_str(u2.object, passwd)#str(u["password"]));
     print uname, name, passwd
     # Assign the structure back to the "bins" variable
     user[0] = u0
     user[1] = u1
     user[2] = u2
     print "name ",u["name"]
     print "reading from object " , user[0].object.u.str
     return_value = cl.citrusleaf_put(clu, "user", str(user_count), key_obj, user, 3, None);
Ejemplo n.º 8
0
from citrusleaf import cl_write_parameters


# Initialize citrusleaf once
cl.citrusleaf_init()
# Create a cluster with a particular starting host
asc = cl.citrusleaf_cluster_create()
# Add host to the cluster
return_value = cl.citrusleaf_cluster_add_host(asc, "127.0.0.1", 3000, 1000)



# set up the key. Create a stack object, set its value to a string
key_obj = cl.cl_object()
#key_obj2 = cl.cl_object()
cl.citrusleaf_object_init_str(key_obj, "rajiv")
#cl.citrusleaf_object_init_str(key_obj2, "newKeyObject")


# Declaring an array in this interface
bins = cl.cl_bin_arr(3)
cans = cl.cl_bin_arr(4)
tins = cl.cl_bin_arr(4)

# Provide values for those bins and then initialize them.
# Initializing bin of type string
b0 = bins[0]
b0.bin_name = "email"
cl.citrusleaf_object_init_str(b0.object, "*****@*****.**");

# Initializing bin of type int
Ejemplo n.º 9
0
 def createKey_Obj(self,key):
     print 'DEBUG: In createKey_Obj for key:',key
     # set up the key. Create a stack object, set its value to a string
     key_obj = cl.cl_object()
     cl.citrusleaf_object_init_str(key_obj, key)
     return key_obj
Ejemplo n.º 10
0
import os

import citrusleaf as cl
import python_citrusleaf as pcl


# Initialize citrusleaf once
cl.citrusleaf_init()
# Create a cluster with a particular starting host
clu = cl.citrusleaf_cluster_create()
# Add host to the cluster
return_value = cl.citrusleaf_cluster_add_host(clu, "127.0.0.1", 3000, 1000)

# set up the key. Create a stack object, set its value to a string
key_obj = cl.cl_object()
cl.citrusleaf_object_init_str(key_obj, "rajiv")

# Declaring an array in this interface
pin = cl.cl_bin_arr(4)
board = cl.cl_bin_arr(4)

comment = cl.cl_bin_arr(4)
count = cl.cl_bin_arr(2)

user = cl.cl_bin_arr(4)
#User bins
u0 = user[0]
u0.bin_name = "name" 
u1 = user[1]
u1.bin_name = "user_name"
u2 = user[2]