def _launch_command(self): logging.debug(self.cmdstr) app = self.argv[0] conn = None for idx in reversed(range(len(self.argv))): if self.argv[idx] == "--connect": conn = virtinst.cli.getConnection(self.argv[idx + 1]) break if not conn and "virt-convert" not in app: raise RuntimeError("couldn't parse URI from command %s" % self.argv) skipmsg = self._skip_msg(conn) if skipmsg is not None: return (self.SKIP, skipmsg) oldstdout = sys.stdout oldstderr = sys.stderr oldargv = sys.argv try: out = StringIO.StringIO() sys.stdout = out sys.stderr = out sys.argv = self.argv try: if app.count("virt-install"): ret = virtinstall.main(conn=conn) elif app.count("virt-clone"): ret = virtclone.main(conn=conn) elif app.count("virt-image"): ret = virtimage.main(conn=conn) elif app.count("virt-convert"): ret = virtconvert.main() except SystemExit, sys_e: ret = sys_e.code if ret != 0: ret = -1 outt = out.getvalue() if outt.endswith("\n"): outt = outt[:-1] return (ret, outt)
def _launch_command(self, conn): logging.debug(self.cmdstr) app = self.argv[0] oldstdout = sys.stdout oldstderr = sys.stderr oldstdin = sys.stdin oldargv = sys.argv try: out = StringIO.StringIO() sys.stdout = out sys.stderr = out sys.argv = self.argv if self.input_file: sys.stdin = file(self.input_file) exc = "" try: if app.count("virt-install"): ret = virtinstall.main(conn=conn) elif app.count("virt-clone"): ret = virtclone.main(conn=conn) elif app.count("virt-convert"): ret = virtconvert.main(conn=conn) elif app.count("virt-xml"): ret = virtxml.main(conn=conn) except SystemExit, sys_e: ret = sys_e.code except Exception: ret = -1 exc = "\n" + "".join(traceback.format_exc()) if ret != 0: ret = -1 outt = out.getvalue() + exc if outt.endswith("\n"): outt = outt[:-1] return (ret, outt)