commit: 7fa105b7153c20d63acfd4250764adb86985e8e1
Author: Chris Reffett <creffett <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 11 17:27:27 2014 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Wed Apr 30 07:38:46 2014 +0000
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=7fa105b7
Bring CVS module up to current module spec
Add exists(), new(), _sync() as in the git and rsync classes. Clean up
output style to use logger and writemsg_level instead of straight print
statements
---
pym/portage/sync/modules/cvs/__init__.py | 19 +++--
pym/portage/sync/modules/cvs/cvs.py | 119 ++++++++++++++++++++++---------
2 files changed, 99 insertions(+), 39 deletions(-)
diff --git a/pym/portage/sync/modules/cvs/__init__.py
b/pym/portage/sync/modules/cvs/__init__.py
index 56f6902..7e786c0 100644
--- a/pym/portage/sync/modules/cvs/__init__.py
+++ b/pym/portage/sync/modules/cvs/__init__.py
@@ -14,10 +14,21 @@ module_spec = {
'name': "cvs",
'class': "CVSSync",
'description': __doc__,
- 'functions': ['sync',],
+ 'functions': ['sync', 'new', 'exists'],
'func_desc': {
- 'sync', 'Performs a cvs up on the repository',
- }
- }
+ 'sync': 'Performs a cvs up on the repository',
+ 'new': 'Creates the new repository at the
specified location',
+ 'exists': 'Returns a boolean of whether the
specified dir ' +
+ 'exists and is a valid CVS repository',
+ },
+ 'func_parameters': {
+ 'kwargs': {
+ 'type': dict,
+ 'description': 'Standard python
**kwargs parameter format' +
+ 'Please refer to the sync
modules specs at ' +
+
'"https://wiki.gentoo.org:Project:Portage" for details',
+ },
+ },
}
}
+}
diff --git a/pym/portage/sync/modules/cvs/cvs.py
b/pym/portage/sync/modules/cvs/cvs.py
index 69edac4..dadbf7b 100644
--- a/pym/portage/sync/modules/cvs/cvs.py
+++ b/pym/portage/sync/modules/cvs/cvs.py
@@ -13,7 +13,7 @@ from portage.util import writemsg_level
class CVSSync(object):
'''CVS sync module'''
- short_desc = "Perform sync operations on rsync based repositories"
+ short_desc = "Perform sync operations on CVS repositories"
@staticmethod
def name():
@@ -26,52 +26,101 @@ class CVSSync(object):
def __init__(self):
self.settings = None
+ self.options = None
+ self.logger = None
+ self.xterm_titles = None
+ self.has_cvs = True
+ if portage.process.find_binary("cvs") is None:
+ msg = "Command not found: cvs"
+ "Type \"emerge %s\" to enable CVS support." %
portage.const.CVS_PACKAGE_ATOM
+ for l in msg:
+ writemsg_level("!!! %s\n" % l,
+ level=logging.ERROR, noiselevel=-1)
+ self.has_cvs = False
+
+ def _kwargs(self, **kwargs):
+ self.options = kwargs.get('options', {})
+ self.repo = self.options.get('repo', None)
+ self.logger = self.options.get('logger', None)
+ self.xterm_titles = self.options.get('xterm_titles', None)
+
+
+ def exists(self, **kwargs):
+ if kwargs:
+ self._kwargs(kwargs)
+ elif not self.repo:
+ return False
+ spawn_kwargs = self.options.get('spawn_kwargs', None)
+
+ if not os.path.exists(os.path.join(repo.location, "CVS")):
+ return False
+ return True
def sync(self, **kwargs):
- '''repo.sync_type == "cvs":'''
+ if kwargs:
+ self._kwargs(kwargs)
- if not os.path.exists("/usr/bin/cvs"):
- print("!!! /usr/bin/cvs does not exist, so CVS support
is disabled.")
- print("!!! Type \"emerge %s\" to enable CVS support." %
portage.const.CVS_PACKAGE_ATOM)
- return os.EX_UNAVAILABLE, False
+ if not self.has_cvs:
+ return (1, False)
+ if not self.exists():
+ return self.new()
+ return self.sync()
+
+
+ def new(self, **kwargs):
if kwargs:
- options = kwargs.get('options', {})
- repo = options.get('repo', None)
- spawn_kwargs = options.get('spawn_kwargs', None)
+ self._kwargs(kwargs)
+ #initial checkout
+ msg = ">>> Starting initial cvs checkout with %s..." %
self.repo.sync_uri
+ self.logger(self.xterm_titles, msg)
+ writemsg_level(msg + "\n")
+ try:
+ os.rmdir(self.repo.location)
+ except OSError as e:
+ if e.errno != errno.ENOENT:
+ msg = "!!! existing '%s' directory; exiting." %
self.repo.location
+ self.logger(self.xterm_titles, msg)
+ writemsg_level(msg + "\n", noiselevel=-1,
level=logging.ERROR)
+ return (1, False)
+ del e
+ if portage.process.spawn_bash(
+ "cd %s; exec cvs -z0 -d %s co -P -d %s %s" %
+
(portage._shell_quote(os.path.dirname(self.repo.location)),
portage._shell_quote(cvs_root),
+
portage._shell_quote(os.path.basename(self.repo.location)),
+ portage._shell_quote(self.repo.sync_cvs_repo)),
+ **portage._native_kwargs(spawn_kwargs)) !=
os.EX_OK:
+ msg = "!!! cvs checkout error; exiting."
+ self.logger(self.xterm_titles, msg)
+ writemsg_level(msg + "\n", noiselevel=-1,
level=logging.ERROR)
+ return (1, False)
+ return (0, False)
+
+ def _sync(self):
+ """
+ Internal function to sync an existing CVS repository
+
+ @return: tuple of return code (0=success), whether the cache
+ needs to be updated
+ @rtype: (int, bool)
+ """
+
+ spawn_kwargs = options.get('spawn_kwargs', None)
+ cvs_root = self.repo.sync_uri
- cvs_root = repo.sync_uri
if cvs_root.startswith("cvs://"):
cvs_root = cvs_root[6:]
- if not os.path.exists(os.path.join(repo.location, "CVS")):
- #initial checkout
- print(">>> Starting initial cvs checkout with
"+repo.sync_uri+"...")
- try:
- os.rmdir(repo.location)
- except OSError as e:
- if e.errno != errno.ENOENT:
- sys.stderr.write(
- "!!! existing '%s' directory;
exiting.\n" % repo.location)
- exitcode = 1
- return (exitcode, False)
- del e
- if portage.process.spawn_bash(
- "cd %s; exec cvs -z0 -d %s co -P -d %s
%s" %
-
(portage._shell_quote(os.path.dirname(repo.location)),
portage._shell_quote(cvs_root),
-
portage._shell_quote(os.path.basename(repo.location)),
portage._shell_quote(repo.sync_cvs_repo)),
- **portage._native_kwargs(spawn_kwargs))
!= os.EX_OK:
- print("!!! cvs checkout error; exiting.")
- exitcode = 1
- else:
#cvs update
- print(">>> Starting cvs update with
"+repo.sync_uri+"...")
+ msg = ">>> Starting cvs update with %s..." %
self.repo.sync_uri
+ self.logger(self.xterm_titles, msg)
+ writemsg_level(msg + "\n")
exitcode = portage.process.spawn_bash(
"cd %s; exec cvs -z0 -q update -dP" % \
- (portage._shell_quote(repo.location),),
+ (portage._shell_quote(self.repo.location),),
**portage._native_kwargs(spawn_kwargs))
if exitcode != os.EX_OK:
- writemsg_level("!!! cvs update error;
exiting.\n",
- noiselevel=-1, level=logging.ERROR)
+ msg = "!!! cvs update error; exiting."
+ self.logger(self.xterm_titles, msg)
+ writemsg_level(msg + "\n", noiselevel=-1,
level=logging.ERROR)
return (exitcode, False)
-