Gentoo Archives: gentoo-commits

From: Brian Dolbec <brian.dolbec@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/sync/modules/websync/, ...
Date: Fri, 02 May 2014 23:13:44
Message-Id: 1399072156.bff56b63af5536b88ae88caa62bc865aceeaa891.dol-sen@gentoo
1 commit: bff56b63af5536b88ae88caa62bc865aceeaa891
2 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
3 AuthorDate: Sun Mar 30 03:36:00 2014 +0000
4 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
5 CommitDate: Fri May 2 23:09:16 2014 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=bff56b63
7
8 Code the new validate_config system
9
10 ---
11 pym/portage/sync/__init__.py | 19 +++++++-
12 pym/portage/sync/config_checks.py | 68 ++++++++++++++++++++++++++++
13 pym/portage/sync/controller.py | 7 +--
14 pym/portage/sync/modules/cvs/__init__.py | 20 ++++++++
15 pym/portage/sync/modules/git/__init__.py | 4 ++
16 pym/portage/sync/modules/rsync/__init__.py | 4 ++
17 pym/portage/sync/modules/websync/__init__.py | 4 ++
18 7 files changed, 122 insertions(+), 4 deletions(-)
19
20 diff --git a/pym/portage/sync/__init__.py b/pym/portage/sync/__init__.py
21 index 65498ec..6d2a732 100644
22 --- a/pym/portage/sync/__init__.py
23 +++ b/pym/portage/sync/__init__.py
24 @@ -1,10 +1,11 @@
25 -# Copyright 2010 Gentoo Foundation
26 +# Copyright 2014 Gentoo Foundation
27 # Distributed under the terms of the GNU General Public License v2
28
29 import os
30
31 from portage.emaint.module import Modules
32 from portage.sync.controller import SyncManager
33 +from portage.sync.config_checks import check_type
34
35 sync_manager = None
36
37 @@ -20,6 +21,13 @@ module_names = module_controller.module_names[:]
38
39
40 def get_syncer(settings=None, logger=None):
41 + '''Initializes and returns the SyncManager instance
42 + to be used for sync operations
43 +
44 + @param settings: emerge.settings instance
45 + @param logger: emerge logger instance
46 + @returns SyncManager instance
47 + '''
48 global sync_manager
49 if sync_manager and not settings and not logger:
50 return sync_manager
51 @@ -33,4 +41,13 @@ def get_syncer(settings=None, logger=None):
52 return sync_manager
53
54
55 +def validate_config(repo, logger):
56 + '''Validate the repos.conf settings for the repo'''
57 + if not check_type(repo, logger, module_names):
58 + return False
59
60 + #print(repo)
61 + if repo.sync_type:
62 + validated = module_controller.modules[repo.sync_type]['validate_config']
63 + return validated(repo, logger).repo_checks()
64 + return True
65
66 diff --git a/pym/portage/sync/config_checks.py b/pym/portage/sync/config_checks.py
67 new file mode 100644
68 index 0000000..8ef1974
69 --- /dev/null
70 +++ b/pym/portage/sync/config_checks.py
71 @@ -0,0 +1,68 @@
72 +# Copyright 2014 Gentoo Foundation
73 +# Distributed under the terms of the GNU General Public License v2
74 +
75 +'''
76 +Base class for performing repos.conf sync variables checks.
77 +This class contains common checks code and functions.
78 +
79 +For additional checks or other customizations,
80 +subclass it adding and/or overriding classes as needed.
81 +'''
82 +
83 +import logging
84 +
85 +from portage.localization import _
86 +from portage.util import writemsg_level
87 +
88 +
89 +def check_type(repo, logger, module_names):
90 + if repo.sync_uri is not None and repo.sync_type is None:
91 + writemsg_level("!!! %s\n" %
92 + _("Repository '%s' has sync-uri attribute, but is missing sync-type attribute")
93 + % repo.name, level=logger.ERROR, noiselevel=-1)
94 + return False
95 + if repo.sync_type not in module_names + [None]:
96 + writemsg_level("!!! %s\n" %
97 + _("Repository '%s' has sync-type attribute set to unsupported value: '%s'")
98 + % (repo.name, repo.sync_type),
99 + level=logger.ERROR, noiselevel=-1)
100 + return False
101 + return True
102 +
103 +
104 +class CheckSyncConfig(object):
105 + '''Base repos.conf settings checks class'''
106 +
107 + def __init__(self, repo=None, logger=None):
108 + '''Class init function
109 +
110 + @param logger: optional logging instance,
111 + defaults to logging module
112 + '''
113 + self.logger = logger or logging
114 + self.repo = repo
115 + self.checks = ['check_uri', 'check_auto_sync']
116 +
117 +
118 + def repo_checks(self):
119 + '''Perform all checks available'''
120 + for check in self.checks:
121 + getattr(self, check)()
122 +
123 +
124 + def check_uri(self):
125 + '''Check the sync_uri setting'''
126 + if self.repo.sync_uri is None:
127 + writemsg_level("!!! %s\n" % _("Repository '%s' has sync-type attribute, but is missing sync-uri attribute")
128 + % self.repo.name, level=self.logger.ERROR, noiselevel=-1)
129 +
130 +
131 + def check_auto_sync(self):
132 + '''Check the auto_sync setting'''
133 + if self.repo.auto_sync is None:
134 + writemsg_level("!!! %s\n" % _("Repository '%s' is missing auto_sync attribute")
135 + % self.repo.name, level=self.logger.ERROR, noiselevel=-1)
136 + elif self.repo.auto_sync.lower() not in ["yes", "true", "no", "false"]:
137 + writemsg_level("!!! %s\n" % _("Repository '%s' auto_sync attribute must be one of: %s")
138 + % (self.repo.name, '{yes, true, no, false}'),
139 + level=self.logger.ERROR, noiselevel=-1)
140
141 diff --git a/pym/portage/sync/controller.py b/pym/portage/sync/controller.py
142 index a71cb96..70ec27b 100644
143 --- a/pym/portage/sync/controller.py
144 +++ b/pym/portage/sync/controller.py
145 @@ -1,4 +1,4 @@
146 -# Copyright 1999-2014 Gentoo Foundation
147 +# Copyright 2014 Gentoo Foundation
148 # Distributed under the terms of the GNU General Public License v2
149
150 from __future__ import print_function
151 @@ -87,10 +87,11 @@ class SyncManager(object):
152 self.module_names = self.module_controller.module_names[:]
153
154
155 - def get_modules(self, mod):
156 + def get_module_descriptions(self, mod):
157 desc = self.module_controller.get_func_descriptions(mod)
158 if desc:
159 - pass
160 + return desc
161 + return []
162
163
164 def sync(self, emerge_config=None, repo=None, callback=None):
165
166 diff --git a/pym/portage/sync/modules/cvs/__init__.py b/pym/portage/sync/modules/cvs/__init__.py
167 index 7e786c0..93e0e26 100644
168 --- a/pym/portage/sync/modules/cvs/__init__.py
169 +++ b/pym/portage/sync/modules/cvs/__init__.py
170 @@ -6,6 +6,25 @@ Performs a cvs up on repositories
171 """
172
173
174 +from portage.localization import _
175 +from portage.sync.config_checks import CheckSyncConfig
176 +from portage.util import writemsg_level
177 +
178 +
179 +class CheckCVSConfig(CheckSyncConfig):
180 +
181 + def __init__(self, logger):
182 + CheckSyncConfig.__init__(self, logger)
183 + self.checks.append('check_cvs_repo')
184 +
185 +
186 + def check_cvs_repo(self):
187 + if self.repo.sync_cvs_repo is None:
188 + writemsg_level("!!! %s\n" %
189 + _("Repository '%s' has sync-type=cvs, but is missing sync-cvs-repo attribute")
190 + % self.repo.name, level=self.logger.ERROR, noiselevel=-1)
191 +
192 +
193 module_spec = {
194 'name': 'cvs',
195 'description': __doc__,
196 @@ -29,6 +48,7 @@ module_spec = {
197 '"https://wiki.gentoo.org:Project:Portage" for details',
198 },
199 },
200 + 'validate_config': CheckCVSConfig,
201 }
202 }
203 }
204
205 diff --git a/pym/portage/sync/modules/git/__init__.py b/pym/portage/sync/modules/git/__init__.py
206 index 4ceaa84..eca44e2 100644
207 --- a/pym/portage/sync/modules/git/__init__.py
208 +++ b/pym/portage/sync/modules/git/__init__.py
209 @@ -6,6 +6,9 @@ Performs a git pull on repositories
210 """
211
212
213 +from portage.sync.config_checks import CheckSyncConfig
214 +
215 +
216 module_spec = {
217 'name': 'git',
218 'description': __doc__,
219 @@ -29,6 +32,7 @@ module_spec = {
220 '"https://wiki.gentoo.org:Project:Portage" for details',
221 },
222 },
223 + 'validate_config': CheckSyncConfig,
224 }
225 }
226 }
227
228 diff --git a/pym/portage/sync/modules/rsync/__init__.py b/pym/portage/sync/modules/rsync/__init__.py
229 index a0239bf..e3729ac 100644
230 --- a/pym/portage/sync/modules/rsync/__init__.py
231 +++ b/pym/portage/sync/modules/rsync/__init__.py
232 @@ -6,6 +6,9 @@
233 """
234
235
236 +from portage.sync.config_checks import CheckSyncConfig
237 +
238 +
239 module_spec = {
240 'name': 'rsync',
241 'description': __doc__,
242 @@ -28,6 +31,7 @@ module_spec = {
243 '"https://wiki.gentoo.org:Project:Portage" for details',
244 },
245 },
246 + 'validate_config': CheckSyncConfig,
247 }
248 }
249 }
250
251 diff --git a/pym/portage/sync/modules/websync/__init__.py b/pym/portage/sync/modules/websync/__init__.py
252 index 22abf8c..52356b7 100644
253 --- a/pym/portage/sync/modules/websync/__init__.py
254 +++ b/pym/portage/sync/modules/websync/__init__.py
255 @@ -8,6 +8,9 @@ Performs a http download of a portage snapshot and verifies and
256
257 import os
258
259 +from portage.sync.config_checks import CheckSyncConfig
260 +
261 +
262 DEFAULT_CLASS = "WebRsync"
263 AVAILABLE_CLASSES = [ "WebRsync", "PyWebsync"]
264 options = {"1": "WebRsync", "2": "PyWebsync"}
265 @@ -45,6 +48,7 @@ module_spec = {
266 '"https://wiki.gentoo.org:Project:Portage" for details',
267 },
268 },
269 + 'validate_config': CheckSyncConfig,
270 },
271 }
272 }