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 1/3] pym/portage/package/ebuild/fetch.py: Factor out _get_checksum_failure_max_tries
Date: Sun, 19 Jan 2014 03:08:34
Message-Id: 26b08899dfaa958e93339ba9d33e5bf36f20a914.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 | 58 +++++++++++++++++++++----------------
7 1 file changed, 33 insertions(+), 25 deletions(-)
8
9 diff --git a/pym/portage/package/ebuild/fetch.py b/pym/portage/package/ebuild/fetch.py
10 index 5316f03..4337247 100644
11 --- a/pym/portage/package/ebuild/fetch.py
12 +++ b/pym/portage/package/ebuild/fetch.py
13 @@ -240,6 +240,37 @@ _size_suffix_map = {
14 'Y' : 80,
15 }
16
17 +
18 +def _get_checksum_failure_max_tries(settings, default=5):
19 + """Get the maximum number of failed download attempts
20 +
21 + Generally, downloading the same file repeatedly from
22 + every single available mirror is a waste of bandwidth
23 + and time, so there needs to be a cap.
24 + """
25 + v = default
26 + try:
27 + v = int(settings.get("PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS",
28 + default))
29 + except (ValueError, OverflowError):
30 + writemsg(_("!!! Variable PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS"
31 + " contains non-integer value: '%s'\n") % \
32 + settings["PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS"],
33 + noiselevel=-1)
34 + writemsg(_("!!! Using PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS "
35 + "default value: %s\n") % default,
36 + noiselevel=-1)
37 + v = default
38 + if v < 1:
39 + writemsg(_("!!! Variable PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS"
40 + " contains value less than 1: '%s'\n") % v, noiselevel=-1)
41 + writemsg(_("!!! Using PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS "
42 + "default value: %s\n") % default,
43 + noiselevel=-1)
44 + v = default
45 + return v
46 +
47 +
48 def fetch(myuris, mysettings, listonly=0, fetchonly=0,
49 locks_in_subdir=".locks", use_locks=1, try_mirrors=1, digests=None,
50 allow_missing_digests=True):
51 @@ -263,31 +294,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
52 print(_(">>> \"mirror\" mode desired and \"mirror\" restriction found; skipping fetch."))
53 return 1
54
55 - # Generally, downloading the same file repeatedly from
56 - # every single available mirror is a waste of bandwidth
57 - # and time, so there needs to be a cap.
58 - checksum_failure_max_tries = 5
59 - v = checksum_failure_max_tries
60 - try:
61 - v = int(mysettings.get("PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS",
62 - checksum_failure_max_tries))
63 - except (ValueError, OverflowError):
64 - writemsg(_("!!! Variable PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS"
65 - " contains non-integer value: '%s'\n") % \
66 - mysettings["PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS"], noiselevel=-1)
67 - writemsg(_("!!! Using PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS "
68 - "default value: %s\n") % checksum_failure_max_tries,
69 - noiselevel=-1)
70 - v = checksum_failure_max_tries
71 - if v < 1:
72 - writemsg(_("!!! Variable PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS"
73 - " contains value less than 1: '%s'\n") % v, noiselevel=-1)
74 - writemsg(_("!!! Using PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS "
75 - "default value: %s\n") % checksum_failure_max_tries,
76 - noiselevel=-1)
77 - v = checksum_failure_max_tries
78 - checksum_failure_max_tries = v
79 - del v
80 + checksum_failure_max_tries = _get_checksum_failure_max_tries(
81 + settings=mysettings)
82
83 fetch_resume_size_default = "350K"
84 fetch_resume_size = mysettings.get("PORTAGE_FETCH_RESUME_MIN_SIZE")
85 --
86 1.8.5.2.8.g0f6c0d1

Replies