changeset 48:a6bce56dfaad

Verifies that a specified ignore group is in the ignore list. IN: -
author John Schneiderman <JohnMS@CodeGNU.com>
date Thu, 21 Aug 2014 18:42:17 -0500
parents ca60d20eb3c8
children 4e1ed60b2643
files src/manager.py
diffstat 1 files changed, 24 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/manager.py	Thu Aug 21 18:33:00 2014 -0500
+++ b/src/manager.py	Thu Aug 21 18:42:17 2014 -0500
@@ -25,13 +25,13 @@
 from hwm import settings
 
 
-def create(repository, ignoreGroup, skipCommon):
+def create(repository, ignoreGroups, skipCommon):
 	""" Creates a new repository under HgWeb.
 
 	 @pre The repository to create cannot already exist.
 
 	 @param[in] repository	The targeted repository to create.
-	 @param[in] ignoreGroup	The list of all ignore groups to add.
+	 @param[in] ignoreGroups	The list of all ignore groups to add.
 	 @param[in] skipCommon	A flag that when true indicates the common group
 						 should not be added by default.
 
@@ -62,7 +62,7 @@
 		# Create the requested repository.
 		if __addRepository(repository):
 			print "Initialised repository directory."
-			if not __create_ignores(repository, ignoreGroup, skipCommon):
+			if not __create_ignores(repository, ignoreGroups, skipCommon):
 				__removeRepository(repository)
 				return False
 		else:
@@ -117,7 +117,7 @@
 			print >>sys.stderr, "Failed to register repository."
 			return False
 
-def modify(newRepository, currentStorageName, ignoreGroup, skipCommon):
+def modify(newRepository, currentStorageName, ignoreGroups, skipCommon):
 	""" Changes an existing repository in HgWeb.
 
 	 @pre The repository to modify must already exist.
@@ -126,7 +126,7 @@
 								 modify.
 	 @param[in] currentStorageName	The current storage name of the
 								 repository to modify.
-	 @param[in] ignoreGroup			The list of all ignore groups to add.
+	 @param[in] ignoreGroups			The list of all ignore groups to add.
 	 @param[in] skipCommon			A flag that when true indicates the
 								 common group should not be added by
 								 default.
@@ -184,8 +184,8 @@
 			return False
 
 		# Update ignore file if requested.
-		if ignoreGroup is not None:
-			if __create_ignores(newRepository, ignoreGroup, skipCommon):
+		if ignoreGroups is not None:
+			if __create_ignores(newRepository, ignoreGroups, skipCommon):
 				print "Successfully modified ignore file."
 			else:
 				print >>sys.stderr, "Failed to modify ignore file."
@@ -259,7 +259,7 @@
 
 
 
-def __create_ignores(repo, ignoreGroup, skipCommon):
+def __create_ignores(repo, ignoreGroups, skipCommon):
 	""" Generates and commits an ignore file to an existing repository.
 
 	 @pre The repository to create an ignore file must already exist. The list
@@ -267,7 +267,7 @@
 	  "ignores.xml" and be in the hwm-ignore schema.
 
 	 @param[in] repo		The targeted repository for the ignore file.
-	 @param[in] ignoreGroup	The list of all ignore groups to add.
+	 @param[in] ignoreGroups	The list of all ignore groups to add.
 	 @param[in] skipCommon	A flag that when true indicates the common group
 						 should not be added by default.
 
@@ -282,8 +282,8 @@
 	import xml
 
 	# Extract Ignore Collection
-	if ignoreGroup is None:
-		ignoreGroup = []
+	if ignoreGroups is None:
+		ignoreGroups = []
 	ignores = {}
 	try:
 		ignores = ignorepo.extract('ignores.xml')
@@ -296,8 +296,14 @@
 
 	if skipCommon:
 		del ignores['Common']
-	elif not 'common' in [ignoreName.lower() for ignoreName in ignoreGroup]:
-		ignoreGroup.append('Common')
+	elif not 'common' in [ignoreGroup.lower() for ignoreGroup in ignoreGroups]:
+		ignoreGroups.append('Common')
+
+	if not '+' in ignoreGroups:
+		for ignoreGroup in ignoreGroups:
+			if not ignoreGroup.lower() in [ignore.lower() for ignore in ignores]:
+				print >>sys.stderr, "The list of ignores does not have the '%s' group." % ignoreGroup
+				return False
 
 	ignoreFile = settings.RepositoryPath + os.sep + repo.StorageName + os.sep + '.hgignore'
 	wasCreated = not os.path.isfile(ignoreFile)
@@ -308,14 +314,14 @@
 
 	# Write Ignore File
 	with open(ignoreFile, 'w') as hgIgnore:
-		for group,patterns in ignores.items():
-			if not '+' in ignoreGroup and not group.lower() in [ignoreName.lower() for ignoreName in ignoreGroup]:
+		for groupName,groupPatterns in ignores.items():
+			if not '+' in ignoreGroups and not groupName.lower() in [ignoreGroup.lower() for ignoreGroup in ignoreGroups]:
 				continue
-			hgIgnore.write("#\n#\tIgnore Group: %s\n#" % group)
+			hgIgnore.write("#\n#\tIgnore Group: %s\n#" % groupName)
 			# Reverse the sorting order to put the regular expressions first.
-			patterns.sort(key = lambda p: p.Filter, reverse = True)
+			groupPatterns.sort(key = lambda p: p.Filter, reverse = True)
 			filteringOn = None
-			for pattern in patterns:
+			for pattern in groupPatterns:
 				if pattern.Filter == filteringOn:
 					hgIgnore.write("\n%s\t\t#  %s" % (pattern.Value, pattern.Description))
 				else: