From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 2F72D138247 for ; Sun, 19 Jan 2014 22:14:57 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1D2EDE0E23; Sun, 19 Jan 2014 22:14:48 +0000 (UTC) Received: from qmta06.westchester.pa.mail.comcast.net (qmta06.westchester.pa.mail.comcast.net [76.96.62.56]) by pigeon.gentoo.org (Postfix) with ESMTP id 79441E0E1A for ; Sun, 19 Jan 2014 22:14:47 +0000 (UTC) Received: from omta21.westchester.pa.mail.comcast.net ([76.96.62.72]) by qmta06.westchester.pa.mail.comcast.net with comcast id Fy1a1n0011ZXKqc56yEn0J; Sun, 19 Jan 2014 22:14:47 +0000 Received: from odin.tremily.us ([24.18.63.50]) by omta21.westchester.pa.mail.comcast.net with comcast id FyEl1n00M152l3L3hyEmsk; Sun, 19 Jan 2014 22:14:47 +0000 Received: from mjolnir.tremily.us (unknown [192.168.0.141]) by odin.tremily.us (Postfix) with ESMTPS id 8B0ABF07B72; Sun, 19 Jan 2014 14:14:45 -0800 (PST) Received: (nullmailer pid 11339 invoked by uid 1000); Sun, 19 Jan 2014 22:14:16 -0000 From: "W. Trevor King" To: gentoo-portage-dev@lists.gentoo.org Cc: "W. Trevor King" , Zac Medico , Arfrever Frehtes Taifersar Arahesis Subject: [gentoo-portage-dev] [PATCH v2 1/3] pym/portage/package/ebuild/fetch.py: Factor out _get_checksum_failure_max_tries Date: Sun, 19 Jan 2014 14:14:10 -0800 Message-Id: X-Mailer: git-send-email 1.8.5.2.8.g0f6c0d1 In-Reply-To: References: <20140119205802.GE19935@odin.tremily.us> In-Reply-To: References: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20121106; t=1390169687; bh=N0PQIrbqTxHvzhyftf1OffZYN6qbHGWHxzsV2ZFY/C8=; h=Received:Received:Received:Received:From:To:Subject:Date: Message-Id; b=l0jq1NmPXwLmbSeSzi7v3KGIZRAozQxfikwhB5XfJT7Uf5wJ0BFK7vMgGC0YISStr E5onfPgx8aFWlqkOtruSrshf20YvKkN1KGA6X18/ghjQhKMG4XM5U/mjOYkUVVWSnG p1ImEKXEoyiirWknre22kGghH93ddJHU2i7bhy5CFGmhszGpwWpCYmXV8+9rl1LWn3 pPbx8tussWswRZkcnSSSMNBqj99Y32JA4BP2YVPbhIFdyzWhQtqxk8pKyl3xhPNRHt 5oUJCwwtoD7eFEr1dEHkXchAyCTVxJysWIqZK5X1QHMVSz3ziOy0GW5ZvHz0jqSRBB 8wLbZV7/h1qtA== Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Archives-Salt: aac5b1b5-3518-4a58-ae8e-c6730aa5b5b2 X-Archives-Hash: 6553c10dac4089bfc27ee06b363f00dd The current fetch() function is quite long, which makes it hard to know what I can change without adverse side effects. By pulling this logic out of the main function, we get clearer logic in fetch() and more explicit input for the config extraction. --- pym/portage/package/ebuild/fetch.py | 59 +++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/pym/portage/package/ebuild/fetch.py b/pym/portage/package/ebuild/fetch.py index 5316f03..6f46572 100644 --- a/pym/portage/package/ebuild/fetch.py +++ b/pym/portage/package/ebuild/fetch.py @@ -240,6 +240,38 @@ _size_suffix_map = { 'Y' : 80, } + +def _get_checksum_failure_max_tries(settings, default=5): + """ + Get the maximum number of failed download attempts + + Generally, downloading the same file repeatedly from + every single available mirror is a waste of bandwidth + and time, so there needs to be a cap. + """ + v = default + try: + v = int(settings.get("PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS", + default)) + except (ValueError, OverflowError): + writemsg(_("!!! Variable PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS" + " contains non-integer value: '%s'\n") % \ + settings["PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS"], + noiselevel=-1) + writemsg(_("!!! Using PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS " + "default value: %s\n") % default, + noiselevel=-1) + v = default + if v < 1: + writemsg(_("!!! Variable PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS" + " contains value less than 1: '%s'\n") % v, noiselevel=-1) + writemsg(_("!!! Using PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS " + "default value: %s\n") % default, + noiselevel=-1) + v = default + return v + + def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", use_locks=1, try_mirrors=1, digests=None, allow_missing_digests=True): @@ -263,31 +295,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, print(_(">>> \"mirror\" mode desired and \"mirror\" restriction found; skipping fetch.")) return 1 - # Generally, downloading the same file repeatedly from - # every single available mirror is a waste of bandwidth - # and time, so there needs to be a cap. - checksum_failure_max_tries = 5 - v = checksum_failure_max_tries - try: - v = int(mysettings.get("PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS", - checksum_failure_max_tries)) - except (ValueError, OverflowError): - writemsg(_("!!! Variable PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS" - " contains non-integer value: '%s'\n") % \ - mysettings["PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS"], noiselevel=-1) - writemsg(_("!!! Using PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS " - "default value: %s\n") % checksum_failure_max_tries, - noiselevel=-1) - v = checksum_failure_max_tries - if v < 1: - writemsg(_("!!! Variable PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS" - " contains value less than 1: '%s'\n") % v, noiselevel=-1) - writemsg(_("!!! Using PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS " - "default value: %s\n") % checksum_failure_max_tries, - noiselevel=-1) - v = checksum_failure_max_tries - checksum_failure_max_tries = v - del v + checksum_failure_max_tries = _get_checksum_failure_max_tries( + settings=mysettings) fetch_resume_size_default = "350K" fetch_resume_size = mysettings.get("PORTAGE_FETCH_RESUME_MIN_SIZE") -- 1.8.5.2.8.g0f6c0d1