Exemplo n.º 1
0
    async def run(self):
        self.expected = getattr(self, "expected", None) or {"returncode": 0}
        if self.debug:
            fd_pipes = {}
            pr = None
            pw = None
        else:
            pr, pw = os.pipe()
            fd_pipes = {1: pw, 2: pw}
            pr = open(pr, "rb", 0)

        proc = AsyncFunction(
            scheduler=asyncio.get_event_loop(),
            target=self._subprocess,
            args=(self.args, self.cwd, self.env, self.expected, self.debug),
            fd_pipes=fd_pipes,
        )

        proc.start()
        if pw is not None:
            os.close(pw)

        await proc.async_wait()

        if pr is None:
            stdio = None
        else:
            stdio = await _reader(pr)

        self.result = {
            "stdio": stdio,
            "result": proc.result,
        }
Exemplo n.º 2
0
    def test_getpid_double_fork(self):
        """
		Verify that portage.getpid() cache is updated correctly after
		two forks.
		"""
        loop = asyncio._wrap_loop()
        proc = AsyncFunction(scheduler=loop, target=self._test_getpid_fork)
        proc.start()
        self.assertEqual(proc.wait(), 0)
Exemplo n.º 3
0
 def _testAsyncFunctionStdin(self, loop=None):
     test_string = '1\n2\n3\n'
     pr, pw = os.pipe()
     fd_pipes = {0: pr}
     reader = AsyncFunction(scheduler=loop,
                            fd_pipes=fd_pipes,
                            target=self._read_from_stdin,
                            args=(pw, ))
     reader.start()
     os.close(pr)
     _set_nonblocking(pw)
     with open(pw, mode='wb', buffering=0) as pipe_write:
         yield _writer(pipe_write, test_string.encode('utf_8'), loop=loop)
     self.assertEqual((yield reader.async_wait()), os.EX_OK)
     self.assertEqual(reader.result, test_string)
Exemplo n.º 4
0
 async def _testAsyncFunctionStdin(self, loop):
     test_string = "1\n2\n3\n"
     pr, pw = os.pipe()
     fd_pipes = {0: pr}
     reader = AsyncFunction(scheduler=loop,
                            fd_pipes=fd_pipes,
                            target=self._read_from_stdin,
                            args=(pw, ))
     reader.start()
     os.close(pr)
     _set_nonblocking(pw)
     with open(pw, mode="wb", buffering=0) as pipe_write:
         await _writer(pipe_write, test_string.encode("utf_8"))
     self.assertEqual((await reader.async_wait()), os.EX_OK)
     self.assertEqual(reader.result, test_string)
Exemplo n.º 5
0
	def sync_async(self, emerge_config=None, repo=None, master_hooks=True):
		self.emerge_config = emerge_config
		self.settings, self.trees, self.mtimedb = emerge_config
		self.xterm_titles = "notitles" not in self.settings.features
		self.portdb = self.trees[self.settings['EROOT']]['porttree'].dbapi
		return SyncRepo(sync_task=AsyncFunction(target=self.sync,
			kwargs=dict(emerge_config=emerge_config, repo=repo,
			master_hooks=master_hooks)),
			sync_callback=self._sync_callback)
Exemplo n.º 6
0
    def _test_getpid_fork(self):
        """
		Verify that portage.getpid() cache is updated in a forked child process.
		"""
        loop = asyncio._wrap_loop()
        proc = AsyncFunction(scheduler=loop, target=portage.getpid)
        proc.start()
        proc.wait()
        self.assertEqual(proc.pid, proc.result)
Exemplo n.º 7
0
    def submit(self, fn, *args, **kwargs):
        """Submits a callable to be executed with the given arguments.

        Schedules the callable to be executed as fn(*args, **kwargs) and returns
        a Future instance representing the execution of the callable.

        Returns:
                A Future representing the given call.
        """
        future = self._loop.create_future()
        proc = AsyncFunction(
            target=functools.partial(self._guarded_fn_call, fn, args, kwargs))
        self._submit_queue.append((future, proc))
        self._schedule()
        return future
Exemplo n.º 8
0
 def _copy_proot_exit(self, proc):
     if self._default_exit(proc) != os.EX_OK:
         self.wait()
     else:
         self._start_task(
             AsyncFunction(
                 target=install_mask_dir,
                 args=(
                     os.path.join(
                         self._proot, self.settings["EPREFIX"].lstrip(os.sep)
                     ),
                     self._pkg_install_mask,
                 ),
             ),
             self._pkg_install_mask_exit,
         )
def async_main(fork_exitcode, loop=None):
    loop = asyncio._wrap_loop(loop)
    proc = AsyncFunction(scheduler=loop, target=fork_main)
    proc.start()
    proc.async_wait().add_done_callback(
        lambda future: fork_exitcode.set_result(future.result()))
Exemplo n.º 10
0
					hooks[filepath] = name
				else:
					writemsg_level(" %s %s hook: '%s' is not executable\n"
						% (warn("*"), _dir, _unicode_decode(name),),
						level=logging.WARN, noiselevel=2)
			self.hooks[_dir] = hooks


	def get_module_descriptions(self, mod):
		desc = self.module_controller.get_func_descriptions(mod)
		if desc:
			return desc
		return []

	def async(self, emerge_config=None, repo=None):
		proc = AsyncFunction(target=self.sync,
			kwargs=dict(emerge_config=emerge_config, repo=repo))
		proc.addExitListener(self._sync_callback)
		return proc

	def sync(self, emerge_config=None, repo=None):
		self.emerge_config = emerge_config
		self.callback = None
		self.repo = repo
		self.exitcode = 1
		self.updatecache_flg = False
		if repo.sync_type in self.module_names:
			tasks = [self.module_controller.get_class(repo.sync_type)]
		else:
			msg = "\n%s: Sync module '%s' is not an installed/known type'\n" \
				% (bad("ERROR"), repo.sync_type)
			return self.exitcode, msg
Exemplo n.º 11
0
 def async (self, emerge_config=None, repo=None):
     proc = AsyncFunction(target=self.sync,
                          kwargs=dict(emerge_config=emerge_config,
                                      repo=repo))
     proc.addExitListener(self._sync_callback)
     return proc