public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: pym/portage/sync/modules/websync/, pym/portage/sync/modules/git/, ...
@ 2015-01-30 20:06 Brian Dolbec
  0 siblings, 0 replies; only message in thread
From: Brian Dolbec @ 2015-01-30 20:06 UTC (permalink / raw
  To: gentoo-commits

commit:     21159f5d367831e7c07aa78a562c5f28cff947c9
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jan 24 19:13:01 2015 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Jan 30 19:58:12 2015 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=21159f5d

portage/sync: Break out a NewBase class from SyncBase

From mgorny's suggestion, rename _sync() to update().
Raise NotImplementedError in base classes.
Directly override sync() in websync module.
Fix up line spacing to be consistent.

---
 pym/portage/sync/modules/cvs/cvs.py         | 10 +++---
 pym/portage/sync/modules/git/git.py         |  8 ++---
 pym/portage/sync/modules/rsync/rsync.py     | 12 +++----
 pym/portage/sync/modules/svn/svn.py         | 10 +++---
 pym/portage/sync/modules/websync/websync.py | 21 +++++------
 pym/portage/sync/syncbase.py                | 56 ++++++++++++++++++-----------
 6 files changed, 64 insertions(+), 53 deletions(-)

diff --git a/pym/portage/sync/modules/cvs/cvs.py b/pym/portage/sync/modules/cvs/cvs.py
index 919cb34..9153815 100644
--- a/pym/portage/sync/modules/cvs/cvs.py
+++ b/pym/portage/sync/modules/cvs/cvs.py
@@ -7,10 +7,10 @@ import errno
 import portage
 from portage import os
 from portage.util import writemsg_level
-from portage.sync.syncbase import SyncBase
+from portage.sync.syncbase import NewBase
 
 
-class CVSSync(SyncBase):
+class CVSSync(NewBase):
 	'''CVS sync module'''
 
 	short_desc = "Perform sync operations on CVS repositories"
@@ -21,7 +21,7 @@ class CVSSync(SyncBase):
 
 
 	def __init__(self):
-		SyncBase.__init__(self, "cvs", portage.const.CVS_PACKAGE_ATOM)
+		NewBase.__init__(self, "cvs", portage.const.CVS_PACKAGE_ATOM)
 
 
 	def exists(self, **kwargs):
@@ -47,9 +47,9 @@ class CVSSync(SyncBase):
 		return (0, False)
 
 
-	def _sync(self):
+	def update(self):
 		"""
-		Internal function to sync an existing CVS repository
+		Internal function to update an existing CVS repository
 
 		@return: tuple of return code (0=success), whether the cache
 			needs to be updated

diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
index 3acfc2a..cea681c 100644
--- a/pym/portage/sync/modules/git/git.py
+++ b/pym/portage/sync/modules/git/git.py
@@ -10,10 +10,10 @@ from portage.output import create_color_func
 good = create_color_func("GOOD")
 bad = create_color_func("BAD")
 warn = create_color_func("WARN")
-from portage.sync.syncbase import SyncBase
+from portage.sync.syncbase import NewBase
 
 
-class GitSync(SyncBase):
+class GitSync(NewBase):
 	'''Git sync class'''
 
 	short_desc = "Perform sync operations on git based repositories"
@@ -24,7 +24,7 @@ class GitSync(SyncBase):
 
 
 	def __init__(self):
-		SyncBase.__init__(self, "git", portage.const.GIT_PACKAGE_ATOM)
+		NewBase.__init__(self, "git", portage.const.GIT_PACKAGE_ATOM)
 
 
 	def exists(self, **kwargs):
@@ -67,7 +67,7 @@ class GitSync(SyncBase):
 		return (os.EX_OK, True)
 
 
-	def _sync(self):
+	def update(self):
 		''' Update existing git repository, and ignore the syncuri. We are
 		going to trust the user and assume that the user is in the branch
 		that he/she wants updated. We'll let the user manage branches with

diff --git a/pym/portage/sync/modules/rsync/rsync.py b/pym/portage/sync/modules/rsync/rsync.py
index 52d8b0f..817164d 100644
--- a/pym/portage/sync/modules/rsync/rsync.py
+++ b/pym/portage/sync/modules/rsync/rsync.py
@@ -21,14 +21,14 @@ from portage.const import VCS_DIRS, TIMESTAMP_FORMAT, RSYNC_PACKAGE_ATOM
 from portage.util import writemsg, writemsg_stdout
 from portage.sync.getaddrinfo_validate import getaddrinfo_validate
 from _emerge.UserQuery import UserQuery
-from portage.sync.syncbase import SyncBase
+from portage.sync.syncbase import NewBase
 
 
 SERVER_OUT_OF_DATE = -1
 EXCEEDED_MAX_RETRIES = -2
 
 
-class RsyncSync(SyncBase):
+class RsyncSync(NewBase):
 	'''Rsync sync module'''
 
 	short_desc = "Perform sync operations on rsync based repositories"
@@ -39,11 +39,11 @@ class RsyncSync(SyncBase):
 
 
 	def __init__(self):
-		SyncBase.__init__(self, "rsync", RSYNC_PACKAGE_ATOM)
+		NewBase.__init__(self, "rsync", RSYNC_PACKAGE_ATOM)
 
 
-	def _sync(self):
-		'''Internal sync function which performs only the sync'''
+	def update(self):
+		'''Internal update function which performs the transfer'''
 		opts = self.options.get('emerge_config').opts
 		self.usersync_uid = self.options.get('usersync_uid', None)
 		enter_invalid = '--ask-enter-invalid' in opts
@@ -287,7 +287,7 @@ class RsyncSync(SyncBase):
 					'Created New Directory %s ' % self.repo.location )
 		except IOError:
 			return (1, False)
-		return self._sync()
+		return self.update()
 
 
 	def _set_rsync_defaults(self):

diff --git a/pym/portage/sync/modules/svn/svn.py b/pym/portage/sync/modules/svn/svn.py
index 60ead4b..492ada3 100644
--- a/pym/portage/sync/modules/svn/svn.py
+++ b/pym/portage/sync/modules/svn/svn.py
@@ -7,10 +7,10 @@ import errno
 import portage
 from portage import os
 from portage.util import writemsg_level
-from portage.sync.syncbase import SyncBase
+from portage.sync.syncbase import NewBase
 
 
-class SVNSync(SyncBase):
+class SVNSync(NewBase):
 	'''SVN sync module'''
 
 	short_desc = "Perform sync operations on SVN repositories"
@@ -21,7 +21,7 @@ class SVNSync(SyncBase):
 
 
 	def __init__(self):
-		SyncBase.__init__(self, "svn", "dev-vcs/subversion")
+		NewBase.__init__(self, "svn", "dev-vcs/subversion")
 
 
 	def exists(self, **kwargs):
@@ -46,9 +46,9 @@ class SVNSync(SyncBase):
 		return (exitcode, False)
 
 
-	def _sync(self):
+	def update(self):
 		"""
-		Internal function to sync an existing SVN repository
+		Internal function to update an existing SVN repository
 
 		@return: tuple of return code (0=success), whether the cache
 			needs to be updated

diff --git a/pym/portage/sync/modules/websync/websync.py b/pym/portage/sync/modules/websync/websync.py
index 0ad4efb..3576116 100644
--- a/pym/portage/sync/modules/websync/websync.py
+++ b/pym/portage/sync/modules/websync/websync.py
@@ -27,14 +27,14 @@ class WebRsync(SyncBase):
 		SyncBase.__init__(self, 'emerge-webrsync', '>=sys-apps/portage-2.3')
 
 
-	def new(self, **kwargs):
-		'''Do the initial download and install of the repository'''
-		return self._sync()
+	def sync(self, **kwargs):
+		'''Sync the repository'''
+		if kwargs:
+			self._kwargs(kwargs)
 
+		if not self.has_bin:
+			return (1, False)
 
-	def _sync(self):
-		''' Update existing repository
-		'''
 		emerge_config = self.options.get('emerge_config', None)
 		portdb = self.options.get('portdb', None)
 
@@ -64,12 +64,7 @@ class PyWebRsync(SyncBase):
 		SyncBase.__init__(self, None, '>=sys-apps/portage-2.3')
 
 
-	def new(self, **kwargs):
-		'''Do the initial download and install of the repository'''
+	def sync(self, **kwargs):
+		'''Sync the repository'''
 		pass
 
-
-	def _sync(self):
-		''' Update existing repository
-		'''
-		pass

diff --git a/pym/portage/sync/syncbase.py b/pym/portage/sync/syncbase.py
index 04db2d0..c820bcf 100644
--- a/pym/portage/sync/syncbase.py
+++ b/pym/portage/sync/syncbase.py
@@ -57,14 +57,13 @@ class SyncBase(object):
 		self.xterm_titles = self.options.get('xterm_titles', False)
 		self.spawn_kwargs = self.options.get('spawn_kwargs', None)
 
+
 	def exists(self, **kwargs):
 		'''Tests whether the repo actually exists'''
 		if kwargs:
 			self._kwargs(kwargs)
 		elif not self.repo:
 			return False
-
-
 		if not os.path.exists(self.repo.location):
 			return False
 		return True
@@ -72,26 +71,9 @@ class SyncBase(object):
 
 	def sync(self, **kwargs):
 		'''Sync the repository'''
-		if kwargs:
-			self._kwargs(kwargs)
-
-		if not self.has_bin:
-			return (1, False)
-
-		if not self.exists():
-			return self.new()
-		return self._sync()
+		raise NotImplementedError
 
 
-	def new(self, **kwargs):
-		'''Do the initial download and install of the repository'''
-		pass
-
-	def _sync(self):
-		'''Update existing repository
-		'''
-		pass
-
 	def post_sync(self, portdb, location, emerge_config):
 		'''repo.sync_type == "Blank":
 		# NOTE: Do this after reloading the config, in case
@@ -100,6 +82,7 @@ class SyncBase(object):
 		'''
 		pass
 
+
 	def _get_submodule_paths(self):
 		paths = []
 		emerge_config = self.options.get('emerge_config')
@@ -107,3 +90,36 @@ class SyncBase(object):
 			for name in emerge_config.opts.get('--sync-submodule', []):
 				paths.append(_SUBMODULE_PATH_MAP[name])
 		return tuple(paths)
+
+
+class NewBase(SyncBase):
+	'''Subclasses Syncbase adding a new() and runs it
+	instead of update() if the repository does not exist()'''
+
+
+	def __init__(self, bin_command, bin_pkg):
+		SyncBase.__init__(self, bin_command, bin_pkg)
+
+
+	def sync(self, **kwargs):
+		'''Sync the repository'''
+		if kwargs:
+			self._kwargs(kwargs)
+
+		if not self.has_bin:
+			return (1, False)
+
+		if not self.exists():
+			return self.new()
+		return self.update()
+
+
+	def new(self, **kwargs):
+		'''Do the initial download and install of the repository'''
+		raise NotImplementedError
+
+
+	def update(self):
+		'''Update existing repository
+		'''
+		raise NotImplementedError


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-01-30 20:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-30 20:06 [gentoo-commits] proj/portage:master commit in: pym/portage/sync/modules/websync/, pym/portage/sync/modules/git/, Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox