5 import lib.utils as utils
6 import lib.server as server
8 from select import select
10 def _setup_mythfilename(self):
11 # mythtv:mythtv@192.168.3.110:6543/1002_20070426230000.nuv
13 _mysql = self.args["input"].split("@")[0].split(":")
15 _mysql = ["mythtv", "mythtv"]
18 _args = self.args["input"].split("@")[1].split(":")
20 _args = self.args["input"].split(":")
23 gmyth_dict["mysql"] = _mysql
24 gmyth_dict["backend"] = _args[0]
25 gmyth_dict["port"] = _args[1].split("/", 1)[0]
27 self.log.debug("aqui 2 %s" % _args)
29 _tmp_file = _args[1].split("/", 1)[1]
31 if _tmp_file.find("channel") >= 0:
32 gmyth_dict["kind"] = "c"
33 gmyth_dict["cfile"] = _tmp_file.split("=")[1]
35 gmyth_dict["kind"] = "f"
36 gmyth_dict["cfile"] = _tmp_file
38 self.args["input"] = "-"
42 def _setup_mythfile(err):
43 size = err.read(20).split("\n")[0].split("Size:")[1]
44 flags = fcntl.fcntl (err, fcntl.F_GETFL, 0) | os.O_NONBLOCK
45 fcntl.fcntl(err, fcntl.F_SETFL, flags)
49 def _setup_gmythcat(self):
50 gmyth_cat = utils.which("gmyth-cat")
51 return [ utils.which("gmyth-cat"),
52 "-h", self.args["gmyth-cat"]["backend"],
53 "-p", self.args["gmyth-cat"]["port"],
54 "-" + self.args["gmyth-cat"]["kind"],
55 self.args["gmyth-cat"]["cfile"]
59 def start_myth(self, outfd):
60 opts = _setup_gmythcat(self)
62 self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE,
63 stderr=subprocess.PIPE,
66 self.log.error("Error executing gmyth-cat: %s" % e)
69 if not self._run_mencoder(input=self.gmyth.stdout,
70 output=subprocess.PIPE):
73 if self.args["gmyth-cat"]["kind"] == "f":
75 size = _setup_mythfile(self.gmyth.stderr)
76 self.log.debug("Size of file: %s" % size)
78 self.log.error("Problems getting size of file: %s" % e)
82 while self.proc and self.proc.poll() == None:
83 r, w, x = select([self.gmyth.stderr, self.proc.stdout],
85 if self.proc.stdout in r:
86 d = self.proc.stdout.read(4096)
89 if self.gmyth.stderr in r:
90 partial = self.gmyth.stderr.read(50).split("\n")[-2]
92 self.status = utils.progress_bar(self.log,
99 self.log.error("Problems handling data: %s" % e)
102 self.log.info("Finished sending data")