Example #1
0
    def test_await_process_tee(self):
        with open("a", "wb") as a_fh, open("b", "wb") as b_fh:
            process = Popen(["/bin/cat", "/bin/cat"], stdout=PIPE)
            await_process_tee(process, a_fh, b_fh)

        with open("a", "rb") as f:
            a_content = f.read()
        with open("b", "rb") as f:
            b_content = f.read()
        with open("/bin/cat", "rb") as f:
            cat_content = f.read()

        self.assertTrue(process.stdout.closed)
        self.assertEqual(cat_content, a_content)
        self.assertEqual(cat_content, b_content)
Example #2
0
    def execEclipse(self):
        log_name = "{}.LOG".format(self.base_name)

        with pushd(self.run_path), open(log_name, "wb") as log_file:
            if not os.path.exists(self.data_file):
                raise IOError("Can not find data_file:{}".format(
                    self.data_file))
            if not os.access(self.data_file, os.R_OK):
                raise OSError("Can not read data file:{}".format(
                    self.data_file))

            if self.num_cpu == 1:
                command = [self.sim.executable, self.base_name]
            else:
                self.initMPI()
                command = [
                    self.sim.mpirun, "-machinefile", self.machine_file, "-np",
                    str(self.num_cpu), self.sim.executable, self.base_name
                ]

            process = subprocess.Popen(
                command,
                env=self._build_simulator_environment(),
                stdout=subprocess.PIPE,
            )
            return await_process_tee(process, sys.stdout, log_file)
Example #3
0
    def test_await_process_tee(self):
        with open("original", "wb") as fh:
            fh.write(bytearray(os.urandom(_maxBytes)))

        with open("a", "wb") as a_fh, open("b", "wb") as b_fh:
            process = Popen(["/bin/cat", "original"], stdout=PIPE)
            await_process_tee(process, a_fh, b_fh)

        with open("a", "rb") as f:
            a_content = f.read()
        with open("b", "rb") as f:
            b_content = f.read()
        with open("original", "rb") as f:
            original_content = f.read()

        self.assertTrue(process.stdout.closed)
        self.assertEqual(original_content, a_content)
        self.assertEqual(original_content, b_content)
Example #4
0
    def execEclipse(self, eclrun_config=None):
        use_eclrun = eclrun_config is not None
        log_name = self._get_log_name(eclrun_config=eclrun_config)

        with pushd(self.run_path), open(log_name, "wb") as log_file:
            if not os.path.exists(self.data_file):
                raise IOError("Can not find data_file:{}".format(
                    self.data_file))
            if not os.access(self.data_file, os.R_OK):
                raise OSError("Can not read data file:{}".format(
                    self.data_file))

            command = (self._get_run_command(eclrun_config)
                       if use_eclrun else self._get_legacy_run_command())
            env = eclrun_config.run_env if use_eclrun else self._get_legacy_run_env(
            )

            process = subprocess.Popen(
                command,
                env=env,
                stdout=subprocess.PIPE,
            )
            return await_process_tee(process, sys.stdout, log_file)