Gentoo Archives: gentoo-portage-dev

From: Alexandru Elisei <alexandru.elisei@×××××.com>
To: gentoo-portage-dev@l.g.o
Cc: alexandru.elisei@×××××.com
Subject: [gentoo-portage-dev] [PATCH V2] sync.py: extend the checks in _get_repos() and fail when necessary (bugs 567478, 576272, 601054)
Date: Sun, 19 Feb 2017 21:02:53
Message-Id: 20170219210208.10389-1-alexandru.elisei@gmail.com
1 The existence of the sync-type attribute is now being checked for all
2 repos, not just for the repos given as arguments to emerge --sync. A
3 message is returned when a repo without sync-type is found and sync
4 will fail.
5
6 Emerge will now fail if at least one of the repos given to emerge --sync
7 doesn't exist or has auto-sync disabled.
8
9 auto_sync() and all_repos() also fail when no valid repos are found, but
10 they return success when no auto-sync repos are defined, or no repos are
11 defined at all on the system.
12
13 This commit and commit f57ae38 'emerge: make emerge --sync print
14 messages from SyncRepos.auto_sync()' shoulg solve bugs 567478, 576282
15 and partly 601054.
16 ---
17 pym/portage/emaint/modules/sync/sync.py | 104 +++++++++++++++++++-------------
18 1 file changed, 62 insertions(+), 42 deletions(-)
19
20 diff --git a/pym/portage/emaint/modules/sync/sync.py b/pym/portage/emaint/modules/sync/sync.py
21 index 08a92a7..4d66411 100644
22 --- a/pym/portage/emaint/modules/sync/sync.py
23 +++ b/pym/portage/emaint/modules/sync/sync.py
24 @@ -89,25 +89,45 @@ class SyncRepos(object):
25 def auto_sync(self, **kwargs):
26 '''Sync auto-sync enabled repos'''
27 options = kwargs.get('options', None)
28 - selected = self._get_repos(True)
29 if options:
30 return_messages = options.get('return-messages', False)
31 else:
32 return_messages = False
33 - return self._sync(selected, return_messages,
34 - emaint_opts=options)
35 + success, selected, msgs = self._get_repos(True)
36 + if not success:
37 + if return_messages:
38 + msgs.append(red(" * ") + \
39 + "Errors were encountered while getting repos... returning")
40 + return (False, msgs)
41 + return (False, None)
42 + if not selected:
43 + if return_messages:
44 + msgs.append("Nothing to sync... returning")
45 + return (True, msgs)
46 + return (True, None)
47 + return self._sync(selected, return_messages, emaint_opts=options)
48
49
50 def all_repos(self, **kwargs):
51 '''Sync all repos defined in repos.conf'''
52 - selected = self._get_repos(auto_sync_only=False)
53 options = kwargs.get('options', None)
54 if options:
55 return_messages = options.get('return-messages', False)
56 else:
57 return_messages = False
58 - return self._sync(selected, return_messages,
59 - emaint_opts=options)
60 + success, selected, msgs = self._get_repos(auto_sync_only=False)
61 + if not success:
62 + if return_messages:
63 + msgs.append(red(" * ") + \
64 + "Errors were encountered while getting repos... returning")
65 + return (False, msgs)
66 + return (False, None)
67 + if not selected:
68 + if return_messages:
69 + msgs.append("Nothing to sync... returning")
70 + return (True, msgs)
71 + return (True, None)
72 + return self._sync(selected, return_messages, emaint_opts=options)
73
74
75 def repo(self, **kwargs):
76 @@ -120,16 +140,17 @@ class SyncRepos(object):
77 return_messages = False
78 if isinstance(repos, _basestring):
79 repos = repos.split()
80 - available = self._get_repos(auto_sync_only=False)
81 + success, available, msgs = self._get_repos(auto_sync_only=False)
82 + # Ignore errors from _get_repos(), we only want to know if the repo
83 + # exists.
84 selected = self._match_repos(repos, available)
85 if not selected:
86 - msgs = [red(" * ") + "The specified repos were not found: %s" %
87 - (bold(", ".join(repos))) + "\n ...returning"]
88 + msgs.append(red(" * ") + "The specified repos are invalid or missing: %s" %
89 + (bold(", ".join(repos))) + "\n ...returning")
90 if return_messages:
91 return (False, msgs)
92 return (False, None)
93 - return self._sync(selected, return_messages,
94 - emaint_opts=options)
95 + return self._sync(selected, return_messages, emaint_opts=options)
96
97
98 @staticmethod
99 @@ -148,10 +169,11 @@ class SyncRepos(object):
100
101
102 def _get_repos(self, auto_sync_only=True):
103 + msgs = []
104 + emerge_repos = []
105 selected_repos = []
106 - unknown_repo_names = []
107 - missing_sync_type = []
108 if self.emerge_config.args:
109 + unknown_repo_names = []
110 for repo_name in self.emerge_config.args:
111 #print("_get_repos(): repo_name =", repo_name)
112 try:
113 @@ -159,32 +181,37 @@ class SyncRepos(object):
114 except KeyError:
115 unknown_repo_names.append(repo_name)
116 else:
117 - selected_repos.append(repo)
118 - if repo.sync_type is None:
119 - missing_sync_type.append(repo)
120 -
121 + emerge_repos.append(repo)
122 if unknown_repo_names:
123 - writemsg_level("!!! %s\n" % _("Unknown repo(s): %s") %
124 - " ".join(unknown_repo_names),
125 - level=logging.ERROR, noiselevel=-1)
126 -
127 - if missing_sync_type:
128 - writemsg_level("!!! %s\n" %
129 - _("Missing sync-type for repo(s): %s") %
130 - " ".join(repo.name for repo in missing_sync_type),
131 - level=logging.ERROR, noiselevel=-1)
132 -
133 - if unknown_repo_names or missing_sync_type:
134 - writemsg_level("Missing or unknown repos... returning",
135 - level=logging.INFO, noiselevel=2)
136 - return []
137 -
138 + msgs.append(warn(" * ") + "Unknown repo(s): %s\n" %
139 + " ".join(unknown_repo_names));
140 + return (False, emerge_repos, msgs)
141 + selected_repos = emerge_repos
142 else:
143 selected_repos.extend(self.emerge_config.target_config.settings.repositories)
144 - #print("_get_repos(), selected =", selected_repos)
145 +
146 + valid_repos = []
147 + missing_sync_type = []
148 + for repo in selected_repos:
149 + if repo.sync_type is None:
150 + missing_sync_type.append(repo.name)
151 + else:
152 + valid_repos.append(repo)
153 + if missing_sync_type:
154 + msgs.append(warn(" * ") + "Missing sync-type for repo(s): %s" %
155 + " ".join(missing_sync_type) + "\n")
156 + return (False, valid_repos, msgs)
157 +
158 if auto_sync_only:
159 - return self._filter_auto(selected_repos)
160 - return selected_repos
161 + selected_repos = self._filter_auto(selected_repos)
162 + #print("_get_repos(), selected =", selected_repos)
163 + if emerge_repos:
164 + skipped_repos = set(emerge_repos) - set(selected_repos)
165 + if skipped_repos:
166 + msgs.append(warn(" * ") + "auto-sync is disabled for repo(s): %s" %
167 + " ".join(repo.name for repo in skipped_repos) + "\n")
168 + return (False, selected_repos, msgs)
169 + return (True, selected_repos, msgs)
170
171
172 def _filter_auto(self, repos):
173 @@ -204,14 +231,7 @@ class SyncRepos(object):
174 k = "--" + k.replace("_", "-")
175 self.emerge_config.opts[k] = v
176
177 - selected_repos = [repo for repo in selected_repos if repo.sync_type is not None]
178 msgs = []
179 - if not selected_repos:
180 - msgs.append("Nothing to sync... returning")
181 - if return_messages:
182 - msgs.extend(self.rmessage([('None', os.EX_OK)], 'sync'))
183 - return (True, msgs)
184 - return (True, None)
185 # Portage needs to ensure a sane umask for the files it creates.
186 os.umask(0o22)
187
188 --
189 2.10.2

Replies