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 |
21 |
b/pym/portage/emaint/modules/sync/sync.py |
22 |
index 08a92a7..4d66411 100644 |
23 |
--- a/pym/portage/emaint/modules/sync/sync.py |
24 |
+++ b/pym/portage/emaint/modules/sync/sync.py |
25 |
@@ -89,25 +89,45 @@ class SyncRepos(object): |
26 |
def auto_sync(self, **kwargs): |
27 |
'''Sync auto-sync enabled repos''' |
28 |
options = kwargs.get('options', None) |
29 |
- selected = self._get_repos(True) |
30 |
if options: |
31 |
return_messages = options.get('return-messages', False) |
32 |
else: |
33 |
return_messages = False |
34 |
- return self._sync(selected, return_messages, |
35 |
- emaint_opts=options) |
36 |
+ success, selected, msgs = self._get_repos(True) |
37 |
+ if not success: |
38 |
+ if return_messages: |
39 |
+ msgs.append(red(" * ") + \ |
40 |
+ "Errors were encountered while getting repos... returning") |
41 |
+ return (False, msgs) |
42 |
+ return (False, None) |
43 |
+ if not selected: |
44 |
+ if return_messages: |
45 |
+ msgs.append("Nothing to sync... returning") |
46 |
+ return (True, msgs) |
47 |
+ return (True, None) |
48 |
+ return self._sync(selected, return_messages, emaint_opts=options) |
49 |
|
50 |
|
51 |
def all_repos(self, **kwargs): |
52 |
'''Sync all repos defined in repos.conf''' |
53 |
- selected = self._get_repos(auto_sync_only=False) |
54 |
options = kwargs.get('options', None) |
55 |
if options: |
56 |
return_messages = options.get('return-messages', False) |
57 |
else: |
58 |
return_messages = False |
59 |
- return self._sync(selected, return_messages, |
60 |
- emaint_opts=options) |
61 |
+ success, selected, msgs = self._get_repos(auto_sync_only=False) |
62 |
+ if not success: |
63 |
+ if return_messages: |
64 |
+ msgs.append(red(" * ") + \ |
65 |
+ "Errors were encountered while getting repos... returning") |
66 |
+ return (False, msgs) |
67 |
+ return (False, None) |
68 |
+ if not selected: |
69 |
+ if return_messages: |
70 |
+ msgs.append("Nothing to sync... returning") |
71 |
+ return (True, msgs) |
72 |
+ return (True, None) |
73 |
+ return self._sync(selected, return_messages, emaint_opts=options) |
74 |
|
75 |
|
76 |
def repo(self, **kwargs): |
77 |
@@ -120,16 +140,17 @@ class SyncRepos(object): |
78 |
return_messages = False |
79 |
if isinstance(repos, _basestring): |
80 |
repos = repos.split() |
81 |
- available = self._get_repos(auto_sync_only=False) |
82 |
+ success, available, msgs = self._get_repos(auto_sync_only=False) |
83 |
+ # Ignore errors from _get_repos(), we only want to know if the repo |
84 |
+ # exists. |
85 |
selected = self._match_repos(repos, available) |
86 |
if not selected: |
87 |
- msgs = [red(" * ") + "The specified repos were not found: %s" % |
88 |
- (bold(", ".join(repos))) + "\n ...returning"] |
89 |
+ msgs.append(red(" * ") + "The specified repos are invalid or missing: %s" % |
90 |
+ (bold(", ".join(repos))) + "\n ...returning") |
91 |
if return_messages: |
92 |
return (False, msgs) |
93 |
return (False, None) |
94 |
- return self._sync(selected, return_messages, |
95 |
- emaint_opts=options) |
96 |
+ return self._sync(selected, return_messages, emaint_opts=options) |
97 |
|
98 |
|
99 |
@staticmethod |
100 |
@@ -148,10 +169,11 @@ class SyncRepos(object): |
101 |
|
102 |
|
103 |
def _get_repos(self, auto_sync_only=True): |
104 |
+ msgs = [] |
105 |
+ emerge_repos = [] |
106 |
selected_repos = [] |
107 |
- unknown_repo_names = [] |
108 |
- missing_sync_type = [] |
109 |
if self.emerge_config.args: |
110 |
+ unknown_repo_names = [] |
111 |
for repo_name in self.emerge_config.args: |
112 |
#print("_get_repos(): repo_name =", repo_name) |
113 |
try: |
114 |
@@ -159,32 +181,37 @@ class SyncRepos(object): |
115 |
except KeyError: |
116 |
unknown_repo_names.append(repo_name) |
117 |
else: |
118 |
- selected_repos.append(repo) |
119 |
- if repo.sync_type is None: |
120 |
- missing_sync_type.append(repo) |
121 |
- |
122 |
+ emerge_repos.append(repo) |
123 |
if unknown_repo_names: |
124 |
- writemsg_level("!!! %s\n" % _("Unknown repo(s): %s") % |
125 |
- " ".join(unknown_repo_names), |
126 |
- level=logging.ERROR, noiselevel=-1) |
127 |
- |
128 |
- if missing_sync_type: |
129 |
- writemsg_level("!!! %s\n" % |
130 |
- _("Missing sync-type for repo(s): %s") % |
131 |
- " ".join(repo.name for repo in missing_sync_type), |
132 |
- level=logging.ERROR, noiselevel=-1) |
133 |
- |
134 |
- if unknown_repo_names or missing_sync_type: |
135 |
- writemsg_level("Missing or unknown repos... returning", |
136 |
- level=logging.INFO, noiselevel=2) |
137 |
- return [] |
138 |
- |
139 |
+ msgs.append(warn(" * ") + "Unknown repo(s): %s\n" % |
140 |
+ " ".join(unknown_repo_names)); |
141 |
+ return (False, emerge_repos, msgs) |
142 |
+ selected_repos = emerge_repos |
143 |
else: |
144 |
selected_repos.extend(self.emerge_config.target_config.settings.repositories) |
145 |
- #print("_get_repos(), selected =", selected_repos) |
146 |
+ |
147 |
+ valid_repos = [] |
148 |
+ missing_sync_type = [] |
149 |
+ for repo in selected_repos: |
150 |
+ if repo.sync_type is None: |
151 |
+ missing_sync_type.append(repo.name) |
152 |
+ else: |
153 |
+ valid_repos.append(repo) |
154 |
+ if missing_sync_type: |
155 |
+ msgs.append(warn(" * ") + "Missing sync-type for repo(s): %s" % |
156 |
+ " ".join(missing_sync_type) + "\n") |
157 |
+ return (False, valid_repos, msgs) |
158 |
+ |
159 |
if auto_sync_only: |
160 |
- return self._filter_auto(selected_repos) |
161 |
- return selected_repos |
162 |
+ selected_repos = self._filter_auto(selected_repos) |
163 |
+ #print("_get_repos(), selected =", selected_repos) |
164 |
+ if emerge_repos: |
165 |
+ skipped_repos = set(emerge_repos) - set(selected_repos) |
166 |
+ if skipped_repos: |
167 |
+ msgs.append(warn(" * ") + "auto-sync is disabled for repo(s): %s" % |
168 |
+ " ".join(repo.name for repo in skipped_repos) + "\n") |
169 |
+ return (False, selected_repos, msgs) |
170 |
+ return (True, selected_repos, msgs) |
171 |
|
172 |
|
173 |
def _filter_auto(self, repos): |
174 |
@@ -204,14 +231,7 @@ class SyncRepos(object): |
175 |
k = "--" + k.replace("_", "-") |
176 |
self.emerge_config.opts[k] = v |
177 |
|
178 |
- selected_repos = [repo for repo in selected_repos if repo.sync_type |
179 |
is not None] |
180 |
msgs = [] |
181 |
- if not selected_repos: |
182 |
- msgs.append("Nothing to sync... returning") |
183 |
- if return_messages: |
184 |
- msgs.extend(self.rmessage([('None', os.EX_OK)], 'sync')) |
185 |
- return (True, msgs) |
186 |
- return (True, None) |
187 |
# Portage needs to ensure a sane umask for the files it creates. |
188 |
os.umask(0o22) |
189 |
|
190 |
-- |
191 |
2.10.2 |