changeset 62:e082759a26b8

Configuration file now split into logical sections. New data path in the configuration file.
author John Schneiderman
date Tue, 07 Apr 2015 19:07:10 +0200
parents a1b9dc5efa75
children 670c2af462f6
files doc/ChangeLog setup.py src/config.py src/hwm.py src/manager.py
diffstat 5 files changed, 55 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Tue Apr 07 18:25:31 2015 +0200
+++ b/doc/ChangeLog	Tue Apr 07 19:07:10 2015 +0200
@@ -17,6 +17,8 @@
 ***  You should have received a copy of the GNU Affero General Public License***
 ***  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
 ********************************************************************************
+2015-XX-XX John Schneiderman <Licensing _AT_ CodeGNU _DOT_ com> 0.5.0
+- Split configuration file into logical sections.
 2015-03-28 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.
--- a/setup.py	Tue Apr 07 18:25:31 2015 +0200
+++ b/setup.py	Tue Apr 07 19:07:10 2015 +0200
@@ -78,7 +78,7 @@
 		(
 			"share/" + SHORT_NAME,
 			[
-				'data/ignores.xml'
+				'ignores.xml'
 			]
 		),
 	],
--- a/src/config.py	Tue Apr 07 18:25:31 2015 +0200
+++ b/src/config.py	Tue Apr 07 19:07:10 2015 +0200
@@ -25,30 +25,42 @@
 
 	# The configuration file parser.
 	__parser = None
+
 	# The absolute directory path and file name of the hg command.
 	__hgCommand = None
-	# The absolute directory path to the managed HgWeb repositories.
-	__repositoryPath = None
-	# The absolute directory path to the HgWeb web-server.
-	__hgWebPath = None
-	# The user-name of the Mercurial web-manager.
-	__hgUser = None
 
 	@property
 	def HgCommand(self):
 		""" Gets the command for executing mercurial. """
 		return self.__hgCommand
 
+	# The absolute directory path to the managed HgWeb repositories.
+	__repositoryPath = None
+
 	@property
 	def RepositoryPath(self):
 		""" Gets the directory path to the managed repositories. """
 		return self.__repositoryPath
 
+	# The absolute directory path to the HgWeb web-server site.
+	__hgWebPath = None
+
 	@property
 	def HgWebPath(self):
-		""" Gets the directory path to the repository web-server. """
+		""" Gets the directory path to the repository web-server site. """
 		return self.__hgWebPath
 
+	# The directory path for HWM data.
+	__dataPath = None
+
+	@property
+	def DataPath(self):
+		""" Gets the directory path to the HWM data directory. """
+		return self.__dataPath
+
+	# The user-name of the Mercurial web-manager.
+	__hgUser = None
+
 	@property
 	def HgUser(self):
 		""" Gets the user-name of the web-manager. """
@@ -59,29 +71,46 @@
 
 		@param[in] path	The path and file name of the configuration file.
 
-		@throws ConfigParser.Error		When the configuration file cannot be
-										found.
+		@throws ValueError		When the configuration file cannot be found.
+		@throw RuntimeError		When the configuration file is missing required
+								entries.
 		"""
-		from ConfigParser import SafeConfigParser, Error
+		from ConfigParser import SafeConfigParser
 
 		self.__parser = SafeConfigParser()
 		if not self.__parser.read(path):
 			raise ValueError("Failed to find configuration file.")
 
 		if self.__parser.has_section('Mercurial'):
-			if self.__parser.has_option('Mercurial', 'Base'):
-				self.__repositoryPath = self.__parser.get('Mercurial', 'Base')
-
 			if self.__parser.has_option('Mercurial', 'Command'):
 				self.__hgCommand = self.__parser.get('Mercurial', 'Command')
+			else:
+				self.__hgCommand = '/usr/bin/hg'
+		else:
+			self.__hgCommand = '/usr/bin/hg'
 
-			if self.__parser.has_option('Mercurial', 'User'):
-				self.__hgUser = self.__parser.get('Mercurial', 'User')
+		if self.__parser.has_section('HgWeb'):
+			if self.__parser.has_option('HgWeb', 'Base'):
+				self.__repositoryPath = self.__parser.get('HgWeb', 'Base')
+			else:
+				raise RuntimeError('Failed to locate the HgWeb-Base entry')
 
-			if self.__parser.has_option('Mercurial', 'Web'):
-				self.__hgWebPath = self.__parser.get('Mercurial', 'Web')
+			if self.__parser.has_option('HgWeb', 'Server'):
+				self.__hgWebPath = self.__parser.get('HgWeb', 'Server')
+			else:
+				raise RuntimeError('Failed to locate the HgWeb-Server entry')
 		else:
-			self.__hgUser = "hg"
-			self.__repositoryPath = "/var/hg/repos"
-			self.__hgCommand = "/usr/bin/hg"
-			self.__hgWebPath = "/var/www/hgweb"
+			raise RuntimeError('Failed to locate the HgWeb configuration section')
+
+		if self.__parser.has_section('HWM'):
+			if self.__parser.has_option('HWM', 'Data'):
+				self.__dataPath = self.__parser.get('HWM', 'Data')
+			else:
+				self.__dataPath = '/usr/share/hwm'
+
+			if self.__parser.has_option('HWM', 'Manager'):
+				self.__hgUser = self.__parser.get('HWM', 'Manager')
+			else:
+				raise RuntimeError('Failed to locate the HWM-Manager entry')
+		else:
+			raise RuntimeError('Failed to locate the HWM configuration section')
--- a/src/hwm.py	Tue Apr 07 18:25:31 2015 +0200
+++ b/src/hwm.py	Tue Apr 07 19:07:10 2015 +0200
@@ -77,6 +77,7 @@
 
 if __name__ == '__main__':
 	import _app_info
+	import sys
 
 	try:
 		# Display license
@@ -90,7 +91,6 @@
 		from manager import settings
 		import argparse
 		import manager
-		import sys
 
 		if not is_hgWeb_user(settings.HgUser):
 			print >>sys.stderr, 'Must execute as the Mercurial Web manager.'
--- a/src/manager.py	Tue Apr 07 18:25:31 2015 +0200
+++ b/src/manager.py	Tue Apr 07 19:07:10 2015 +0200
@@ -272,7 +272,7 @@
 	# Extract Ignore Collection
 	if ignoreGroups is None:
 		ignoreGroups = []
-	ignores = ignorepo.extract('ignores.xml')
+	ignores = ignorepo.extract(os.path.join(settings.DataPath, 'ignores.xml'))
 
 	if skipCommon:
 		del ignores['Common']