Gentoo Archives: gentoo-portage-dev

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

Replies