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>
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, 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)) * \