* Re: [gentoo-portage-dev] [PATCH 2/3] pym/portage/package/ebuild/fetch.py: Factor out _get_fetch_resume_size
@ 2014-01-20 1:41 99% ` Tom Wijsman
0 siblings, 0 replies; 1+ results
From: Tom Wijsman @ 2014-01-20 1:41 UTC (permalink / raw
To: wking; +Cc: gentoo-portage-dev
[-- Attachment #1: Type: text/plain, Size: 2022 bytes --]
On Sat, 18 Jan 2014 19:07:46 -0800
"W. Trevor King" <wking@tremily.us> wrote:
> +def _get_fetch_resume_size(settings, default='350K'):
> + v = settings.get("PORTAGE_FETCH_RESUME_MIN_SIZE")
> + 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
> PORTAGE_FETCH_RESUME_MIN_SIZE"
> + " contains an unrecognized format:
> '%s'\n") % \
> +
> settings["PORTAGE_FETCH_RESUME_MIN_SIZE"],
> + noiselevel=-1)
> + writemsg(_("!!! Using
> PORTAGE_FETCH_RESUME_MIN_SIZE "
> + "default value: %s\n") % default,
> + noiselevel=-1)
> + v = None
> + if v is None:
> + v = default
> + match = _fetch_resume_size_re.match(v)
> + v = int(match.group(1)) * \
> + 2 ** _size_suffix_map[match.group(2).upper()]
> + return v
There is some duplicate code here, I think the conditions can be
rewritten in such way that the duplicate code doesn't take place.
Move everything from the first 'if' except for the first line out
of that 'if', that way get a bare:
if v is not None:
v = "".join(v.split())
Outside that, you now have 'if not v:' whereas you later have
'if v is None:'; you can optimize this to 'if not v or v is None:'
(maybe that can be optimized further, dunno) and just have one
condition set the default here. This gives you:
if not v or v is None:
# If it's empty, silently use the default.
v = default
Afterwards, you have 'match = _fetch_resume_size_re.match(v)' in both
places, you can again just have this once.
Can the two remaining code blocks just be placed after that?
--
With kind regards,
Tom Wijsman (TomWij)
Gentoo Developer
E-mail address : TomWij@gentoo.org
GPG Public Key : 6D34E57D
GPG Fingerprint : C165 AF18 AB4C 400B C3D2 ABF0 95B2 1FCD 6D34 E57D
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply [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 3:07 [gentoo-portage-dev] [PATCH 0/3] Initial fetch() refactoring W. Trevor King
2014-01-19 3:07 ` [gentoo-portage-dev] [PATCH 2/3] pym/portage/package/ebuild/fetch.py: Factor out _get_fetch_resume_size W. Trevor King
2014-01-20 1:41 99% ` Tom Wijsman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox