changeset 34:c480ef7a02eb

Ability to output a list of all repositories manged. IN: -
author John Schneiderman <JohnMS@CodeGNU.com>
date Tue, 12 Aug 2014 20:05:04 -0500
parents f2e0f4de13ea
children f7cdfc4c8408
files doc/ChangeLog doc/TODO src/hwm.py src/manager.py src/manrepo.py
diffstat 5 files changed, 60 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Tue Aug 12 19:12:20 2014 -0500
+++ b/doc/ChangeLog	Tue Aug 12 20:05:04 2014 -0500
@@ -25,6 +25,7 @@
 - HgWeb configuration now managed cleanly, i.e. no longer a raw read/write.
 - Multiple managers cannot work on the set-up at the same time.
 - Two repositories can no longer have the same display name.
+- Ability to list all managed repositories.
 2014-07-29 John Schneiderman <Licensing _AT_ CodeGNU _DOT_ com> 0.2.1
 - Fixed issue where the configuration file copy started before it closed.
 - Fixed issue in Windows locking temporary file and preventing copying.
--- a/doc/TODO	Tue Aug 12 19:12:20 2014 -0500
+++ b/doc/TODO	Tue Aug 12 20:05:04 2014 -0500
@@ -34,6 +34,5 @@
 - Manager should handle the HgWeb configuration file settings.
 - Manager should provide a REST API for repository management.
 - Manager should have an API key per user permission values.
-- Manager should list all managed repositories like Display_Name(Storage_Name).
 - Change functions to use exceptions for error handling, except for the command-line module.
 - Create a separate manager for the HgWeb configuration file.
--- a/src/hwm.py	Tue Aug 12 19:12:20 2014 -0500
+++ b/src/hwm.py	Tue Aug 12 20:05:04 2014 -0500
@@ -63,8 +63,8 @@
 	import manrepo
 
 	managed = manrepo.Repository()
-	if args.repository:
-		managed.StorageName = args.repository
+	if args.storage:
+		managed.StorageName = args.storage
 
 	if args.name:
 		managed.DisplayName = args.name
@@ -82,59 +82,63 @@
 	import sys
 
 	if not is_hgWeb_user():
-		print >>sys.stderr, "Must execute as the Mercurial Web manager."
+		print >>sys.stderr, 'Must execute as the Mercurial Web manager.'
 		exit(1)
 
 	parser = argparse.ArgumentParser(description=DESCRIPTION)
-	parser.add_argument("repository", action="store", help='The storage-name of the repository to perform an action upon.')
-	parser.add_argument("-a", "--action", action="store", nargs=1, type=str, choices=['create','modify','delete', 'register'], help='Performs an action upon a managed repository.')
-	parser.add_argument("-n", "--name", action="store", nargs='?', default=None, help='The display name of the repository.')
-	parser.add_argument("-d", "--description", action="store", nargs='?', default=None, help='The description of the repository.')
-	parser.add_argument("-c", "--contact", action="store", nargs='?', default=None, help='The contact point of a repository.')
-	parser.add_argument("-r", "--rename", action="store", nargs='?', default=None, help='The new storage-name for a repository.')
-	parser.add_argument("-i", "--ignore", action="store", nargs='+', default=None, help='The groups to place in an ignore file.')
+	parser.add_argument('-l', '--list', action='store_true', help='Outputs a list of all the managed repositories.')
+
+	manGrp = parser.add_argument_group('Manage', '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.')
+	manGrp.add_argument('-a', '--action', action='store', nargs=1, type=str, choices=['c', 'create', 'm', 'modify', 'd', 'delete', 'r', 'register'], help='Performs an action upon a managed repository.')
+	manGrp.add_argument('-i', '--ignore', action='store', nargs='+', default=None, help='The groups to place in an ignore file.')
+	manGrp.add_argument('-n', '--name', action='store', nargs='?', default=None, help='The display name of the repository.')
+	manGrp.add_argument('-d', '--description', action='store', nargs='?', default=None, help='The description of the repository.')
+	manGrp.add_argument('-c', '--contact', action='store', nargs='?', default=None, help='The contact point of a repository.')
+	manGrp.add_argument('-r', '--rename', action='store', nargs='?', default=None, help='The new storage-name for a repository.')
+
+	# Examine the supplied arguments and perform requested actions.
 	args = parser.parse_args()
 	repo = __extract_values(args)
 
