changeset 56:8b9816c1b322

Ability to remove a repository plug-in. IN: -
author John Schneiderman
date Tue, 10 Mar 2015 19:43:21 +0100
parents 3a0242e260ab
children d9170c4ce812
files doc/ChangeLog doc/TODO src/hwm.py src/manager.py src/manrepo.py
diffstat 5 files changed, 47 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Tue Mar 10 19:24:23 2015 +0100
+++ b/doc/ChangeLog	Tue Mar 10 19:43:21 2015 +0100
@@ -19,6 +19,7 @@
 ********************************************************************************
 2015-00-00 John Schneiderman <Licensing _AT_ CodeGNU _DOT_ com> 0.4.0
 - Ability to add a plug-in to a managed repository.
+- Ability to remove a plug-in from a managed repository.
 - No longer dependant upon third-party general file locker for repositories.
 - Manager functions use exceptions for error handling.
 2014-08-21 John Schneiderman <Licensing _AT_ CodeGNU _DOT_ com> 0.3.0
--- a/doc/TODO	Tue Mar 10 19:24:23 2015 +0100
+++ b/doc/TODO	Tue Mar 10 19:43:21 2015 +0100
@@ -27,7 +27,6 @@
 ***                                                                          ***
 ***                              Feature Goals                               ***
 ***                                                                          ***
-- Allow plug-ins removal from repositories.
 - Installation tutorial.
 - User tutorials.
 - Manager functions should take both an output and error device instead of defaulting to std.
--- a/src/hwm.py	Tue Mar 10 19:24:23 2015 +0100
+++ b/src/hwm.py	Tue Mar 10 19:43:21 2015 +0100
@@ -98,8 +98,9 @@
 		parser.add_argument('-l', '--list', action='store_true', help='Outputs a list of all the managed repositories.')
 
 		plgInGrp = parser.add_argument_group('Manage Plug-Ins', 'Options that operate upon managed repository\'s plug-ins.')
-		plgInGrp.add_argument('-e', '--enable-plugin', action='store', nargs=1, type=str, default=None, help='Enable a plug-in in a repository.')
+		plgInGrp.add_argument('-e', '--enable-plugin', action='store', nargs='?', type=str, default=None, help='Enable a plug-in in a repository.')
 		plgInGrp.add_argument('-f', '--plugin-file', action='store', nargs='?', type=str, default=None, help='The path to the plug-in script.')
+		plgInGrp.add_argument('-x', '--disable-plugin', action='store', nargs='?', type=str, default=None, help='Disable a plug-in in a repository.')
 
 		manGrp = parser.add_argument_group('Manage Repositories', 'Options that operate upon managed repositories.')
 		manGrp.add_argument('storage', action='store', nargs='?', help='The storage-name of the repository to perform an action upon.')
@@ -118,7 +119,9 @@
 		if args.list:
 			manager.list()
 		elif args.enable_plugin is not None:
-			manager.plugInEnable(repo, args.enable_plugin[0], args.plugin_file)
+			manager.plugInEnable(repo, args.enable_plugin, args.plugin_file)
+		elif args.disable_plugin is not None:
+			manager.plugInDisable(repo, args.disable_plugin)
 		elif args.action is None:
 			print >>sys.stderr, "No actionable arguments supplied."
 			exit(1)
--- a/src/manager.py	Tue Mar 10 19:24:23 2015 +0100
+++ b/src/manager.py	Tue Mar 10 19:43:21 2015 +0100
@@ -35,8 +35,8 @@
 	@param[in] plugInName		The name of the plug-in to add.
 	@param[in] scriptFile		The file path location of the plug-in script.
 
-	@post The managed repository has it's configuration file enabling the
-	supplied plug-in.
+	@post The managed repository has it's configuration file changed which
+	enables the supplied plug-in.
 
 	@throws ValueError		When the repository storage name does not exist.
 	"""
@@ -53,6 +53,29 @@
 		__writeRepositoryDetails(repository)
 
 
+def plugInDisable(repository, named):
+	""" Disables a plug-in to a managed repository.
+
+	@pre The repository must already exist.
+
+	@param[in] repository		The targeted repository to remove a plug-in from.
+	@param[in] named			The name of the plug-in to remove.
+
+	@post The managed repository has it's configuration file changed which
+	disables the supplied plug-in.
+
+	@throws ValueError		When the repository storage name does not exist.
+	"""
+	with RepositoryManagerLock():
+		print "\tDisable plug-in %s for %s" % (named, repository.StorageName)
+		if not __doesRepositoryStorageNameExist(repository):
+			raise ValueError("The repository '%s' does not exist." % repository.StorageName)
+
+		print 'Removing plug-in information ...'
+		repository.removePlugIn(named)
+		__writeRepositoryDetails(repository)
+
+
 def create(repository, ignoreGroups, skipCommon):
 	""" Creates a new repository under HgWeb.
 
--- a/src/manrepo.py	Tue Mar 10 19:24:23 2015 +0100
+++ b/src/manrepo.py	Tue Mar 10 19:43:21 2015 +0100
@@ -154,7 +154,7 @@
 		return repo
 
 	def addPlugIn(self, plugIn):
-		""" Adds a plug-in to enable in a repository.
+		""" Makes a plug-in in a repository enabled.
 
 		@param[in] plugIn	The plug-in that is to be enabled.
 
@@ -167,6 +167,21 @@
 		else:
 			raise ValueError("The plug-in '%s' is already enabled." % plugIn.name)
 
+	def removePlugIn(self, named):
+		""" Makes a plug-in in a repository disabled.
+
+		@param[in] named	The name of the plug-in that is to be disabled.
+
+		@post The object no longer has the supplied plug-in as being enabled.
+
+		@throws ValueError		When the supplied plug-in is already disabled.
+		"""
+		for plugIn in self.PlugIns:
+			if named == plugIn.name:
+				self.__plugIns.remove(plugIn)
+				return
+		raise ValueError("The plug-in '%s' is already disabled." % named)
+
 
 class RepositoryPlugin(object):
 	__name = None