Mercurial > hgweb.cgi > hwm
changeset 23:b18cd3cb2c09
Better error message when the configuration file is not read. IN: -
author | John Schneiderman <JohnMS@CodeGNU.com> |
---|---|
date | Tue, 29 Jul 2014 19:23:38 -0500 |
parents | 974587bd3cba |
children | 9ebd6d65b6c1 |
files | src/__init__.py src/config.py src/configuration.py src/hwm.py src/manager.py src/manrepo.py |
diffstat | 6 files changed, 96 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- a/src/__init__.py Tue Jul 29 18:31:00 2014 -0500 +++ b/src/__init__.py Tue Jul 29 19:23:38 2014 -0500 @@ -23,7 +23,7 @@ # Files to include when creating the package. __all__ = [ - 'configuration.py' + 'config.py' , 'hwm.py' , 'manager.py' , 'manrepo.py'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/config.py Tue Jul 29 19:23:38 2014 -0500 @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +#******************************************************************************* +#** This file is part of HgWeb Manager. *** +#** *** +#** Copyright (C) 2014 *** +#** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** +#** *** +#** This program is free software: you can redistribute it and/or modify it *** +#** under the terms of the GNU Affero General Public License as published *** +#** by the Free Software Foundation, either version 3 of the License, or *** +#** (at your option) any later version. *** +#** *** +#** This program is distributed in the hope that it will be useful, but *** +#** WITHOUT ANY WARRANTY; without even the implied warranty of *** +#** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** +#** See the GNU Affero General Public License for more details. *** +#** *** +#** 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/>. *** +#******************************************************************************* + +class Manager(object): + """ Manages the configurations for HgWebManager """ + # 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 + + @property + def RepositoryPath(self): + """ Gets the directory path to the managed repositories. """ + return self.__repositoryPath + + @property + def HgWebPath(self): + """ Gets the directory path to the repository web-server. """ + return self.__hgWebPath + + @property + def HgUser(self): + """ Gets the user-name of the web-manager. """ + return self.__hgUser + + + def __init__(self, path = ['/etc/hwm.ini', '~/.hwm/hwm.ini', './hwm.ini']): + """ Loads the settings values stored in the configuration file. + + @param[in] path The path and file name of the configuration file. + """ + from ConfigParser import SafeConfigParser, Error + + self.__parser = SafeConfigParser() + if len(self.__parser.read(path)) == 0: + raise Error("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') + + if self.__parser.has_option('Mercurial', 'User'): + self.__hgUser = self.__parser.get('Mercurial', 'User') + + if self.__parser.has_option('Mercurial', 'Web'): + self.__hgWebPath = self.__parser.get('Mercurial', 'Web') + else: + self.__hgUser = "hg" + self.__repositoryPath = "/var/hg/repos" + self.__hgCommand = "/usr/bin/hg" + self.__hgWebPath = "/var/www/hgweb"
--- a/src/configuration.py Tue Jul 29 18:31:00 2014 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -# -*- coding: utf-8 -*- -#******************************************************************************* -#** This file is part of HgWeb Manager. *** -#** *** -#** Copyright (C) 2014 *** -#** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** -#** *** -#** This program is free software: you can redistribute it and/or modify it *** -#** under the terms of the GNU Affero General Public License as published *** -#** by the Free Software Foundation, either version 3 of the License, or *** -#** (at your option) any later version. *** -#** *** -#** This program is distributed in the hope that it will be useful, but *** -#** WITHOUT ANY WARRANTY; without even the implied warranty of *** -#** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** -#** See the GNU Affero General Public License for more details. *** -#** *** -#** 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/>. *** -#******************************************************************************* - -class Manager(object): - """ Manages the configurations for HgWebManager """ - # 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 - - @property - def RepositoryPath(self): - """ Gets the directory path to the managed repositories. """ - return self.__repositoryPath - - @property - def HgWebPath(self): - """ Gets the directory path to the repository web-server. """ - return self.__hgWebPath - - @property - def HgUser(self): - """ Gets the user-name of the web-manager. """ - return self.__hgUser - - - def __init__(self, path = ['/etc/hwm.ini', '~/.hwm/hwm.ini', './hwm.ini']): - """ Loads the settings values stored in the configuration file. - - @param[in] path The path and file name of the configuration file. - """ - from ConfigParser import SafeConfigParser - - self.__parser = SafeConfigParser() - self.__parser.read(path) - - 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') - - if self.__parser.has_option('Mercurial', 'User'): - self.__hgUser = self.__parser.get('Mercurial', 'User') - - if self.__parser.has_option('Mercurial', 'Web'): - self.__hgWebPath = self.__parser.get('Mercurial', 'Web') - else: - self.__hgUser = "hg" - self.__repositoryPath = "/var/hg/repos" - self.__hgCommand = "/usr/bin/hg" - self.__hgWebPath = "/var/www/hgweb"
--- a/src/hwm.py Tue Jul 29 18:31:00 2014 -0500 +++ b/src/hwm.py Tue Jul 29 19:23:38 2014 -0500 @@ -36,11 +36,17 @@ """ IMPORTS """ -import configuration as config +import config # Configuration values for HgWebManager. -settings = config.Manager() +try: + settings = config.Manager() +except Exception as e: + import sys + print >>sys.stderr, 'Settings Error:', e + exit(1) + def is_hgWeb_user(): """Determines if the current running user is the expected HgWeb user. @@ -104,7 +110,7 @@ if manager.create(repo): exit(0) else: - exit(1) + exit(2) elif 'modify' == args.action[0]: currentStorageName = repo.StorageName if args.rename: @@ -112,17 +118,17 @@ if manager.modify(repo, currentStorageName): exit(0) else: - exit(1) + exit(2) elif 'delete' == args.action[0]: if manager.delete(repo): exit(0) else: - exit(1) + exit(2) elif 'register' == args.action[0]: if manager.register(repo): exit(0) else: - exit(1) + exit(2) else: print >>sys.stderr, "Failure determine action request %s." % args.action exit(2)