From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B20601382C5 for ; Mon, 23 Apr 2018 18:52:41 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 02A3DE0ACB; Mon, 23 Apr 2018 18:52:41 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B84B0E0ABA for ; Mon, 23 Apr 2018 18:52:40 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 31147335C30 for ; Mon, 23 Apr 2018 18:52:39 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id E504C27C for ; Mon, 23 Apr 2018 18:52:37 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1524508756.8002d9343c385075ece19a131b0f584ec255a5b5.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/dbapi/porttree.py X-VCS-Directories: pym/portage/dbapi/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 8002d9343c385075ece19a131b0f584ec255a5b5 X-VCS-Branch: master Date: Mon, 23 Apr 2018 18:52:37 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: e4e0c65b-b090-4847-9ce8-2e0fd8fea44d X-Archives-Hash: 353e2d56f54aa9d7ab1b0044e4809c44 commit: 8002d9343c385075ece19a131b0f584ec255a5b5 Author: Zac Medico gentoo org> AuthorDate: Sun Apr 22 19:57:09 2018 +0000 Commit: Zac Medico gentoo org> CommitDate: Mon Apr 23 18:39:16 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=8002d934 portdbapi: add async_fetch_map method (bug 653810) Add a portdbapi.async_fetch_map method which is identical to the existing portdbapi.getFetchMap method, but returns a future. This will be used by EbuildFetcher in order to avoid event loop recursion. Bug: https://bugs.gentoo.org/653810 Reviewed-by: Brian Dolbec gentoo.org> pym/portage/dbapi/porttree.py | 75 +++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 951e5760a..3cd929963 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -728,25 +728,66 @@ class portdbapi(dbapi): URIs. @rtype: dict """ + loop = self._event_loop + return loop.run_until_complete( + self.async_fetch_map(mypkg, useflags=useflags, + mytree=mytree, loop=loop)) - try: - eapi, myuris = self.aux_get(mypkg, - ["EAPI", "SRC_URI"], mytree=mytree) - except KeyError: - # Convert this to an InvalidDependString exception since callers - # already handle it. - raise portage.exception.InvalidDependString( - "getFetchMap(): aux_get() error reading "+mypkg+"; aborting.") + def async_fetch_map(self, mypkg, useflags=None, mytree=None, loop=None): + """ + Asynchronous form of getFetchMap. - if not eapi_is_supported(eapi): - # Convert this to an InvalidDependString exception - # since callers already handle it. - raise portage.exception.InvalidDependString( - "getFetchMap(): '%s' has unsupported EAPI: '%s'" % \ - (mypkg, eapi)) - - return _parse_uri_map(mypkg, {'EAPI':eapi,'SRC_URI':myuris}, - use=useflags) + @param mypkg: cpv for an ebuild + @type mypkg: String + @param useflags: a collection of enabled USE flags, for evaluation of + conditionals + @type useflags: set, or None to enable all conditionals + @param mytree: The canonical path of the tree in which the ebuild + is located, or None for automatic lookup + @type mypkg: String + @param loop: event loop (defaults to global event loop) + @type loop: EventLoop + @return: A future that results in a dict which maps each file name to + a set of alternative URIs. + @rtype: asyncio.Future (or compatible) + """ + loop = loop or global_event_loop() + loop = getattr(loop, '_asyncio_wrapper', loop) + result = loop.create_future() + + def aux_get_done(aux_get_future): + if result.cancelled(): + return + if aux_get_future.exception() is not None: + if isinstance(future.exception(), PortageKeyError): + # Convert this to an InvalidDependString exception since + # callers already handle it. + result.set_exception(portage.exception.InvalidDependString( + "getFetchMap(): aux_get() error reading " + + mypkg + "; aborting.")) + else: + result.set_exception(future.exception()) + return + + eapi, myuris = aux_get_future.result() + + if not eapi_is_supported(eapi): + # Convert this to an InvalidDependString exception + # since callers already handle it. + result.set_exception(portage.exception.InvalidDependString( + "getFetchMap(): '%s' has unsupported EAPI: '%s'" % \ + (mypkg, eapi))) + return + + result.set_result(_parse_uri_map(mypkg, + {'EAPI':eapi,'SRC_URI':myuris}, use=useflags)) + + aux_get_future = self.async_aux_get( + mypkg, ["EAPI", "SRC_URI"], mytree=mytree) + result.add_done_callback(lambda result: + aux_get_future.cancel() if result.cancelled() else None) + aux_get_future.add_done_callback(aux_get_done) + return result def getfetchsizes(self, mypkg, useflags=None, debug=0, myrepo=None): # returns a filename:size dictionnary of remaining downloads