From dd28e90f183972cc2a395094ce3e3f72e861953f Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 21 Sep 2012 13:55:05 -0400 Subject: run pylint for errors on almost everything, full runs on some selected stuff --- src/lib/Bcfg2/Server/Plugins/Svn2.py | 114 ++++++++++++++++------------------- 1 file changed, 53 insertions(+), 61 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins/Svn2.py') diff --git a/src/lib/Bcfg2/Server/Plugins/Svn2.py b/src/lib/Bcfg2/Server/Plugins/Svn2.py index e4df9574f..110f2c2eb 100644 --- a/src/lib/Bcfg2/Server/Plugins/Svn2.py +++ b/src/lib/Bcfg2/Server/Plugins/Svn2.py @@ -1,41 +1,47 @@ +""" The Svn2 plugin provides a revision interface for Bcfg2 repos using +Subversion. It uses a pure python backend and exposes two additional +XML-RPC methods. """ + +import sys +import Bcfg2.Server.Plugin +# pylint: disable=F0401 try: import pysvn - missing = False -except: - missing = True -import Bcfg2.Server.Plugin + HAS_SVN = False +except ImportError: + HAS_SVN = True +# pylint: enable=F0401 + class Svn2(Bcfg2.Server.Plugin.Plugin, Bcfg2.Server.Plugin.Version): """Svn is a version plugin for dealing with Bcfg2 repos.""" - name = 'Svn2' __author__ = 'bcfg-dev@mcs.anl.gov' conflicts = ['Svn'] - experimental = True - __rmi__ = Bcfg2.Server.Plugin.Plugin.__rmi__ + ['Update','Commit'] + __rmi__ = Bcfg2.Server.Plugin.Plugin.__rmi__ + ['Update', 'Commit'] def __init__(self, core, datastore): Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) + Bcfg2.Server.Plugin.Version.__init__(self, datastore) - if missing: - self.logger.error("Svn2: Missing PySvn") - raise Bcfg2.Server.Plugin.PluginInitError + if HAS_SVN: + msg = "Missing PySvn" + self.logger.error("Svn2: " + msg) + raise Bcfg2.Server.Plugin.PluginInitError(msg) self.client = pysvn.Client() - self.core = core - self.datastore = datastore self.svn_root = None self.revision = None # Read revision from bcfg2 repo revision = self.get_revision() if not self.revision: - raise Bcfg2.Server.Plugin.PluginInitError + raise Bcfg2.Server.Plugin.PluginInitError("Failed to get revision") - self.logger.debug("Initialized svn plugin with svn root %s at revision %s" - % (self.svn_root, revision)) + 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.""" @@ -44,55 +50,18 @@ class Svn2(Bcfg2.Server.Plugin.Plugin, self.revision = info.revision self.svn_root = info.url return str(self.revision.number) - except: + except pysvn.ClientError: # pylint: disable=E1101 self.logger.error("Svn2: Failed to get revision", exc_info=1) self.revision = None return str(-1) - def commit_data(self, file_list, comment=None): - """Commit changes into the repository""" - if not comment: - comment = 'Svn2: autocommit' - - # First try to update - if not self.Update(): - self.logger.error("Failed to update svn repository, refusing to commit changes") - return - - #FIXME - look for conflicts? - - for fname in file_list: - stat = self.client.status(fname) - self.client.add([f.path for f in stat \ - if f.text_status == pysvn.wc_status_kind.unversioned]) - try: - self.revision = self.client.checkin([self.datastore], comment, - recurse=True) - self.revision = self.client.update(self.datastore, recurse=True)[0] - self.logger.info("Svn2: Commited changes. At %s" % - self.revision.number) - except Exception: - err = sys.exc_info()[1] - # try to be smart about the error we got back - details = None - if "callback_ssl_server_trust_prompt" in str(err): - details = "SVN server certificate is not trusted" - elif "callback_get_login" in str(err): - details = "SVN credentials not cached" - - if details is None: - self.logger.error("Svn2: Failed to commit changes", - exc_info=1) - else: - self.logger.error("Svn2: Failed to commit changes: %s" % - details) - def Update(self): '''Svn2.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 Exception, err: + except pysvn.ClientError: # pylint: disable=E1101 + err = sys.exc_info()[1] # try to be smart about the error we got back details = None if "callback_ssl_server_trust_prompt" in str(err): @@ -104,8 +73,8 @@ class Svn2(Bcfg2.Server.Plugin.Plugin, self.logger.error("Svn2: Failed to update server repository", exc_info=1) else: - self.logger.error("Svn2: Failed to update server repository: %s" % - details) + self.logger.error("Svn2: Failed to update server repository: " + "%s" % details) return False if old_revision == self.revision.number: @@ -117,10 +86,33 @@ class Svn2(Bcfg2.Server.Plugin.Plugin, def Commit(self): """Svn2.Commit() => True|False\nCommit svn repository\n""" - try: - self.commit_changes([]) - return True - except: + # First try to update + if not self.Update(): + self.logger.error("Failed to update svn repository, refusing to " + "commit changes") return False + try: + self.revision = self.client.checkin([self.datastore], + 'Svn2: autocommit', + recurse=True) + self.revision = self.client.update(self.datastore, recurse=True)[0] + self.logger.info("Svn2: Commited changes. At %s" % + self.revision.number) + return True + except pysvn.ClientError: # pylint: disable=E1101 + err = sys.exc_info()[1] + # try to be smart about the error we got back + details = None + if "callback_ssl_server_trust_prompt" in str(err): + details = "SVN server certificate is not trusted" + elif "callback_get_login" in str(err): + details = "SVN credentials not cached" + if details is None: + self.logger.error("Svn2: Failed to commit changes", + exc_info=1) + else: + self.logger.error("Svn2: Failed to commit changes: %s" % + details) + return False -- cgit v1.2.3-1-g7c22