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