Exemple #1
0
	def checkBinary(self, datatocheck):
		return UTFstring.decode(datatocheck)
Exemple #2
0
	def handleRequest(self, cmd, argstuple):

		session = Session()

		log.debug("funcs", "handleRequest(%s, %s)", cmd, argstuple)
		args = []
		for i in argstuple:
			args.append(i)

		try:
			if (session.hasKey('cmdint')):
				cmdint = session['cmdint']

				if (cmd == "importstart"):
					cmdint.db.importstart()
					return 1
				elif (cmd == "importend"):
					cmdint.db.importend()
					return 1
				elif (cmd == "importcancel"):
					cmdint.db.importcancel()
					return 1
				elif (cmd == "importnewsongs"):
					if len(args) > 0:
						#import pprint
						#pprint.pprint(args[0])
						tmp = args[0]
						for row in args[0]:
							for key in row.keys():
								row[key] = UTFstring.decode(row[key])
						#pprint.pprint(tmp)
						return cmdint.db.importnewsongs(tmp)
				elif (cmd == "importsong"):
					if len(args) > 0:
						if type(args[0]) is DictType:
							tmp = args[0]
							for i in tmp.keys():
								tmp[i] = UTFstring.encode(tmp[i])
							#print "tmp:%s" % str(tmp)
							return cmdint.db.importsongs(tmp)
						else:
							#It's not a valid param
							pass
					else:
						#It's a bad command
						pass
				elif (cmd == "importdelete"):
					if len(args) > 0:
						if isinstance(args[0], ListType):
							tmp = args[0]
							#for i in tmp:
							#	if type(tmp[i]) is xmlrpclib.Binary:
							#		tmp[i] = UTFstring.decode(tmp[i])
							return cmdint.db.importdelete(tmp)
						else:
							#It's not a valid param
							pass
					else:
						#It's a bad command
						pass
				elif (cmd == "importcache"):
					log.debug("import", "Import cache called")
					cache = cmdint.db.importcache()
					for i in cache:
						i['filename'] = UTFstring.encode(i['filename'])
					return cache
				elif cmd == "upload":
					log.debug("import", "Upload called")
					if len(args) > 0:
						thehash = cmdint.db.importupload(UTFstring.decode(args[0]))
						for i in thehash.keys():
							thehash[i] = UTFstring.encode(thehash[i])
						return thehash
					else:
						#TODO: Make an error fault
						pass
				elif cmd == "getmetadata":
					log.debug("import", "Got to getmetadata check")
					if len(args) > 0:
						thehash = cmdint.db.getmetadata(UTFstring.decode(args[0]))
						for i in thehash.keys():
							if isinstance(i, ListType):
								for j in i.keys():
									i[j] = UTFstring.encode(i[j])
							else:
								thehash[i] = UTFstring.encode(thehash[i])
						return thehash
					else:
						#TODO: Make an error fault
						pass
				elif cmd == "getCDDB":
					if len(args) > 0:
						tags = cmdint.db.getCDDB(args[0])
						return tags
					else:
						pass
				elif cmd == "pyrip":
					if len(args) > 0:
						return cmdint.db.pyrip (args[0], args[1], args[2])
					else:
						pass
				elif cmd == "pyrip_update":
					return cmdint.db.pyrip_update ()
		except:
			log.exception("Exception while calling XML function")
			raise