Beispiel #1
0
def checkConcurrency(content, updatelist, sock):
	temp = copy.deepcopy(updatelist)
	if len(updatelist["add"]) == 0 and len(updatelist["delete"]) ==0 and len(updatelist["modify"]) == 0 and len(updatelist["rename"]) == 0:
		#print "in outerelse"
		update(content)
		#sock.send("done")
	else:
		#print updatelist
		userinfo = userlog.getInfo()
		username = (userinfo.split('^'))[0]
		for key,values in updatelist.items():
			#print key
			#print values
			filename = []
			for value in values:
				#print key
				if key == "rename":
					print "in rename"
					filename = value[0].split("Sync-n-Share")
					newfile = value[1].split("Sync-n-Share")
					newfile = "Sync-n-Share"+newfile[-1]
				else:
					filename = value.split("Sync-n-Share")
				filename = "Sync-n-Share"+filename[-1]
			#	print content[1]
			#	print filename
				flag = content[1] == filename
				print flag
				if flag:
					if content[0] == "add":
			#			print "in add"
						string = ''
						fp = open(filename, 'r')
						for line in fp:
							string = string + line
						fp.close()
						match = string == content[2]
						if match:
							temp["add"].remove(value)
						else:
							temp["add"].remove(value)
							temp["add"].append(value+"Conflicted_Copy")
							renamefile(filename, filename+"Conflicted_Copy")
							addfile(content)
		#				sock.send("done")	
					elif content[0] == "delete":
						if key == "modify":
							temp["add"].append(value)
							temp["modify"].remove(value)
						elif key == "delete":
							temp["delete"].remove(value)
						else :
			#				print "delete - rename section"
							temp["add"].append(newfile)
							temp["rename"].remove(value)
		#				sock.send("done")	
					elif content[0] == "modify":
						if key == "modify":
							filecontent = connectify.getResponse('4'+username+'^'+content[1],sock)
						#	print filecontent
							string = ''
							fp = open(filename, 'r')
							for line in fp:
								string = string + line
							fp.close()
							match = string == filecontent
							if not match:
								temp["add"].append(value+"Conflicted_Copy")
								renamefile(filename, filename+"Conflicted_Copy")
								content[2] = filecontent
								del content[3:]
							#	print content
								addfile(content)
							temp["modify"].remove(value)
						elif key == "delete":
							filecontent = connectify.getResponse('4'+username+'^'+content[1],sock)
							content[2] = filecontent
							del content[3:]
							addfile(content)
							temp["delete"].remove(value)
						else :
							string = ''
							fp = open(newfile, 'r')
							for line in fp:
								string = string + line
							fp.close()
							content2 = ["add",filename,string]
							addfile(content2)
							temp["add"].append(value[1])
							temp["rename"].remove(value)
							modfile(content)
		#					sock.send("done")	
					elif content[0]== "rename":
						if key == "modify":
							filecontent = connectify.getResponse('4'+username+'^'+content[1],sock)
							content[1] = content[2]
							content[2] = filecontent
							addfile(content)
							temp["add"].append(value)
							temp["modify"].remove(value)	
						elif key == "delete":
							filecontent = connectify.getResponse('4'+username+'^'+content[1],sock)
							content[1] = content[2]
							content[2] = filecontent
							addfile(content)
							temp["delete"].remove(value)
						else :
							if not content[2] == newfile:
								string = ''
								fp = open(newfile, 'r')
								for line in fp:
									string = string + line
								fp.close()
								content2 = "add^"+content[2]+'^'+string
								temp["add"].append(value[1])
								print "rename content2 is"+content2
								content2 = content2.split('^')
								addfile(content2)
							temp["rename"].remove(value)
		#					sock.send("done")
				else:
					#print "in else"
					update(content)
		#			sock.send("done")	
	updatelist = temp		
	print "latest updatelist :" 
	print  updatelist
	return updatelist
Beispiel #2
0
def getUser(sock):
	try:
		userinfo = userlog.getInfo()
	except:	
		userinfo = configure.init(sock)
	return userinfo