summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Laszlo <tim.laszlo@gmail.com>2010-12-17 17:12:31 -0600
committerTim Laszlo <tim.laszlo@gmail.com>2010-12-18 09:13:28 -0600
commitb84ae0fc40cdbd5b7062c3dff8f649cc0561268c (patch)
tree206813ac58ee524754277fad5781057b0addf8fe
parentf3b9c4992c8043187d122ae097d55f87017754f3 (diff)
downloadbcfg2-b84ae0fc40cdbd5b7062c3dff8f649cc0561268c.tar.gz
bcfg2-b84ae0fc40cdbd5b7062c3dff8f649cc0561268c.tar.bz2
bcfg2-b84ae0fc40cdbd5b7062c3dff8f649cc0561268c.zip
Svn2: Native svn plugin
-rw-r--r--src/lib/Server/Plugins/Svn2.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/lib/Server/Plugins/Svn2.py b/src/lib/Server/Plugins/Svn2.py
new file mode 100644
index 000000000..89b36b89f
--- /dev/null
+++ b/src/lib/Server/Plugins/Svn2.py
@@ -0,0 +1,71 @@
+import os
+try:
+ import pysvn
+ missing = False
+except:
+ missing = True
+import Bcfg2.Server.Plugin
+
+# FIXME
+REPOS_URL = 'file:///space/svn/admin'
+
+class Svn2(Bcfg2.Server.Plugin.Plugin,
+ Bcfg2.Server.Plugin.Version):
+ """Svn is a version plugin for dealing with Bcfg2 repos."""
+ name = 'Svn2'
+ __version__ = '$Id$'
+ __author__ = 'bcfg-dev@mcs.anl.gov'
+
+ conflicts = ['Svn']
+ experimental = True
+ __rmi__ = Bcfg2.Server.Plugin.Plugin.__rmi__ + ['Update']
+
+ def __init__(self, core, datastore):
+ Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore)
+
+ if missing:
+ self.logger.error("Svn2: Missing PySvn")
+ raise Bcfg2.Server.Plugin.PluginInitError
+
+ self.client = pysvn.Client()
+
+ self.core = core
+ self.datastore = datastore
+ self.svn_root = REPOS_URL
+ self.revision = None
+
+ # Read revision from bcfg2 repo
+ revision = self.get_revision()
+ if not self.revision:
+ raise Bcfg2.Server.Plugin.PluginInitError
+
+ self.logger.debug("Initialized svn plugin with svn root %s at revision %s" \
+ % (self.svn_root, revision))
+
+ def get_revision(self):
+ """Read svn revision information for the Bcfg2 repository."""
+ try:
+ info = self.client.info(self.datastore)
+ self.revision = info.revision
+ return str(self.revision.number)
+ except:
+ self.logger.error("Svn2: Failed to get revision", exc_info=1)
+ self.revision = None
+ return str(-1)
+
+ def Update(self):
+ '''NatvieSvn.Update() => True|False\nUpdate svn working copy\n'''
+ try:
+ old_revision = self.revision.number
+ self.revision = self.client.update(self.datastore, recurse=True)[0]
+ except:
+ self.logger.error("Svn2: Failed to update server repository", exc_info=1)
+ return False
+
+ if old_revision == self.revision.number:
+ self.logger.debug("repository is current")
+ else:
+ self.logger.info("Updated %s from revision %s to %s" % \
+ (self.datastore, old_revision, self.revision.number))
+ return True
+