Gentoo Archives: gentoo-portage-dev

From: "W. Trevor King" <wking@×××××××.us>
To: gentoo-portage-dev@l.g.o
Cc: "W. Trevor King" <wking@×××××××.us>
Subject: [gentoo-portage-dev] [PATCH 2/3] pym/portage/package/ebuild/fetch.py: Factor out _get_fetch_resume_size
Date: Sun, 19 Jan 2014 03:08:46
Message-Id: 8db147529a1958a6c86087a521e33c019e619dec.1390099978.git.wking@tremily.us
In Reply to: [gentoo-portage-dev] [PATCH 0/3] Initial fetch() refactoring by "W. Trevor King"
1 The current fetch() function is quite long, which makes it hard to
2 know what I can change without adverse side effects. By pulling this
3 logic out of the main function, we get clearer logic in fetch() and
4 more explicit input for the config extraction.
5 ---
6 pym/portage/package/ebuild/fetch.py | 50 ++++++++++++++++++++-----------------
7 1 file changed, 27 insertions(+), 23 deletions(-)
8
9 diff --git a/pym/portage/package/ebuild/fetch.py b/pym/portage/package/ebuild/fetch.py
10 index 4337247..bd572fa 100644
11 --- a/pym/portage/package/ebuild/fetch.py
12 +++ b/pym/portage/package/ebuild/fetch.py
13 @@ -271,6 +271,32 @@ def _get_checksum_failure_max_tries(settings, default=5):
14 return v
15
16
17 +def _get_fetch_resume_size(settings, default='350K'):
18 + v = settings.get("PORTAGE_FETCH_RESUME_MIN_SIZE")
19 + if v is not None:
20 + v = "".join(v.split())
21 + if not v:
22 + # If it's empty, silently use the default.
23 + v = default
24 + match = _fetch_resume_size_re.match(v)
25 + if (match is None or
26 + match.group(2).upper() not in _size_suffix_map):
27 + writemsg(_("!!! Variable PORTAGE_FETCH_RESUME_MIN_SIZE"
28 + " contains an unrecognized format: '%s'\n") % \
29 + settings["PORTAGE_FETCH_RESUME_MIN_SIZE"],
30 + noiselevel=-1)
31 + writemsg(_("!!! Using PORTAGE_FETCH_RESUME_MIN_SIZE "
32 + "default value: %s\n") % default,
33 + noiselevel=-1)
34 + v = None
35 + if v is None:
36 + v = default
37 + match = _fetch_resume_size_re.match(v)
38 + v = int(match.group(1)) * \
39 + 2 ** _size_suffix_map[match.group(2).upper()]
40 + return v
41 +
42 +
43 def fetch(myuris, mysettings, listonly=0, fetchonly=0,
44 locks_in_subdir=".locks", use_locks=1, try_mirrors=1, digests=None,
45 allow_missing_digests=True):
46 @@ -296,29 +322,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
47
48 checksum_failure_max_tries = _get_checksum_failure_max_tries(
49 settings=mysettings)
50 -
51 - fetch_resume_size_default = "350K"
52 - fetch_resume_size = mysettings.get("PORTAGE_FETCH_RESUME_MIN_SIZE")
53 - if fetch_resume_size is not None:
54 - fetch_resume_size = "".join(fetch_resume_size.split())
55 - if not fetch_resume_size:
56 - # If it's undefined or empty, silently use the default.
57 - fetch_resume_size = fetch_resume_size_default
58 - match = _fetch_resume_size_re.match(fetch_resume_size)
59 - if match is None or \
60 - (match.group(2).upper() not in _size_suffix_map):
61 - writemsg(_("!!! Variable PORTAGE_FETCH_RESUME_MIN_SIZE"
62 - " contains an unrecognized format: '%s'\n") % \
63 - mysettings["PORTAGE_FETCH_RESUME_MIN_SIZE"], noiselevel=-1)
64 - writemsg(_("!!! Using PORTAGE_FETCH_RESUME_MIN_SIZE "
65 - "default value: %s\n") % fetch_resume_size_default,
66 - noiselevel=-1)
67 - fetch_resume_size = None
68 - if fetch_resume_size is None:
69 - fetch_resume_size = fetch_resume_size_default
70 - match = _fetch_resume_size_re.match(fetch_resume_size)
71 - fetch_resume_size = int(match.group(1)) * \
72 - 2 ** _size_suffix_map[match.group(2).upper()]
73 + fetch_resume_size = _get_fetch_resume_size(settings=mysettings)
74
75 # Behave like the package has RESTRICT="primaryuri" after a
76 # couple of checksum failures, to increase the probablility
77 --
78 1.8.5.2.8.g0f6c0d1

Replies