Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/_emirrordist/
Date: Sat, 27 Feb 2021 03:57:25
Message-Id: 1614398079.0f3070198c56a8bc3b23e3965ab61136d3de76ae.zmedico@gentoo
1 commit: 0f3070198c56a8bc3b23e3965ab61136d3de76ae
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Sat Feb 27 03:49:29 2021 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Sat Feb 27 03:54:39 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=0f307019
7
8 emirrordist: support minimal object as options for use in unit tests
9
10 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
11
12 lib/portage/_emirrordist/Config.py | 33 +++++++++++++++++----------------
13 1 file changed, 17 insertions(+), 16 deletions(-)
14
15 diff --git a/lib/portage/_emirrordist/Config.py b/lib/portage/_emirrordist/Config.py
16 index 4bee4f45e..1c7a27d66 100644
17 --- a/lib/portage/_emirrordist/Config.py
18 +++ b/lib/portage/_emirrordist/Config.py
19 @@ -1,4 +1,4 @@
20 -# Copyright 2013-2020 Gentoo Authors
21 +# Copyright 2013-2021 Gentoo Authors
22 # Distributed under the terms of the GNU General Public License v2
23
24 import copy
25 @@ -25,24 +25,24 @@ class Config:
26 self.start_time = time.time()
27 self._open_files = []
28
29 - self.log_success = self._open_log('success', options.success_log, 'a')
30 - self.log_failure = self._open_log('failure', options.failure_log, 'a')
31 + self.log_success = self._open_log('success', getattr(options, 'success_log', None), 'a')
32 + self.log_failure = self._open_log('failure', getattr(options, 'failure_log', None), 'a')
33
34 self.distfiles = None
35 - if options.distfiles is not None:
36 + if getattr(options, 'distfiles', None) is not None:
37 self.distfiles = options.distfiles
38
39 self.mirrors = copy.copy(portdb.settings.thirdpartymirrors())
40
41 - if options.mirror_overrides is not None:
42 + if getattr(options, 'mirror_overrides', None) is not None:
43 self.mirrors.update(grabdict(options.mirror_overrides))
44
45 - if options.mirror_skip is not None:
46 + if getattr(options, 'mirror_skip', None) is not None:
47 for x in options.mirror_skip.split(","):
48 self.mirrors[x] = []
49
50 self.whitelist = None
51 - if options.whitelist_from is not None:
52 + if getattr(options, 'whitelist_from', None) is not None:
53 self.whitelist = set()
54 for filename in options.whitelist_from:
55 for line in grablines(filename):
56 @@ -51,27 +51,27 @@ class Config:
57 self.whitelist.add(line)
58
59 self.restrict_mirror_exemptions = None
60 - if options.restrict_mirror_exemptions is not None:
61 + if getattr(options, 'restrict_mirror_exemptions', None) is not None:
62 self.restrict_mirror_exemptions = frozenset(
63 options.restrict_mirror_exemptions.split(","))
64
65 self.recycle_db = None
66 - if options.recycle_db is not None:
67 + if getattr(options, 'recycle_db', None) is not None:
68 self.recycle_db = self._open_shelve(
69 options.recycle_db, 'recycle')
70
71 self.distfiles_db = None
72 - if options.distfiles_db is not None:
73 + if getattr(options, 'distfiles_db', None) is not None:
74 self.distfiles_db = self._open_shelve(
75 options.distfiles_db, 'distfiles')
76
77 self.deletion_db = None
78 - if options.deletion_db is not None:
79 + if getattr(options, 'deletion_db', None) is not None:
80 self.deletion_db = self._open_shelve(
81 options.deletion_db, 'deletion')
82
83 self.layout_conf = MirrorLayoutConfig()
84 - if options.layout_conf is None:
85 + if getattr(options, 'layout_conf', None) is None:
86 options.layout_conf = os.path.join(self.distfiles,
87 'layout.conf')
88 self.layout_conf.read_from_file(options.layout_conf)
89 @@ -79,7 +79,7 @@ class Config:
90
91 def _open_log(self, log_desc, log_path, mode):
92
93 - if log_path is None or self.options.dry_run:
94 + if log_path is None or getattr(self.options, 'dry_run', False):
95 log_func = logging.info
96 line_format = "%s: %%s" % log_desc
97 add_newline = False
98 @@ -106,12 +106,13 @@ class Config:
99 self._log_func(self._line_format % (msg,))
100
101 def _open_shelve(self, db_file, db_desc):
102 - if self.options.dry_run:
103 + dry_run = getattr(self.options, 'dry_run', False)
104 + if dry_run:
105 open_flag = "r"
106 else:
107 open_flag = "c"
108
109 - if self.options.dry_run and not os.path.exists(db_file):
110 + if dry_run and not os.path.exists(db_file):
111 db = {}
112 else:
113 try:
114 @@ -123,7 +124,7 @@ class Config:
115 from bsddb3 import dbshelve
116 db = dbshelve.open(db_file, flags=open_flag)
117
118 - if self.options.dry_run:
119 + if dry_run:
120 logging.warning("dry-run: %s db opened in readonly mode" % db_desc)
121 if not isinstance(db, dict):
122 volatile_db = dict((k, db[k]) for k in db)