changeset 12:43d7ef8912d3

Register existing repositories. IN: -
author John Schneiderman <JohnMS@CodeGNU.com>
date Sat, 26 Jul 2014 14:29:48 -0500
parents 7a7c6a796a6d
children b09caec3d202
files doc/ChangeLog setup.py src/hwm.py src/manager.py
diffstat 4 files changed, 56 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Sat Jul 26 13:59:13 2014 -0500
+++ b/doc/ChangeLog	Sat Jul 26 14:29:48 2014 -0500
@@ -20,6 +20,8 @@
 2014-07-26 John Schneiderman <Licensing _AT_ CodeGNU _DOT_ com> 0.2.0
 - Ability to modify an existing repository.
 - Load a managed repository object from it's storage name.
+- Packaging support across platforms.
+- Register already existing repositories.
 2014-07-21 John Schneiderman <Licensing _AT_ CodeGNU _DOT_ com> 0.1.0
 - Ability to create a new repository.
 - Ability to delete an existing repository.
--- a/setup.py	Sat Jul 26 13:59:13 2014 -0500
+++ b/setup.py	Sat Jul 26 14:29:48 2014 -0500
@@ -24,7 +24,7 @@
 import sys
 
 sys.path.append('./src')
-from hwm import YEARS,VERSION,DESCRIPTION,LONG_DESCRIPTION
+from hwm import YEARS,VERSION,DESCRIPTION,LONG_DESCRIPTION,SHORT_NAME
 
 required= \
 	[
@@ -36,7 +36,8 @@
 	]
 
 # Basic package setup information
-setup(  name='hwm',
+setup(
+	name=SHORT_NAME,
 	version=VERSION,
 	description=DESCRIPTION,
 	long_description=LONG_DESCRIPTION,
--- a/src/hwm.py	Sat Jul 26 13:59:13 2014 -0500
+++ b/src/hwm.py	Sat Jul 26 14:29:48 2014 -0500
@@ -20,6 +20,10 @@
 #**  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
 #*******************************************************************************
 
+# The shortened name of the application
+SHORT_NAME='HWM'
+# The full name of the application
+LONG_NAME='HgWeb Manager'
 # The current version of the application
 VERSION = '0.2.0'
 # The current copyright years.
@@ -88,11 +92,11 @@
 
 	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'], help='Performs an action upon a managed HgWeb repository.')
+	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 the repository.')
+	parser.add_argument("-r", "--rename", action="store", nargs='?', default=None, help='The new storage-name for a repository.')
 	args = parser.parse_args()
 	repo = __extract_values(args)
 
@@ -115,16 +119,21 @@
 			exit(0)
 		else:
 			exit(1)
-
-	print >>sys.stderr, "Failure determine action request %s." % args.action
-	exit(2)
+	elif 'register' == args.action[0]:
+		if manager.register(repo):
+			exit(0)
+		else:
+			exit(1)
+	else:
+		print >>sys.stderr, "Failure determine action request %s." % args.action
+		exit(2)
 
 if __name__ == "__main__":
 	import sys
 
 	# Display license
-	print "HWM %s Copyright (C) %s CodeGNU Solutions" % (VERSION, YEARS)
-	print "HWM comes with ABSOLUTELY NO WARRANTY;"
+	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"
--- a/src/manager.py	Sat Jul 26 13:59:13 2014 -0500
+++ b/src/manager.py	Sat Jul 26 14:29:48 2014 -0500
@@ -29,7 +29,6 @@
 
 def create(repository):
 	""" Creates a new repository under HgWeb.
-	 @todo Check the existence of the requested repository.
 
 	 @pre The repository to create cannot already exist.
 
@@ -45,7 +44,7 @@
 	import os
 	import shutil
 
-	print "Generating repository: " + repository.StorageName
+	print "Generating repository: %s" % repository.StorageName
 	if __doesRepositoryExist(repository):
 		print >>sys.stderr, "The repository '%s' already exists." % repository.StorageName
 		return False
@@ -67,14 +66,35 @@
 		shutil.rmtree(settings.RepositoryPath + os.sep + repository.StorageName)
 		return False
 
+	if not register(repository):
+		os.chmod(settings.RepositoryPath + os.sep + repository.StorageName + os.sep + ".hg" + os.sep + "hgrc", stat.S_IWRITE)
+		shutil.rmtree(settings.RepositoryPath + os.sep + repository.StorageName)
+
+def register(repository):
+	""" Connects an existing repository to the mercurial web registry.
+
+	 @pre The repository to register must already exist.
+
+	 @param[in] repository	The targeted repository to register.
+
+	 @post The new repository is registered in HgWeb to display and is
+	  secured to prevent accidental modification.
+
+	 @return When the registration is successful gives true, else-wise false.
+	"""
+	import sys
+
+	print "Registering the repository: %s" % repository.StorageName
+	if not __doesRepositoryExist(repository):
+		print >>sys.stderr, "The repository '%s' does not exists." % repository.StorageName
+		return False
+
 	# Add the new repository to the web registry.
 	if __registerRepository(repository):
-		print "Registered repository with HgWeb."
+		print "Registered repository."
 		return True
 	else:
-		print >>sys.stderr, "Failed to register repository with HgWeb."
-		os.chmod(settings.RepositoryPath + os.sep + repository.StorageName + os.sep + ".hg" + os.sep + "hgrc", stat.S_IWRITE)
-		shutil.rmtree(settings.RepositoryPath + os.sep + repository.StorageName)
+		print >>sys.stderr, "Failed to register repository."
 		return False
 
 def modify(newRepository, currentStorageName):
@@ -102,7 +122,7 @@
 
 	# Remove the current repository from the web registry.
 	if not __unregisterRepository(oldRepository):
-		print >>sys.stderr, "Failed to unregister repository from HgWeb."
+		print >>sys.stderr, "Failed to unregister repository."
 		return False
 
 	# Update renamed repositories
@@ -130,14 +150,14 @@
 
 	# Add the new repository to the web registry.
 	if __registerRepository(newRepository):
-		print "Registered %s to HgWeb." % newRepository.StorageName
+		print "Registered %s." % newRepository.StorageName
 	else:
-		print >>sys.stderr, "Failed to register repository from HgWeb."
+		print >>sys.stderr, "Failed to register repository."
 		return False
 	return True
 
 def delete(repository):
-	""" Removes an existing repository from HgWeb.
+	""" Removes an existing repository.
 
 	 @pre The repository to remove must already exist.
 
@@ -155,11 +175,11 @@
 		print >>sys.stderr, "The repository %s is not valid." % repository.StorageName
 		return False
 
-	print "Removing repository: " + repository.StorageName
+	print "Removing repository: %s" % repository.StorageName
 	if __unregisterRepository(repository):
-		print "Unregistered from HgWeb."
+		print "Unregistered repository."
 	else:
-		print >>sys.stderr, "Failed to unregister repository from HgWeb."
+		print >>sys.stderr, "Failed to unregister repository."
 		return False
 
 	if __deleteRepository(repository):
@@ -221,7 +241,7 @@
 		return False
 
 def __unregisterRepository(repo):
-	""" Removes the registration of the supplied repository from HgWeb.
+	""" Removes the registration of the supplied repository.
 
 	 @param[in] repo	The targeted repository for which to unregister.
 
@@ -354,7 +374,7 @@
 	return status
 
 def __registerRepository(repo):
-	""" Adds the registration details of the repository to HgWeb.
+	""" Adds the registration details of the repository.
 
 	 @param[in] repo	The targeted repository for which to register in HgWeb.