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
14 _mysql = self.args["input"].split("@")[0].split(":")
16 _mysql = ["mythtv", "mythtv"]
18 self.log.debug("aqui 1")
20 _args = self.args["input"].split("@")[1].split(":")
22 gmyth_dict["mysql"] = _mysql
23 gmyth_dict["backend"] = _args[0]
24 gmyth_dict["port"] = _args[1].split("/", 1)[0]
26 self.log.debug("aqui 2 %s" % _args)
28 _tmp_file = _args[1].split("/", 1)[1]
30 self.log.debug("aqui 2a %s" % _tmp_file)
32 if _tmp_file.find("channel") >= 0:
33 gmyth_dict["kind"] = "c"
34 gmyth_dict["cfile"] = _tmp_file.split("=")[1]
35 self.log.debug("aqui 3")
37 gmyth_dict["kind"] = "f"
38 gmyth_dict["cfile"] = _tmp_file
39 self.log.debug("aqui 4")
41 self.log.debug("aqui 5")
43 self.args["input"] = "-"
47 def _setup_mythfile(err):
48 size = err.read(20).split("\n")[0].split("Size:")[1]
49 flags = fcntl.fcntl (err, fcntl.F_GETFL, 0) | os.O_NONBLOCK
50 fcntl.fcntl(err, fcntl.F_SETFL, flags)
54 def _setup_gmythcat(self):
55 gmyth_cat = utils.which("gmyth-cat")
56 return [ utils.which("gmyth-cat"),
57 "-h", self.args["gmyth-cat"]["backend"],
58 "-p", self.args["gmyth-cat"]["port"],
59 "-" + self.args["gmyth-cat"]["kind"],
60 self.args["gmyth-cat"]["cfile"]
64 def start_myth(self, outfd):
65 opts = _setup_gmythcat(self)
67 self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE,
68 stderr=subprocess.PIPE,
71 self.log.error("Error executing gmyth-cat: %s" % e)
74 if not self._run_mencoder(input=self.gmyth.stdout,
75 output=subprocess.PIPE):
78 if self.args["gmyth-cat"]["kind"] == "f":
80 size = _setup_mythfile(self.gmyth.stderr)
81 self.log.debug("Size of file: %s" % size)
83 self.log.error("Problems getting size of file: %s" % e)
87 while self.proc and self.proc.poll() == None:
88 r, w, x = select([self.gmyth.stderr, self.proc.stdout],
90 if self.proc.stdout in r:
91 d = self.proc.stdout.read(4096)
94 if self.gmyth.stderr in r:
95 partial = self.gmyth.stderr.read(50).split("\n")[-2]
97 self.status = utils.progress_bar(self.log,
101 except IndexError, e:
104 self.log.error("Problems handling data: %s" % e)
107 self.log.info("Finished sending data")