Gentoo Archives: gentoo-portage-dev

From: Brian Dolbec <dolsen@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH 1/3] portage/sync: Break out a NewBase class from SyncBase
Date: Thu, 29 Jan 2015 19:46:02
Message-Id: 1422560721-28354-2-git-send-email-dolsen@gentoo.org
In Reply to: [gentoo-portage-dev] portage sync changes, fixes by Brian Dolbec
1 From mgorny's suggestion, rename _sync() to update().
2 Raise NotImplementedError in base classes.
3 Directly override sync() in websync module.
4 Fix up line spacing to be consistent.
5 ---
6 pym/portage/sync/modules/cvs/cvs.py | 10 +++---
7 pym/portage/sync/modules/git/git.py | 8 ++---
8 pym/portage/sync/modules/rsync/rsync.py | 12 +++----
9 pym/portage/sync/modules/svn/svn.py | 10 +++---
10 pym/portage/sync/modules/websync/websync.py | 21 +++++------
11 pym/portage/sync/syncbase.py | 56 ++++++++++++++++++-----------
12 6 files changed, 64 insertions(+), 53 deletions(-)
13
14 diff --git a/pym/portage/sync/modules/cvs/cvs.py b/pym/portage/sync/modules/cvs/cvs.py
15 index 919cb34..9153815 100644
16 --- a/pym/portage/sync/modules/cvs/cvs.py
17 +++ b/pym/portage/sync/modules/cvs/cvs.py
18 @@ -7,10 +7,10 @@ import errno
19 import portage
20 from portage import os
21 from portage.util import writemsg_level
22 -from portage.sync.syncbase import SyncBase
23 +from portage.sync.syncbase import NewBase
24
25
26 -class CVSSync(SyncBase):
27 +class CVSSync(NewBase):
28 '''CVS sync module'''
29
30 short_desc = "Perform sync operations on CVS repositories"
31 @@ -21,7 +21,7 @@ class CVSSync(SyncBase):
32
33
34 def __init__(self):
35 - SyncBase.__init__(self, "cvs", portage.const.CVS_PACKAGE_ATOM)
36 + NewBase.__init__(self, "cvs", portage.const.CVS_PACKAGE_ATOM)
37
38
39 def exists(self, **kwargs):
40 @@ -47,9 +47,9 @@ class CVSSync(SyncBase):
41 return (0, False)
42
43
44 - def _sync(self):
45 + def update(self):
46 """
47 - Internal function to sync an existing CVS repository
48 + Internal function to update an existing CVS repository
49
50 @return: tuple of return code (0=success), whether the cache
51 needs to be updated
52 diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
53 index 3acfc2a..cea681c 100644
54 --- a/pym/portage/sync/modules/git/git.py
55 +++ b/pym/portage/sync/modules/git/git.py
56 @@ -10,10 +10,10 @@ from portage.output import create_color_func
57 good = create_color_func("GOOD")
58 bad = create_color_func("BAD")
59 warn = create_color_func("WARN")
60 -from portage.sync.syncbase import SyncBase
61 +from portage.sync.syncbase import NewBase
62
63
64 -class GitSync(SyncBase):
65 +class GitSync(NewBase):
66 '''Git sync class'''
67
68 short_desc = "Perform sync operations on git based repositories"
69 @@ -24,7 +24,7 @@ class GitSync(SyncBase):
70
71
72 def __init__(self):
73 - SyncBase.__init__(self, "git", portage.const.GIT_PACKAGE_ATOM)
74 + NewBase.__init__(self, "git", portage.const.GIT_PACKAGE_ATOM)
75
76
77 def exists(self, **kwargs):
78 @@ -67,7 +67,7 @@ class GitSync(SyncBase):
79 return (os.EX_OK, True)
80
81
82 - def _sync(self):
83 + def update(self):
84 ''' Update existing git repository, and ignore the syncuri. We are
85 going to trust the user and assume that the user is in the branch
86 that he/she wants updated. We'll let the user manage branches with
87 diff --git a/pym/portage/sync/modules/rsync/rsync.py b/pym/portage/sync/modules/rsync/rsync.py
88 index 52d8b0f..817164d 100644
89 --- a/pym/portage/sync/modules/rsync/rsync.py
90 +++ b/pym/portage/sync/modules/rsync/rsync.py
91 @@ -21,14 +21,14 @@ from portage.const import VCS_DIRS, TIMESTAMP_FORMAT, RSYNC_PACKAGE_ATOM
92 from portage.util import writemsg, writemsg_stdout
93 from portage.sync.getaddrinfo_validate import getaddrinfo_validate
94 from _emerge.UserQuery import UserQuery
95 -from portage.sync.syncbase import SyncBase
96 +from portage.sync.syncbase import NewBase
97
98
99 SERVER_OUT_OF_DATE = -1
100 EXCEEDED_MAX_RETRIES = -2
101
102
103 -class RsyncSync(SyncBase):
104 +class RsyncSync(NewBase):
105 '''Rsync sync module'''
106
107 short_desc = "Perform sync operations on rsync based repositories"
108 @@ -39,11 +39,11 @@ class RsyncSync(SyncBase):
109
110
111 def __init__(self):
112 - SyncBase.__init__(self, "rsync", RSYNC_PACKAGE_ATOM)
113 + NewBase.__init__(self, "rsync", RSYNC_PACKAGE_ATOM)
114
115
116 - def _sync(self):
117 - '''Internal sync function which performs only the sync'''
118 + def update(self):
119 + '''Internal update function which performs the transfer'''
120 opts = self.options.get('emerge_config').opts
121 self.usersync_uid = self.options.get('usersync_uid', None)
122 enter_invalid = '--ask-enter-invalid' in opts
123 @@ -287,7 +287,7 @@ class RsyncSync(SyncBase):
124 'Created New Directory %s ' % self.repo.location )
125 except IOError:
126 return (1, False)
127 - return self._sync()
128 + return self.update()
129
130
131 def _set_rsync_defaults(self):
132 diff --git a/pym/portage/sync/modules/svn/svn.py b/pym/portage/sync/modules/svn/svn.py
133 index 60ead4b..492ada3 100644
134 --- a/pym/portage/sync/modules/svn/svn.py
135 +++ b/pym/portage/sync/modules/svn/svn.py
136 @@ -7,10 +7,10 @@ import errno
137 import portage
138 from portage import os
139 from portage.util import writemsg_level
140 -from portage.sync.syncbase import SyncBase
141 +from portage.sync.syncbase import NewBase
142
143
144 -class SVNSync(SyncBase):
145 +class SVNSync(NewBase):
146 '''SVN sync module'''
147
148 short_desc = "Perform sync operations on SVN repositories"
149 @@ -21,7 +21,7 @@ class SVNSync(SyncBase):
150
151
152 def __init__(self):
153 - SyncBase.__init__(self, "svn", "dev-vcs/subversion")
154 + NewBase.__init__(self, "svn", "dev-vcs/subversion")
155
156
157 def exists(self, **kwargs):
158 @@ -46,9 +46,9 @@ class SVNSync(SyncBase):
159 return (exitcode, False)
160
161
162 - def _sync(self):
163 + def update(self):
164 """
165 - Internal function to sync an existing SVN repository
166 + Internal function to update an existing SVN repository
167
168 @return: tuple of return code (0=success), whether the cache
169 needs to be updated
170 diff --git a/pym/portage/sync/modules/websync/websync.py b/pym/portage/sync/modules/websync/websync.py
171 index 0ad4efb..3576116 100644
172 --- a/pym/portage/sync/modules/websync/websync.py
173 +++ b/pym/portage/sync/modules/websync/websync.py
174 @@ -27,14 +27,14 @@ class WebRsync(SyncBase):
175 SyncBase.__init__(self, 'emerge-webrsync', '>=sys-apps/portage-2.3')
176
177
178 - def new(self, **kwargs):
179 - '''Do the initial download and install of the repository'''
180 - return self._sync()
181 + def sync(self, **kwargs):
182 + '''Sync the repository'''
183 + if kwargs:
184 + self._kwargs(kwargs)
185
186 + if not self.has_bin:
187 + return (1, False)
188
189 - def _sync(self):
190 - ''' Update existing repository
191 - '''
192 emerge_config = self.options.get('emerge_config', None)
193 portdb = self.options.get('portdb', None)
194
195 @@ -64,12 +64,7 @@ class PyWebRsync(SyncBase):
196 SyncBase.__init__(self, None, '>=sys-apps/portage-2.3')
197
198
199 - def new(self, **kwargs):
200 - '''Do the initial download and install of the repository'''
201 + def sync(self, **kwargs):
202 + '''Sync the repository'''
203 pass
204
205 -
206 - def _sync(self):
207 - ''' Update existing repository
208 - '''
209 - pass
210 diff --git a/pym/portage/sync/syncbase.py b/pym/portage/sync/syncbase.py
211 index 04db2d0..c820bcf 100644
212 --- a/pym/portage/sync/syncbase.py
213 +++ b/pym/portage/sync/syncbase.py
214 @@ -57,14 +57,13 @@ class SyncBase(object):
215 self.xterm_titles = self.options.get('xterm_titles', False)
216 self.spawn_kwargs = self.options.get('spawn_kwargs', None)
217
218 +
219 def exists(self, **kwargs):
220 '''Tests whether the repo actually exists'''
221 if kwargs:
222 self._kwargs(kwargs)
223 elif not self.repo:
224 return False
225 -
226 -
227 if not os.path.exists(self.repo.location):
228 return False
229 return True
230 @@ -72,26 +71,9 @@ class SyncBase(object):
231
232 def sync(self, **kwargs):
233 '''Sync the repository'''
234 - if kwargs:
235 - self._kwargs(kwargs)
236 -
237 - if not self.has_bin:
238 - return (1, False)
239 -
240 - if not self.exists():
241 - return self.new()
242 - return self._sync()
243 + raise NotImplementedError
244
245
246 - def new(self, **kwargs):
247 - '''Do the initial download and install of the repository'''
248 - pass
249 -
250 - def _sync(self):
251 - '''Update existing repository
252 - '''
253 - pass
254 -
255 def post_sync(self, portdb, location, emerge_config):
256 '''repo.sync_type == "Blank":
257 # NOTE: Do this after reloading the config, in case
258 @@ -100,6 +82,7 @@ class SyncBase(object):
259 '''
260 pass
261
262 +
263 def _get_submodule_paths(self):
264 paths = []
265 emerge_config = self.options.get('emerge_config')
266 @@ -107,3 +90,36 @@ class SyncBase(object):
267 for name in emerge_config.opts.get('--sync-submodule', []):
268 paths.append(_SUBMODULE_PATH_MAP[name])
269 return tuple(paths)
270 +
271 +
272 +class NewBase(SyncBase):
273 + '''Subclasses Syncbase adding a new() and runs it
274 + instead of update() if the repository does not exist()'''
275 +
276 +
277 + def __init__(self, bin_command, bin_pkg):
278 + SyncBase.__init__(self, bin_command, bin_pkg)
279 +
280 +
281 + def sync(self, **kwargs):
282 + '''Sync the repository'''
283 + if kwargs:
284 + self._kwargs(kwargs)
285 +
286 + if not self.has_bin:
287 + return (1, False)
288 +
289 + if not self.exists():
290 + return self.new()
291 + return self.update()
292 +
293 +
294 + def new(self, **kwargs):
295 + '''Do the initial download and install of the repository'''
296 + raise NotImplementedError
297 +
298 +
299 + def update(self):
300 + '''Update existing repository
301 + '''
302 + raise NotImplementedError
303 --
304 2.2.2

Replies