def handle(self, *args, **options): # check if mpg123 is available fin, fout = os.popen4(["which", "mpg123"]) self.mpg123 = fout.read().replace("\n", "") if not len(self.mpg123): print "mpg123 not installed" return pidFile = os.path.dirname( os.path.abspath(__file__) ) + "/../../daemon.pid" if options["start"]: if os.path.exists(pidFile): print "Daemon already running, pid file exists" return pid = daemon.pidfile.TimeoutPIDLockFile( pidFile, 10 ) print "Starting jukebox_mpg123 daemon..." self.daemon = daemon.DaemonContext( uid=os.getuid(), gid=os.getgid(), pidfile=pid, working_directory=os.getcwd(), detach_process=True, signal_map={ SIGTSTP: self.shutdown, SIGABRT: self.skipSong } ) with self.daemon: print "Register player" pid = int(open(pidFile).read()) players_api = api.players() players_api.add(pid) self.play() elif options["stop"]: if not os.path.exists(pidFile): print "Daemon not running" return print "Stopping daemon..." pid = int(open(pidFile).read()) os.kill(pid, SIGTSTP) print "Unregister player " + str(pid) players_api = api.players() players_api.remove(pid) else: self.print_help("jukebox_shout", "help")
def handle(self, *args, **options): # check if mpg123 is available fin, fout = os.popen4(["which", "mpg123"]) self.mpg123 = fout.read().replace("\n", "") if not len(self.mpg123): print "mpg123 not installed" return pidFile = os.path.dirname( os.path.abspath(__file__)) + "/../../daemon.pid" if options["start"]: if os.path.exists(pidFile): print "Daemon already running, pid file exists" return pid = daemon.pidfile.TimeoutPIDLockFile(pidFile, 10) print "Starting jukebox_mpg123 daemon..." self.daemon = daemon.DaemonContext(uid=os.getuid(), gid=os.getgid(), pidfile=pid, working_directory=os.getcwd(), detach_process=True, signal_map={ SIGTSTP: self.shutdown, SIGABRT: self.skipSong }) with self.daemon: print "Register player" pid = int(open(pidFile).read()) players_api = api.players() players_api.add(pid) self.play() elif options["stop"]: if not os.path.exists(pidFile): print "Daemon not running" return print "Stopping daemon..." pid = int(open(pidFile).read()) os.kill(pid, SIGTSTP) print "Unregister player " + str(pid) players_api = api.players() players_api.remove(pid) else: self.print_help("jukebox_shout", "help")
def handle(self, *args, **options): pidFile = os.path.dirname( os.path.abspath(__file__) ) + "/../../daemon.pid" if options["start"] or options["fg"]: if (options["host"] is None or options["port"] is None or options["password"] is None ): print "Required arguments: host, port, password" self.print_help("jukebox_shout", "help") return if os.path.exists(pidFile): print "Daemon already running, pid file exists" return pid = daemon.pidfile.TimeoutPIDLockFile( pidFile, 10 ) self.shout = shout.Shout() print "Using libshout version %s" % shout.version() self.shout.audio_info = { shout.SHOUT_AI_BITRATE: "128", shout.SHOUT_AI_SAMPLERATE: "44100", shout.SHOUT_AI_CHANNELS: "2" } self.shout.name = "Democratic Jukebox" self.shout.url = "http://" + options["host"] + ":" + \ options["port"] + "/stream" self.shout.mount = "/stream" self.shout.port = int(options["port"]) self.shout.user = "******" self.shout.password = options["password"] self.shout.genre = "Mixed" self.shout.description = "Your democratic music player" self.shout.host = options["host"] self.shout.ogv = 0 self.shout.format = "mp3" try: self.shout.open() self.shout.close() except shout.ShoutException as exception: print "Error: " + str(exception) return if options["start"]: print "Starting jukebox_shout daemon..." self.daemon = daemon.DaemonContext( uid=os.getuid(), gid=os.getgid(), pidfile=pid, working_directory=os.getcwd(), detach_process=True, signal_map={ SIGTSTP: self.shutdown, SIGABRT: self.skipSong } ) with self.daemon: self.shout.open() print "Register player" pid = int(open(pidFile).read()) players_api = api.players() players_api.add(pid) songs_api = api.songs() while 1: self.sendfile(songs_api.getNextSong()) elif options["fg"]: self.shout.open() print "Register player" pid = os.getpid() players_api = api.players() players_api.add(pid) songs_api = api.songs() while 1: song = songs_api.getNextSong() self.sendfile(song) elif options["stop"]: if not os.path.exists(pidFile): print "Daemon not running" return print "Stopping daemon..." pid = int(open(pidFile).read()) os.kill(pid, SIGTSTP) print "Unregister player " + str(pid) players_api = api.players() players_api.remove(pid) else: self.print_help("jukebox_shout", "help")
def handle(self, *args, **options): pidFile = os.path.dirname( os.path.abspath(__file__)) + "/../../daemon.pid" if options["start"] or options["fg"]: if (options["host"] is None or options["port"] is None or options["password"] is None): print "Required arguments: host, port, password" self.print_help("jukebox_shout", "help") return if os.path.exists(pidFile): print "Daemon already running, pid file exists" return pid = daemon.pidfile.TimeoutPIDLockFile(pidFile, 10) self.shout = shout.Shout() print "Using libshout version %s" % shout.version() self.shout.audio_info = { shout.SHOUT_AI_BITRATE: "128", shout.SHOUT_AI_SAMPLERATE: "44100", shout.SHOUT_AI_CHANNELS: "2" } self.shout.name = "Democratic Jukebox" self.shout.url = "http://" + options["host"] + ":" + \ options["port"] + "/stream" self.shout.mount = "/stream" self.shout.port = int(options["port"]) self.shout.user = "******" self.shout.password = options["password"] self.shout.genre = "Mixed" self.shout.description = "Your democratic music player" self.shout.host = options["host"] self.shout.ogv = 0 self.shout.format = "mp3" try: self.shout.open() self.shout.close() except shout.ShoutException as exception: print "Error: " + str(exception) return if options["start"]: print "Starting jukebox_shout daemon..." self.daemon = daemon.DaemonContext( uid=os.getuid(), gid=os.getgid(), pidfile=pid, working_directory=os.getcwd(), detach_process=True, signal_map={ SIGTSTP: self.shutdown, SIGABRT: self.skipSong }) with self.daemon: self.shout.open() print "Register player" pid = int(open(pidFile).read()) players_api = api.players() players_api.add(pid) songs_api = api.songs() while 1: self.sendfile(songs_api.getNextSong()) elif options["fg"]: self.shout.open() print "Register player" pid = os.getpid() players_api = api.players() players_api.add(pid) songs_api = api.songs() while 1: song = songs_api.getNextSong() self.sendfile(song) elif options["stop"]: if not os.path.exists(pidFile): print "Daemon not running" return print "Stopping daemon..." pid = int(open(pidFile).read()) os.kill(pid, SIGTSTP) print "Unregister player " + str(pid) players_api = api.players() players_api.remove(pid) else: self.print_help("jukebox_shout", "help")