public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download: 
* [gentoo-portage-dev] [PATCH v3 4/4] pym/portage/package/ebuild/fetch.py: Flatten conditionals in _get_fetch_resume_size
  @ 2014-01-20  3:26 99%   ` W. Trevor King
  0 siblings, 0 replies; 1+ results
From: W. Trevor King @ 2014-01-20  3:26 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Rafael Goncalves Martins, W. Trevor King

Make this easier to read by avoiding nested conditionals [1].

[1]: http://article.gmane.org/gmane.linux.gentoo.portage.devel/4058

Reported-by: Tom Wijsman <TomWij@gentoo.org>
---
 pym/portage/package/ebuild/fetch.py | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/pym/portage/package/ebuild/fetch.py b/pym/portage/package/ebuild/fetch.py
index 0093a6e..2bf88d8 100644
--- a/pym/portage/package/ebuild/fetch.py
+++ b/pym/portage/package/ebuild/fetch.py
@@ -276,24 +276,22 @@ def _get_checksum_failure_max_tries(settings, default=5):
 
 def _get_fetch_resume_size(settings, default='350K'):
 	key = 'PORTAGE_FETCH_RESUME_MIN_SIZE'
-	v = settings.get(key)
+	v = settings.get(key, default)
 	if v is not None:
 		v = "".join(v.split())
-		if not v:
-			# If it's empty, silently use the default.
-			v = default
-		match = _fetch_resume_size_re.match(v)
-		if (match is None or
-				match.group(2).upper() not in _size_suffix_map):
-			writemsg(_("!!! Variable %s contains an "
-				"unrecognized format: '%s'\n")
-				% (key, settings[key]),
-				noiselevel=-1)
-			writemsg(_("!!! Using %s default value: %s\n")
-				% (key, default),
-				noiselevel=-1)
-			v = None
-	if v is None:
+	if not v:
+		# If it's empty, silently use the default.
+		v = default
+	match = _fetch_resume_size_re.match(v)
+	if (match is None or
+			match.group(2).upper() not in _size_suffix_map):
+		writemsg(_("!!! Variable %s contains "
+			"an unrecognized format: '%s'\n")
+			% (key, settings[key]),
+			noiselevel=-1)
+		writemsg(_("!!! Using %s default value: %s\n")
+			% (key, default),
+			noiselevel=-1)
 		v = default
 		match = _fetch_resume_size_re.match(v)
 	v = int(match.group(1)) * \
-- 
1.8.5.2.8.g0f6c0d1



^ permalink raw reply related	[relevance 99%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2014-01-19 22:14     [gentoo-portage-dev] [PATCH v2 0/3] Initial fetch() refactoring W. Trevor King
2014-01-20  3:26     ` [gentoo-portage-dev] [PATCH v3 0/4] " W. Trevor King
2014-01-20  3:26 99%   ` [gentoo-portage-dev] [PATCH v3 4/4] pym/portage/package/ebuild/fetch.py: Flatten conditionals in _get_fetch_resume_size W. Trevor King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox