changeset 36:d3133f1befe0

Ability to modify only a single repository detail. IN: -
author John Schneiderman <JohnMS@CodeGNU.com>
date Wed, 13 Aug 2014 18:21:12 -0500
parents f7cdfc4c8408
children 02d649ca5bb1
files doc/ChangeLog src/hwm.py src/manager.py src/manrepo.py
diffstat 4 files changed, 72 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Wed Aug 13 18:01:04 2014 -0500
+++ b/doc/ChangeLog	Wed Aug 13 18:21:12 2014 -0500
@@ -26,6 +26,7 @@
 - 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.
+- Modify now /only/ changes the values supplied, leaving others alone.
 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/src/hwm.py	Wed Aug 13 18:01:04 2014 -0500
+++ b/src/hwm.py	Wed Aug 13 18:21:12 2014 -0500
@@ -53,7 +53,10 @@
 
 
 def __extract_values(args):
-	""" Pulls the creation arguments out of the command-line.
+	""" Pulls the creation arguments out of the command-line. The returned
+	 object is filled with the repository details when it exists and any of the
+	 detail values supplied on the command-line will replace the one found in
+	 the repository details.
 
 	 @param[in] args	The command-line argument processor containing the
 					creation argument values.
@@ -62,9 +65,15 @@
 	"""
 	import manrepo
 
-	managed = manrepo.Repository()
-	if args.storage:
-		managed.StorageName = args.storage
+	managed = None
+	if args.rename:
+		original = manrepo.Repository(args.storage)
+		managed = manrepo.Repository(args.rename)
+		managed.DisplayName = original.DisplayName
+		managed.Description = original.Description
+		managed.Contact = original.Contact
+	else:
+		managed = manrepo.Repository(args.storage)
 
 	if args.name:
 		managed.DisplayName = args.name
@@ -74,6 +83,7 @@
 
 	if args.contact:
 		managed.Contact = args.contact
+
 	return managed
 
 def main(args):
@@ -115,10 +125,7 @@
 		if not manager.create(repo, ignores):
 			exit(2)
 	elif ('modify' == args.action[0]) or ('m' == args.action[0]):
-		currentStorageName = repo.StorageName
-		if args.rename:
-			repo.StorageName = args.rename
-		if not manager.modify(repo, currentStorageName, args.ignore):
+		if not manager.modify(repo, args.storage, args.ignore):
 			exit(2)
 	elif ('delete' == args.action[0]) or ('d' == args.action[0]):
 		if not manager.delete(repo):
--- a/src/manager.py	Wed Aug 13 18:01:04 2014 -0500
+++ b/src/manager.py	Wed Aug 13 18:21:12 2014 -0500
@@ -142,15 +142,17 @@
 			print >>sys.stderr, "The repository '%s' was not found." % oldRepository.StorageName
 			return False
 
-		if __doesRepositoryDisplayNameExist(newRepository):
-			print >>sys.stderr, "The display name '%s' already exists." % newRepository.DisplayName
-			return False
-
 		# Remove the current repository from the web registry.
 		if not __unregisterRepository(oldRepository):
 			print >>sys.stderr, "Failed to unregister repository."
 			return False
 
+		if __doesRepositoryDisplayNameExist(newRepository):
+			print >>sys.stderr, "The display name '%s' already exists." % newRepository.DisplayName
+			if not __registerRepository(oldRepository):
+				print >>sys.stderr, "Failed to register repository."
+			return False
+
 		# Update renamed repositories
 		if not oldRepository == newRepository:
 			if __renameStorage(oldRepository, newRepository.StorageName):
@@ -382,8 +384,8 @@
 	try:
 		if oldRepo.StorageName == newName:
 			return True
-		elif os.exists(settings.RepositoryPath + os.sep + newName):
-			print >>sys.stderr, "Cannot rename the existing repository %s because the name %s already exists." % (oldRepo.StorageName, newName)
+		elif os.path.isdir(settings.RepositoryPath + os.sep + newName):
+			print >>sys.stderr, "Cannot rename the existing repository '%s' because the name '%s' already exists." % (oldRepo.StorageName, newName)
 			return False
 		else:
 			shutil.move(settings.RepositoryPath + os.sep + oldRepo.StorageName, settings.RepositoryPath + os.sep + newName)
@@ -523,26 +525,18 @@
 	import sys
 
 	print "Saving display details ..."
-	config = settings.RepositoryPath + os.sep + repo.StorageName + os.sep + '.hg' + os.sep + "hgrc"
+	config = settings.RepositoryPath + os.sep + repo.StorageName + os.sep + '.hg' + os.sep + 'hgrc'
 	if os.path.exists(config):
 		hgrcMode = os.stat(config)[stat.ST_MODE]
 		os.chmod(config, hgrcMode | stat.S_IWRITE)
 	else:
 		hgrcMode = stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH
 
-	with open(config, "w") as hgrc:
-		hgrc.write("[web]\n")
-
-		if repo.DisplayName is None:
-			hgrc.write("name = " + repo.StorageName + '\n')
-		else:
-			hgrc.write("name = " + repo.DisplayName + '\n')
-
-		if repo.Description is not None:
-			hgrc.write("description = " + repo.Description + '\n')
-
-		if repo.Contact is not None:
-			hgrc.write("contact = " + repo.Contact + '\n')
+	try:
+		repo.save()
+	except IOError as e:
+		print >>sys.stderr, "Failed to save details, error({0}): {1}".format(e.errno, e.strerror)
+		return False
 	# Ensure the repository details isn't accidentally modified.
 	os.chmod(config, hgrcMode & (~stat.S_IWUSR & ~stat.S_IWGRP & ~stat.S_IWOTH))
 
--- a/src/manrepo.py	Wed Aug 13 18:01:04 2014 -0500
+++ b/src/manrepo.py	Wed Aug 13 18:21:12 2014 -0500
@@ -38,15 +38,14 @@
 	__description = None
 	# The displayed web-site contact information of the managed repository.
 	__contact = None
+	# The Mercurial repository interface.
+	__repo = None
+
 
 	@property
 	def StorageName(self):
 		""" Gets the name of the directory where the managed repository is located. """
 		return self.__storageName
-	@StorageName.setter
-	def StorageName(self, value):
-		""" Sets the name of the directory with a supplied name. """
-		self.__storageName = value
 
 	@property
 	def DisplayName(self):
@@ -87,18 +86,12 @@
 		self.__storageName = repoName
 		if repoName:
 			try:
-				repo = hg.repository(ui.ui(), settings.RepositoryPath + os.sep + repoName)
-				self.__displayName = repo.ui.config('web', 'name', default=None)
-				self.__description = repo.ui.config('web', 'description', default=None)
-				self.__contact = repo.ui.config('web', 'contact', default=None)
+				self.__repo = hg.repository(ui.ui(), settings.RepositoryPath + os.sep + self.__storageName)
+				self.__displayName = self.__repo.ui.config('web', 'name', default=None)
+				self.__description = self.__repo.ui.config('web', 'description', default=None)
+				self.__contact = self.__repo.ui.config('web', 'contact', default=None)
 			except error.RepoError:
-				self.__displayName = None
-				self.__description = None
-				self.__contact = None
-		else:
-			self.__displayName = None
-			self.__description = None
-			self.__contact = None
+				pass
 
 	def __eq__(self, other):
 		""" Determines if two repositories are the same repository.
@@ -111,6 +104,40 @@
 		"""
 		return self.__storageName == other.__storageName
 
+	def save(self):
+		""" Commits the repository detail properties to the repository
+		 configuration file.
+
+		 @throws IOError	When the configuration file for the repository
+						 fails to be written.
+		"""
+		import os
+
+		with open(settings.RepositoryPath + os.sep + self.__storageName + os.sep + '.hg' + os.sep + 'hgrc', 'w') as hgrc:
+			hgrc.write('[web]\n')
+
+			if self.__displayName is None:
+				hgrc.write('name = ' + self.__storageName + '\n')
+			else:
+				hgrc.write('name = ' + self.__displayName + '\n')
+
+			if self.__description is not None:
+				hgrc.write('description = ' + self.__description + '\n')
+
+			if self.__contact is not None:
+				hgrc.write('contact = ' + self.__contact + '\n')
+
+		if self.__repo is None:
+			from mercurial import ui, hg
+			import os
+
+			self.__repo = hg.repository(ui.ui(), settings.RepositoryPath + os.sep + self.__storageName)
+		self.__displayName = self.__repo.ui.config('web', 'name', default=None)
+		self.__description = self.__repo.ui.config('web', 'description', default=None)
+		self.__contact = self.__repo.ui.config('web', 'contact', default=None)
+
+
+
 class ManagedCollection(object):
 	""" A container of all the managed repositories. """