コード例 #1
0
ファイル: test_mux.py プロジェクト: wileykestner/hecate
def newmux():
    mux = Tmux(binascii.hexlify(os.urandom(8)))
    muxes.append(mux)
    return mux
コード例 #2
0
ファイル: hecate.py プロジェクト: wileykestner/hecate
    def __init__(self,
                 *command,
                 width=80,
                 height=24,
                 wait_interval=0.01,
                 default_timeout=1):
        """
        Hecate will run the command line arguments specified by command (
        note: These may not contain spaces. If you want to pass this to a
        shell, invoke the shell explicitly).

        Additional parameters:

            width and height specify the height of the console to run in in
                characters. Note that you cannot currently resize the console
                once started.
            wait_interval is the polling frequency for functions like
                await_text. A smaller value will be more CPU intensive but
                may be slightly faster.
            default_timeout specifies the default timeout for all await
                functions.
        """
        self.wait_interval = wait_interval
        self.default_timeout = default_timeout
        self.has_shutdown = False
        self.tmux_id = binascii.hexlify(os.urandom(8)).decode('ascii')
        self.exit_seen = False
        self.tmux = Tmux(self.tmux_id)
        try:
            self.report_file = os.path.join(hecate_temp_dir(), self.tmux_id)
            with open(self.report_file, "w"):
                pass
            self.shutdown_called = False
            self.launched = False
            self.tmux.new_session(
                width=width,
                height=height,
                name=HECATE_SESSION_NAME,
                command=' '.join(
                    map(shlex.quote,
                        [sys.executable, RUNNER_PROGRAM, self.report_file] +
                        list(command))))
            sessions = [
                l.strip() for l in self.tmux.execute_command(
                    "list-sessions", "-F", "#{session_name}").splitlines()
            ]
            sessions.remove(HECATE_SESSION_NAME)
            for s in sessions:
                self.tmux.kill_session(s)
            windows = [
                l.strip() for l in self.tmux.execute_command(
                    "list-windows", "-F", "#{window_name}").splitlines()
            ]
            assert len(windows) == 1
            self.target_window = windows[0]
            assert len(self.tmux.panes()) == 1
            self.screenshot()
            for _ in self.poll_until_timeout(self.default_timeout):
                report = self.report_variables()
                if runner.CHILD in report:
                    self.ready = True
                    self.screenshot()
                    break
            else:
                raise Timeout("Process failed to start")
            report = self.report_variables()
            os.kill(report[runner.CONTROLLER], signal.SIGUSR1)
            self.child_pid = report[runner.CHILD]
        except:
            self.shutdown_called = True
            self.tmux.shutdown()
            raise