aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/portage/sync/modules/svn')
-rw-r--r--lib/portage/sync/modules/svn/__init__.py33
-rw-r--r--lib/portage/sync/modules/svn/svn.py89
2 files changed, 122 insertions, 0 deletions
diff --git a/lib/portage/sync/modules/svn/__init__.py b/lib/portage/sync/modules/svn/__init__.py
new file mode 100644
index 000000000..c7ae3b87c
--- /dev/null
+++ b/lib/portage/sync/modules/svn/__init__.py
@@ -0,0 +1,33 @@
+# Copyright 2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """SVN plug-in module for portage.
+Performs a svn up on repositories."""
+__doc__ = doc[:]
+
+from portage.localization import _
+from portage.sync.config_checks import CheckSyncConfig
+from portage.util import writemsg_level
+
+
+module_spec = {
+ 'name': 'svn',
+ 'description': doc,
+ 'provides':{
+ 'svn-module': {
+ 'name': "svn",
+ 'sourcefile': "svn",
+ 'class': "SVNSync",
+ 'description': doc,
+ 'functions': ['sync', 'new', 'exists'],
+ 'func_desc': {
+ 'sync': 'Performs a svn 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 SVN repository',
+ },
+ 'validate_config': CheckSyncConfig,
+ 'module_specific_options': (),
+ }
+ }
+}
diff --git a/lib/portage/sync/modules/svn/svn.py b/lib/portage/sync/modules/svn/svn.py
new file mode 100644
index 000000000..723beedcb
--- /dev/null
+++ b/lib/portage/sync/modules/svn/svn.py
@@ -0,0 +1,89 @@
+# Copyright 1999-2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import logging
+
+import portage
+from portage import os
+from portage.util import writemsg_level
+from portage.sync.syncbase import NewBase
+
+
+class SVNSync(NewBase):
+ '''SVN sync module'''
+
+ short_desc = "Perform sync operations on SVN repositories"
+
+ @staticmethod
+ def name():
+ return "SVNSync"
+
+
+ def __init__(self):
+ NewBase.__init__(self, "svn", "dev-vcs/subversion")
+
+
+ def exists(self, **kwargs):
+ '''Tests whether the repo actually exists'''
+ return os.path.exists(os.path.join(self.repo.location, '.svn'))
+
+
+ def new(self, **kwargs):
+ if kwargs:
+ self._kwargs(kwargs)
+ #initial checkout
+ svn_root = self.repo.sync_uri
+ exitcode = portage.process.spawn_bash(
+ "cd %s; exec svn co %s ." %
+ (portage._shell_quote(self.repo.location),
+ portage._shell_quote(svn_root)),
+ **self.spawn_kwargs)
+ if exitcode != os.EX_OK:
+ msg = "!!! svn checkout error; exiting."
+ self.logger(self.xterm_titles, msg)
+ writemsg_level(msg + "\n", noiselevel=-1, level=logging.ERROR)
+ return (exitcode, False)
+
+
+ def update(self):
+ """
+ Internal function to update an existing SVN repository
+
+ @return: tuple of return code (0=success), whether the cache
+ needs to be updated
+ @rtype: (int, bool)
+ """
+
+ exitcode = self._svn_upgrade()
+ if exitcode != os.EX_OK:
+ return (exitcode, False)
+
+ #svn update
+ exitcode = portage.process.spawn_bash(
+ "cd %s; exec svn update" % \
+ (portage._shell_quote(self.repo.location),),
+ **self.spawn_kwargs)
+ if exitcode != os.EX_OK:
+ msg = "!!! svn update error; exiting."
+ self.logger(self.xterm_titles, msg)
+ writemsg_level(msg + "\n", noiselevel=-1, level=logging.ERROR)
+ return (exitcode, False)
+
+
+ def _svn_upgrade(self):
+ """
+ Internal function which performs an svn upgrade on the repo
+
+ @return: tuple of return code (0=success), whether the cache
+ needs to be updated
+ @rtype: (int, bool)
+ """
+ exitcode = portage.process.spawn_bash(
+ "cd %s; exec svn upgrade" %
+ (portage._shell_quote(self.repo.location),),
+ **self.spawn_kwargs)
+ if exitcode != os.EX_OK:
+ msg = "!!! svn upgrade error; exiting."
+ self.logger(self.xterm_titles, msg)
+ writemsg_level(msg + "\n", noiselevel=-1, level=logging.ERROR)
+ return exitcode