5 import lib.utils as utils
6 import lib.server as server
8 from select import select
10 def _setup_mythfile(err):
11 size = err.read(20).split("\n")[0].split("Size:")[1]
12 flags = fcntl.fcntl (err, fcntl.F_GETFL, 0) | os.O_NONBLOCK
13 fcntl.fcntl(err, fcntl.F_SETFL, flags)
17 def _setup_gmythcat(self):
18 gmyth_cat = utils.which("gmyth-cat")
19 return [ utils.which("gmyth-cat"),
20 "-h", self.args["gmyth-cat"][0],
21 "-p", self.args["gmyth-cat"][1],
22 "-" + self.args["gmyth-cat"][2],
23 self.args["gmyth-cat"][3]
27 def start_myth(self, outfd):
28 opts = _setup_gmythcat(self)
30 self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE,
31 stderr=subprocess.PIPE,
34 self.log.error("Error executing gmyth-cat: %s" % e)
37 if not self._run_mencoder(input=self.gmyth.stdout,
38 output=subprocess.PIPE):
41 if self.args["gmyth-cat"][2] == "f":
43 size = _setup_mythfile(self.gmyth.stderr)
44 self.log.debug("Size of file: %s" % size)
46 self.log.error("Problems getting size of file: %s" % e)
50 while self.proc and self.proc.poll() == None:
51 r, w, x = select([self.gmyth.stderr, self.proc.stdout],
53 if self.proc.stdout in r:
54 d = self.proc.stdout.read(4096)
57 if self.gmyth.stderr in r:
58 partial = self.gmyth.stderr.read(50).split("\n")[-2]
60 self.status = utils.progress_bar(self.log,
67 self.log.error("Problems handling data: %s" % e)
70 self.log.info("Finished sending data")