ebuild: fetch: Flatten conditionals in _get_fetch_resume_size fetch-refactor
authorW. Trevor King <wking@tremily.us>
Mon, 20 Jan 2014 03:15:57 +0000 (19:15 -0800)
committerW. Trevor King <wking@tremily.us>
Fri, 24 Jan 2014 18:43:40 +0000 (10:43 -0800)
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

index 0093a6e3b3f4a7168ce7eb44a6d2861383f4aad1..2bf88d8b1e2180f6293be3805584caee29db0e46 100644 (file)
@@ -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'
 
 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 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)) * \
                v = default
                match = _fetch_resume_size_re.match(v)
        v = int(match.group(1)) * \