def listToFile(filename): songList = playlist.getPlaylist() outString = "" for i in songList: outString += i[0]+","+i[1]+","+i[2]+"\n" fileHandle = open(filename,"w") fileHandle.write(outString) fileHandle.close()
def run(self): """ Override base class run() function. """ global stats data = self.conn.recv(1024) if data is None: print "Playlist Server: No data" plpmessage = plp.PLPMessage() plpmessage.parse(data) if plpmessage.command == "GET PLAYLIST" and plpmessage.program =="LTunez-Client": stats.playlists += 1 pl = playlist.getPlaylist(self.playlistLen, server_ip, self.port_rtsp) reply = plpmessage.createServerOkResponse("LTunez-Server", pl) print "Playlist Server: Sending playlist reply:\r\n" + reply self.conn.sendall(reply) else: #print "Playlist Server: Invalid request from client" reply = plpmessage.createServerFailureResponse("LTunez-Server") self.conn.sendall(reply) self.conn.close()
import os import signal import random pidfile='/tmp/animation_pids' def abort(signal,frame,pids): for pid in pids: os.kill(pid,signal.SIGKILL) signal.signal(signal.SIGINT, abort) signal.pause while 1: pl=playlist.getPlaylist() i = random.choice(pl) t = i[0] processlist=[] pids=open(pidfile,"w") pids.close() for animation in i[1]: p=subprocess.Popen(animation) processlist.append(p) print "[" + str(p.pid) + "] " + str(animation) pids= open(pidfile,'a') pids.write(str(p.pid)+"\n") pids.close() time.sleep(t) for process in processlist: process.kill()