-	if 'create' == args.action[0]:
+	if args.list:
+		if not manager.list():
+			exit(2)
+	elif args.action is None:
+		print >>sys.stderr, "No actionable arguments supplied."
+		exit(1)
+	elif ('create' == args.action[0]) or ('c' == args.action[0]):
 		if args.ignore:
 			ignores = args.ignore
 		else:
 			ignores = ['Common']
-		if manager.create(repo, ignores):
-			exit(0)
-		else:
+		if not manager.create(repo, ignores):
 			exit(2)
-	elif 'modify' == args.action[0]:
+	elif ('modify' == args.action[0]) or ('m' == args.action[0]):
 		currentStorageName = repo.StorageName
 		if args.rename:
 			repo.StorageName = args.rename
-		if manager.modify(repo, currentStorageName, args.ignore):
-			exit(0)
-		else:
+		if not manager.modify(repo, currentStorageName, args.ignore):
 			exit(2)
-	elif 'delete' == args.action[0]:
-		if manager.delete(repo):
-			exit(0)
-		else:
+	elif ('delete' == args.action[0]) or ('d' == args.action[0]):
+		if not manager.delete(repo):
 			exit(2)
-	elif 'register' == args.action[0]:
-		if manager.register(repo):
-			exit(0)
-		else:
+	elif ('register' == args.action[0]) or ('r' == args.action[0]):
+		if not manager.register(repo):
 			exit(2)
 	else:
-		print >>sys.stderr, "Failure determine action request %s." % args.action
+		print >>sys.stderr, "Failure determine requested action '%s'." % args.action[0]
 		exit(2)
+	exit(0)
 
-if __name__ == "__main__":
+if __name__ == '__main__':
 	import sys
 
 	# Display license
 	print "%s %s Copyright (C) %s CodeGNU Solutions" % (LONG_NAME, VERSION, YEARS)
 	print "%s comes with ABSOLUTELY NO WARRANTY;" % (SHORT_NAME)
-	print "This is free software, and you are welcome to redistribute it"
-	print "under certain conditions; see the LICENSE file for details,"
-	print "or the Free Software Foundation's AGPL.\n"
+	print 'This is free software, and you are welcome to redistribute it'
+	print 'under certain conditions; see the LICENSE file for details,'
+	print 'or the Free Software Foundation\'s AGPL.\n'
 
 	main(sys.argv)
--- a/src/manager.py	Tue Aug 12 19:12:20 2014 -0500
+++ b/src/manager.py	Tue Aug 12 20:05:04 2014 -0500
@@ -135,7 +135,7 @@
 	print "Acquiring manager lock ..."
 	lock = guard.FileLock('HWM')
 	with lock:
-		print "Modifying repository: " + currentStorageName
+		print "Modifying repository: %s" % currentStorageName
 		oldRepository = Repository(currentStorageName)
 
 		if not __doesRepositoryStorageNameExist(oldRepository):
@@ -227,6 +227,23 @@
 			print >>sys.stderr, "Failed to delete the repository."
 			return False
 
+def list():
+	""" Outputs a listing of all the known managed repositories
+
+	 @return When the output generation is successful gives true, else-wise false.
+	"""
+	import manrepo
+
+	print "Managed Repositories:"
+	try:
+		repoCol = manrepo.ManagedCollection()
+		for repo in repoCol.Repositories:
+			print "\t%s (%s)" % (repo.StorageName, repo.DisplayName)
+		return True
+	except Exception as e:
+		print >>sys.stderr, "Listing error({0}): {1}".format(e.errno, e.strerror)
+		return False
+
 
 
 #--- Functions for fulfilling repository management.
@@ -478,6 +495,10 @@
 	import sys
 	import os
 
+	if repo.StorageName is None:
+		print >>sys.stderr, 'Cannot create a managed repository without a storage name.'
+		return False
+
 	try:
 		statusCode = subprocess.call([settings.HgCommand, 'init', settings.RepositoryPath + os.sep + repo.StorageName])
 	except OSError as e:
--- a/src/manrepo.py	Tue Aug 12 19:12:20 2014 -0500
+++ b/src/manrepo.py	Tue Aug 12 20:05:04 2014 -0500
@@ -128,6 +128,8 @@
 
 	def __init__(self):
 		""" Initialises the container with all the managed repositories.
+
+		 @throws Exception	When the HgWeb configuration cannot be read.
 		"""
 		from ConfigParser import SafeConfigParser
 		import os