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 A395D138247 for ; Mon, 20 Jan 2014 01:42:49 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8D71DE0E84; Mon, 20 Jan 2014 01:42:48 +0000 (UTC) Received: from albert.telenet-ops.be (albert.telenet-ops.be [195.130.137.90]) by pigeon.gentoo.org (Postfix) with ESMTP id C1A93E0E83 for ; Mon, 20 Jan 2014 01:42:47 +0000 (UTC) Received: from TOMWIJ-GENTOO ([94.226.55.127]) by albert.telenet-ops.be with bizsmtp id G1im1n00K2khLEN061imBZ; Mon, 20 Jan 2014 02:42:47 +0100 Date: Mon, 20 Jan 2014 02:41:41 +0100 From: Tom Wijsman To: wking@tremily.us Cc: gentoo-portage-dev@lists.gentoo.org Subject: Re: [gentoo-portage-dev] [PATCH 2/3] pym/portage/package/ebuild/fetch.py: Factor out _get_fetch_resume_size Message-ID: <20140120024141.258009e4@TOMWIJ-GENTOO> In-Reply-To: <8db147529a1958a6c86087a521e33c019e619dec.1390099978.git.wking@tremily.us> References: <8db147529a1958a6c86087a521e33c019e619dec.1390099978.git.wking@tremily.us> X-Mailer: Claws Mail 3.9.0 (GTK+ 2.24.22; x86_64-pc-linux-gnu) 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 Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/55sUeVZ9a3xVWihV0luZ9Al"; protocol="application/pgp-signature" X-Archives-Salt: 2b2c31a1-7b43-4526-a613-7d5e61bb9892 X-Archives-Hash: 7262fce2cc2a1cd5cbb1e6ba15389197 --Sig_/55sUeVZ9a3xVWihV0luZ9Al Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Sat, 18 Jan 2014 19:07:46 -0800 "W. Trevor King" wrote: > +def _get_fetch_resume_size(settings, default=3D'350K'): > + v =3D settings.get("PORTAGE_FETCH_RESUME_MIN_SIZE") > + if v is not None: > + v =3D "".join(v.split()) > + if not v: > + # If it's empty, silently use the default. > + v =3D default > + match =3D _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=3D-1) > + writemsg(_("!!! Using > PORTAGE_FETCH_RESUME_MIN_SIZE " > + "default value: %s\n") % default, > + noiselevel=3D-1) > + v =3D None > + if v is None: > + v =3D default > + match =3D _fetch_resume_size_re.match(v) > + v =3D 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 =3D "".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 =3D default Afterwards, you have 'match =3D _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? --=20 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 --Sig_/55sUeVZ9a3xVWihV0luZ9Al Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQEcBAEBAgAGBQJS3H7VAAoJEJWyH81tNOV9bQsIAJ4bPSYfnjGzBD77DLo0cft4 z5aF/Gu6vajqVVxTbrYSQ+m7zJz992Q9vkKIO9D1uZdJ1w3V8v8qWwCsIryLVYk6 KRA6UynLQTKG4Xde1wYg7dAD2ZXowYQ7+mozA+GLeYOzzcs2iJda8cWfTLYuweka OQpQP6LWAG2lWp9NMbGTpTkFULqswsmGDHfd1fdpIXcsKlnQiGWyISLsCG7hld46 4GdXpDCHCYmcNSYQPtaCug1l74QXnZM3SBCekeafOnU3jlNqlJxqorqi5FlGl0U0 uNjOTPatVX+CipPFqo2Dw2TcHhJua30c/48GntgMCg6rPoT/UniRz/9WDJxz4aQ= =m9p2 -----END PGP SIGNATURE----- --Sig_/55sUeVZ9a3xVWihV0luZ9Al--