diff -r 000000000000 -r 76b9c97faada gmyth-stream/server/0.2/plugins/transcoders/mencoder_lib/mythtv.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder_lib/mythtv.py Tue May 15 20:16:26 2007 +0100 @@ -0,0 +1,72 @@ +import os +import subprocess +import fcntl + +import lib.utils as utils +import lib.server as server + +from select import select + +def _setup_mythfile(err): + size = err.read(20).split("\n")[0].split("Size:")[1] + flags = fcntl.fcntl (err, fcntl.F_GETFL, 0) | os.O_NONBLOCK + fcntl.fcntl(err, fcntl.F_SETFL, flags) + return size +# _setup_mythfile + +def _setup_gmythcat(self): + gmyth_cat = utils.which("gmyth-cat") + return [ utils.which("gmyth-cat"), + "-h", self.args["gmyth-cat"][0], + "-p", self.args["gmyth-cat"][1], + "-" + self.args["gmyth-cat"][2], + self.args["gmyth-cat"][3] + ] +# _setup_gmythcat + +def start_myth(self, outfd): + opts = _setup_gmythcat(self) + try: + self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + close_fds=True) + except Exception, e: + self.log.error("Error executing gmyth-cat: %s" % e) + return False + + if not self._run_mencoder(input=self.gmyth.stdout, + output=subprocess.PIPE): + return False + + if self.args["gmyth-cat"][2] == "f": + try: + size = _setup_mythfile(self.gmyth.stderr) + self.log.debug("Size of file: %s" % size) + except Exception, e: + self.log.error("Problems getting size of file: %s" % e) + return False + + try: + while self.proc and self.proc.poll() == None: + r, w, x = select([self.gmyth.stderr, self.proc.stdout], + [], [], 0) + if self.proc.stdout in r: + d = self.proc.stdout.read(4096) + outfd.write(d) + + if self.gmyth.stderr in r: + partial = self.gmyth.stderr.read(50).split("\n")[-2] + if partial != "": + self.status = utils.progress_bar(self.log, + int(partial), + int(size), 50) + + except IndexError, e: + pass + except Exception, e: + self.log.error("Problems handling data: %s" % e) + return False + + self.log.info("Finished sending data") + return True +# _start_myth()