def start_session(self, host, port, session, username, password, wait):
""" Start a session using qtnx """
self.state = "connecting"
if not os.path.exists(os.path.expanduser('~/.qtnx')):
os.mkdir(os.path.expanduser('~/.qtnx'))
# Generate qtnx's configuration file
filename = os.path.expanduser('~/.qtnx/%s-%s-%s.nxml') % (
host, port, session.replace("/", "_"))
nxml = open(filename, "w+")
config = self.NXML_TEMPLATE
config = config.replace("WL_NAME", "%s-%s-%s" % (host, port,
session.replace("/", "_")))
config = config.replace("WL_SERVER", host)
config = config.replace("WL_PORT", str(port))
config = config.replace("WL_COMMAND", "weblive-session %s" % session)
nxml.write(config)
nxml.close()
# Prepare qtnx call
cmd = [self.BINARY_PATH,
'%s-%s-%s' % (str(host), str(port), session.replace("/", "_")),
username,
password]
def qtnx_countdown():
""" Send progress events every two seconds """
if self.helper_progress == 10:
self.state = "connected"
self.emit("connected", False)
return False
else:
self.emit("progress", self.helper_progress * 10)
self.helper_progress += 1
return True
def qtnx_start_timer():
""" As we don't have a way of knowing the connection
status, we countdown from 20s
"""
self.helper_progress = 0
qtnx_countdown()
GObject.timeout_add_seconds(2, qtnx_countdown)
qtnx_start_timer()
if wait == False:
# Start in the background and attach a watch for when it exits
(self.helper_pid, stdin, stdout, stderr) = GObject.spawn_async(
cmd, standard_input=True, standard_output=True,
standard_error=True, flags=GObject.SPAWN_DO_NOT_REAP_CHILD)
GObject.child_watch_add(self.helper_pid, self._on_qtnx_exit,
filename)
else:
# Start it and wait till it finishes
p = subprocess.Popen(cmd)
p.wait()
评论列表
文章目录