def handleRequest(self, cmd, argstuple): session = Session() args = [] for i in argstuple: args.append(i) if (session.hasKey('cmdint')): cmdint = session['cmdint'] if (cmd == "pause"): #cmdint.push_cmd("pause") cmdint.control.pause() return True elif (cmd == "stop"): #cmdint.push_cmd("stop") cmdint.control.stop() return True elif (cmd == "play"): #cmdint.push_cmd("play") cmdint.control.play() return True elif (cmd == "next"): #cmdint.push_cmd("play") cmdint.control.next() return True elif (cmd == "playindex"): if len(args) == 1: cmdint.control.playIndex(args[0]) return True else: return xmlrpclib.Fault(2, "Error in given parameters")
def handleRequest(self, cmd, argstuple): session = Session() args = [] for i in argstuple: args.append(i) if (session.hasKey('cmdint')): cmdint = session['cmdint'] if (cmd == "login"): #TODO: Handle the callback if (len(args)>1): tmp = cmdint.auth.login(args[0], args[1]) if (tmp != None): return tmp else: return "Permission Denied" else: return xmlrpclib.Fault(1, "Not enough parameters given") elif (cmd == "logout"): if (len(args)==1): return cmdint.auth.logout(args[0]) else: return xmlrpclib.Fault(1, "Invalid command in the auth realm")
def handleRequest(self, cmd, argstuple): session = Session() args = [] for i in argstuple: args.append(i) #print "args " + str(args) #print "len args " + str(len(args)) if (session.hasKey('cmdint')): cmdint = session['cmdint'] if (cmd == "shutdown"): return cmdint.set.shutdown() elif (cmd == "saveconfig"): return cmdint.set.saveconfig() elif (cmd == "endofqueue"): if len(args) == 1: return cmdint.set.endofqueue(args[0]) elif len(args) == 2: return cmdint.set.endofqueue(args[0], args[1]) else: return xmlrpclib.Fault(1, "Proper number of parameters not given") elif (cmd == "volume"): if len(args) == 1: return cmdint.set.volume(args[0]) else: return xmlrpclib.Fault(1, "Proper number of parameters not given") else: return xmlrpclib.Fault(1, "Invalid command in the set realm")
def handleRequest(self, cmd, argstuple): session = Session() args = [] for i in argstuple: args.append(i) #print "args " + str(args) #print "len args " + str(len(args)) if (session.hasKey('cmdint')): cmdint = session['cmdint'] if (cmd == "createplaylist"): if len(args) == 1: return cmdint.edit.createplaylist(args[0]) else: return xmlrpclib.Fault(1, "Proper parameters not given") elif (cmd == "removeplaylist"): if len(args) == 1: return cmdint.edit.removeplaylist(args[0]) else: return xmlrpclib.Fault(1, "Proper parameters not given") elif (cmd == "add"): if len(args) == 4: return cmdint.edit.add(args[0], args[1], args[2], args[3]) else: return xmlrpclib.Fault(1, "Proper parameters not given") elif (cmd == "remove"): if len(args) == 2: return cmdint.edit.remove(args[0], args[1]) else: return xmlrpclib.Fault(1, "Proper parameters not given") elif (cmd == "move"): if len(args) == 3: return cmdint.edit.move(args[0], args[1], args[2]) else: return xmlrpclib.Fault(1, "Proper parameters not given") elif (cmd == "swap"): if len(args) == 3: return cmdint.edit.swap(args[0], args[1], args[2]) else: return xmlrpclib.Fault(1, "Proper parameters not given") elif (cmd == "createplaylistfromqueue"): if len(args) == 1: if isinstance(args[0], types.StringType): return cmdint.edit.createplaylistfromqueue(name=args[0]) elif isinstance(args[0], types.IntType): return cmdint.edit.createplaylistfromqueue(playlistid=args[0]) else: return xmlrpclib.Fault(1, "Proper parameters not given") else: return xmlrpclib.Fault(1, "Proper parameters not given") else: return xmlrpclib.Fault(1, "This is not a valid command")
def handleRequest(self, cmd, argstuple): session = Session() args = [] for i in argstuple: args.append(i) if (session.hasKey('cmdint')): cmdint = session['cmdint'] if cmd == "version": return cmdint.util.version()
def saveconfig(self): """ Save the bossogg.conf file back to the filesystem overwriting the old one. Parameters: * none Returns: * int (always 1) """ session = Session() if session.hasKey('cfg'): session['cfg'].save() return 1
def endofqueue(self): """ Gets the currently selected endofqueue action. Parameters: * none Returns: * String """ session = Session() if session.hasKey('cfg'): return session['cfg'].get("endofqueue") else: return ""
def endofqueue(self,endofqueueaction="allstraight", endofqueueparam=""): """ Sets the endofqueue action. Parameters: * endofqueueaction - string * endofqueueparam - string Returns: * int (always 1) """ session = Session() if session.hasKey('cfg'): session['cfg'].set("endofqueue",endofqueueaction) session['cfg'].set("endofqueueparam",endofqueueparam) return 1
def __init__(self, dbh, parent): self.songqueue = UserEditableQueue(self, dbh, parent) self.endofqueue = AllStraightQueue(self, dbh, parent) self.dbh = dbh self.parent = parent self.session = Session() self.currenteoqtype = None self.usingendofqueue = 0
def handleRequest(self, cmd, argstuple): session = Session() args = [] for i in argstuple: args.append(i) #print "args " + str(args) #print "len args " + str(len(args)) if (session.hasKey('cmdint')): cmdint = session['cmdint'] if (cmd == "status"): return cmdint.info.status() elif (cmd == "endofqueue"): return cmdint.info.endofqueue()
def handleRequest(self, cmd, argstuple): session = Session() args = [] for i in argstuple: args.append(i) #print "args " + str(args) #print "len args " + str(len(args)) if (session.hasKey('cmdint')): cmdint = session['cmdint'] if (cmd == "artists"): tmp = None if (len(args)>0): tmp = cmdint.list.artists(args[0]) else: tmp = cmdint.list.artists() for i in tmp: if "artistname" in i: i['artistname'] = UTFstring.encode(i['artistname']) return tmp elif (cmd == "albums"): tmp = None #if (len(args)>0): try: tmp = cmdint.list.albums(args[0],args[1]) except Exception: try: tmp = cmdint.list.albums(args[0]) except Exception: #return xmlrpclib.Fault(2, "Error in given parameters") tmp = cmdint.list.albums() for i in tmp: if "albumname" in i: i['albumname'] = UTFstring.encode(i['albumname']) if "artistname" in i: i['artistname'] = UTFstring.encode(i['artistname']) return tmp #else: # return xmlrpclib.Fault(1, "No artistid given") elif (cmd == "albumsbygenre"): tmp = None #if (len(args)>0): print "%s" % args try: tmp = cmdint.list.albums(genreid=args[0],anchor=args[1]) except Exception: try: tmp = cmdint.list.albums(genreid=args[0]) except Exception: return xmlrpclib.Fault(2, "Error in given parameters") for i in tmp: if "albumname" in i: i['albumname'] = UTFstring.encode(i['albumname']) return tmp elif (cmd == "songs"): tmp = None if (len(args) > 1): type = args[0] someid = args[1] if (type == "artistid" or type == "albumid" or type == "playlistid"): if (type == "artistid"): try: tmp = cmdint.list.songs(artistid=someid,anchor=args[2]) except Exception: tmp = cmdint.list.songs(artistid=someid) elif (type == "albumid"): try: tmp = cmdint.list.songs(albumid=someid,anchor=args[2]) except Exception: tmp = cmdint.list.songs(albumid=someid) elif (type == "playlistid"): try: tmp = cmdint.list.songs(playlistid=someid,anchor=args[2]) except Exception: tmp = cmdint.list.songs(playlistid=someid) for i in tmp: for j in i.keys(): i[j] = UTFstring.encode(i[j]) return tmp else: return xmlrpclib.Fault(2, "%s is not a valid type" % type) else: return xmlrpclib.Fault(1, "No artistid or albumid given") elif (cmd == "users"): return cmdint.list.users() elif (cmd == "stats"): return cmdint.list.stats() elif (cmd == "playlists"): return cmdint.list.playlists() elif (cmd == "genres"): return cmdint.list.genres() elif (cmd == "songinfo"): tmp = None if len(args) > 0: songid = args[0] tmp = cmdint.list.songinfo(songid) else: tmp = cmdint.list.songinfo() for i in tmp.keys(): tmp[i] = UTFstring.encode(tmp[i]) return tmp elif (cmd == "queue"): tmp = None if len(args) >= 0 and len(args) < 3: if len(args) == 2: if isinstance(args[0], types.IntType) and isinstance(args[1], types.IntType): if args[0] == 1: args[0] = True tmp = cmdint.list.queue(args[0], args[1]) else: return xmlrpclib.Fault(1, "Proper types not given") elif len(args) == 1: if isinstance(args[0], types.IntType): if args[0] == 1: args[0] = True tmp = cmdint.list.queue(args[0]) else: return xmlrpclib.Fault(1, "Proper types not given") else: tmp = cmdint.list.queue() if isinstance(tmp, types.ListType): for i in tmp: for j in i.keys(): i[j] = UTFstring.encode(i[j]) return tmp else: return xmlrpclib.Fault(1, "Proper number of parameters not given") elif (cmd == "top"): tmp = None if len(args) > 0 and len(args) < 3: if len(args) == 2: if isinstance(args[0], types.StringType) and isinstance(args[1], types.IntType): tmp = cmdint.list.top(args[0], args[1]) else: return xmlrpclib.Fault(1, "Proper types not given") else: if isinstance(args[0], types.StringType): tmp = cmdint.list.top(args[0]) else: return xmlrpclib.Fault(1, "Proper types not given") for i in tmp: for j in i.keys(): i[j] = UTFstring.encode(i[j]) return tmp else: return xmlrpclib.Fault(1, "Proper number of parameters not given")
def run(self): #log = bosslog.getLogger() session = Session() while self.shutdown == False: readable, writable, errorable = select.select(self.readable_in,self.writable_in,self.errorable_in,5.0) for i in readable: if i == self.serversocket: (conn, addr) = i.accept() log.debug("bossrpc","Accepted a new connection from: %s" % str(addr[0])) self.readable_in.append(conn) #self.writable_in.append(conn) else: recvbuf = i.recv(self.buflength) if len(recvbuf) == 0: log.debug("bossrpc","Removing connection") log.debug("bossrpc","%i:%s" % (i.fileno(),self.sessions.keys())) if i.fileno() in self.sessions.keys(): if (session.hasKey('cmdint')): cmdint = session['cmdint'] cmdint.auth.logout(self.sessions[i.fileno()]) del self.sessions[i.fileno()] log.debug("bossrpc","Removed session") else: log.debug("bossrpc","No session found to remove") i.close() self.readable_in.remove(i) #self.writable_in.remove(i) else: recvbuf = string.strip(recvbuf) if len(recvbuf) > 0: if i.fileno() in self.lengths: self.data[i.fileno()] += recvbuf #log.debug("bossrpc","more data") else: (msglength,flags,msg) = string.split(recvbuf, ':', 2) self.lengths[i.fileno()] = int(msglength) self.data[i.fileno()] = msg #log.debug("bossrpc","start of data") log.debug("bossrpc", "%i - %i" % (self.lengths[i.fileno()], len(self.data[i.fileno()]))) if self.lengths[i.fileno()] <= len(self.data[i.fileno()]): xml = self.data[i.fileno()] xml = string.strip(zlib.decompress(xml)) response = xmlrpclib.loads(xml) log.debug("bossrpc","Received xmlrpc message: %s",response) if response[1] == "auth" and "login" in response[0]: log.debug("bossrpc","Received login message: %s-%s",str(response[1]),str(response[0])) if (session.hasKey('cmdint')): cmdint = session['cmdint'] sessionid = cmdint.auth.login(response[0][1],response[0][2]) newxml = "" if sessionid != None: log.debug("bossrpc","Received sessionid: %s",sessionid) self.sessions[i.fileno()] = sessionid sessionid = (sessionid,) newxml = self.encodeBossRpc(sessionid,methodresponse=True) else: log.deug("bossrpc","Invalid login") newxml = self.encodeBossRpc(("Permission Denied",),methodresponse=True) i.sendall(newxml) elif response[1] == "auth" and "logout" in response[0]: log.debug("bossrpc","Received logout message") blah = 0 if session.hasKey('cmdint'): cmdint = session['cmdint'] if i.fileno() in self.sessions.keys(): if (session.hasKey('cmdint')): cmdint = session['cmdint'] blah = cmdint.auth.logout(self.sessions[i.fileno()]) del self.sessions[i.fileno()] log.debug("bossrpc","Removed session") else: log.debug("bossrpc","No session found to remove") newxml = self.encodeBossRpc((blah,),methodresponse=True) i.sendall(newxml) elif response[1] in dir(self.interface) and callable(getattr(self.interface, response[1])): ans = (getattr(self.interface,response[1])(*response[0]),) #print ans #xml = string.strip(xmlrpclib.dumps(ans, methodresponse=True)) #log.debug("bossrpc","Sending xmlrpc message: %s",str(ans)) #xml = zlib.compress(xml) #print xml bossxml = self.encodeBossRpc(ans,methodresponse=True) i.sendall(bossxml) del self.lengths[i.fileno()] del self.data[i.fileno()] readable, writable, errorable = select.select(self.readable_in,self.writable_in,self.errorable_in,0) for i in writable: i.shutdown() i.close()
class QueueManager: eoqNameToClass = {"allshuffle": AllRandomQueue, "allstraight": AllStraightQueue, "repeatqueue": RepeatQueue, "playlist": PlaylistQueue, "stop": StopPlayingQueue } def __init__(self, dbh, parent): self.songqueue = UserEditableQueue(self, dbh, parent) self.endofqueue = AllStraightQueue(self, dbh, parent) self.dbh = dbh self.parent = parent self.session = Session() self.currenteoqtype = None self.usingendofqueue = 0 def updateEndOfQueue(self): log.debug("funcs", "QueueManager.updateEndOfQueue()") log.debug("queue", "UEOQ: currenteoqtype: %s sess: %s", self.currenteoqtype, self.session["cfg"].get("endofqueue")) if self.session.hasKey("endofqueue"): log.debug("queue", "endofqueue set") if self.session["endofqueue"] != self.currenteoqtype: self.currenteoqtype = self.session["endofqueue"] self.endofqueue = self.eoqNameToClass[self.currenteoqtype](self, self.dbh, self.parent) else: if self.session["cfg"].get("endofqueue") != self.currenteoqtype: self.currenteoqtype = self.session["cfg"].get("endofqueue") self.endofqueue = self.eoqNameToClass[self.currenteoqtype](self, self.dbh, self.parent) log.debug("queue", "End of Queue type is (%s) %s", self.currenteoqtype, self.endofqueue) def add(self, item): return self.songqueue.add(item) def remove(self, item): return self.songqueue.remove(item) def clear(self): return self.songqueue.clear() def shuffle(self): return self.songqueue.shuffle() def getSongIDs(self): return self.songqueue.getSongIDs() def getmd5sum(self): return self.songqueue.getmd5sum() def jump(self,index): self.usingendofqueue = 0 return self.songqueue.jump(index) def getCurrentSong(self): log.debug("funcs", "QueueManager.getCurrentSong()") if not self.usingendofqueue: temp = self.songqueue.getCurrentSong() #log.debug("queue", "endofqueue not in use. checking songqueue and got %s", temp) if temp is not None: return temp log.debug("queue", "Updating endofqueue and using it") self.updateEndOfQueue() self.usingendofqueue = 1 temp = self.endofqueue.getCurrentSong() log.debug("queue", "Tried to get song and got %s", temp) if temp is not None: return temp self.endofqueue.currentindex = 0 temp = self.endofqueue.getCurrentSong() log.debug("queue", "Tried to get song again and got %s", temp) if temp is not None: return temp if len(self.songqueue.items) > 0: return self.songqueue.items[0] else: return None def next(self): log.debug("funcs", "QueueManager.next()") # try real queue first. if we don't get a valid song, we use # the endofqueue queue. if that doesn't work, reset the # endofqueue index and try again. if self.usingendofqueue: temp = self.songqueue.getCurrentSong() # temp will really be the song we want next; it was # added to the queue while we were playing the # endofqueue queue. if temp is not None: self.usingendofqueue = 0 return temp temp = self.songqueue.next() if temp is not None: return temp self.usingendofqueue = 1 self.updateEndOfQueue() temp = self.endofqueue.next() if temp is not None: return temp # as a last resort, go back to the start of the endofqueue queue. self.endofqueue.currentindex = -1 return self.endofqueue.next() def prev(self): return self.songqueue.prev(self) def move(self,oldindex,newindex): return self.songqueue.move(oldindex, newindex) def getCurrentIndex(self): if self.usingendofqueue: return -1 return self.songqueue.currentindex def setCurrentIndex(self, index): if index < 0: index=len(self.songqueue.getSongIDs()) self.songqueue.currentindex = index
def handleRequest(self, cmd, argstuple): session = Session() args = [] for i in argstuple: args.append(i) #print "args " + str(args) #print "len args " + str(len(args)) if (session.hasKey('cmdint')): cmdint = session['cmdint'] if (cmd == "artist"): if len(args) > 0: arg1 = False if len(args) > 1: if isinstance(args[1], types.StringType): arg1 = True elif isinstance(args[1], types.IntType) and args[1] == 1: arg1 = True return cmdint.load.doQueueAdd("artistid", args[0], arg1) else: return xmlrpclib.Fault(1, "Invalid number of parameters given") elif (cmd == "album"): if len(args) > 0: arg1 = False if len(args) > 1: if isinstance(args[1], types.StringType): arg1 = True elif isinstance(args[1], types.IntType) and args[1] == 1: arg1 = True return cmdint.load.doQueueAdd("albumid", args[0], arg1) else: return xmlrpclib.Fault(1, "Invalid number of parameters given") elif (cmd == "song"): if len(args) > 0: arg1 = False if len(args) > 1: if isinstance(args[1], types.StringType): arg1 = True elif isinstance(args[1], types.IntType) and args[1] == 1: arg1 = True return cmdint.load.doQueueAdd("songid", args[0], arg1) else: return xmlrpclib.Fault(1, "Invalid number of parameters given") elif (cmd == "playlist"): if len(args) > 0: arg1 = False if len(args) > 1: if isinstance(args[1], types.StringType): arg1 = True elif isinstance(args[1], types.IntType) and args[1] == 1: arg1 = True return cmdint.load.doQueueAdd("playlistid", args[0], arg1) else: return xmlrpclib.Fault(1, "Invalid number of parameters given") elif (cmd == "genre"): if len(args) > 0: arg1 = False if len(args) > 1: if isinstance(args[1], types.StringType): arg1 = True elif isinstance(args[1], types.IntType) and args[1] == 1: arg1 = True return cmdint.load.doQueueAdd("genreid", args[0], arg1) else: return xmlrpclib.Fault(1, "Invalid number of parameters given") elif (cmd == "move"): if len(args) == 2 and isinstance(args[0], types.IntType) and isinstance(args[1], types.IntType): return cmdint.load.move(args[0], args[1]) else: return xmlrpclib.Fault(1, "Invalid number or invalid type of parameters given") elif (cmd == "remove"): if len(args) == 1 and isinstance(args[0], types.IntType): return cmdint.load.remove(args[0]) else: return xmlrpclib.Fault(1, "Invalid number or invalid type of parameters given") elif (cmd == "shuffle"): return cmdint.load.shuffle() else: return xmlrpclib.Fault(1, "Invalid command in the load realm")
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