Mercurial > hgweb.cgi > hwm
changeset 2:3f42faf8f864
Read configuration settings from a file. IN: -
author | John Schneiderman <JohnMS@CodeGNU.com> |
---|---|
date | Mon, 21 Jul 2014 20:59:06 -0500 |
parents | 7eab9081bd86 |
children | 23750425eabb |
files | .hgignore doc/ChangeLog doc/TODO src/configuration.py src/manager.py |
diffstat | 5 files changed, 41 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Mon Jul 21 20:54:24 2014 -0500 +++ b/.hgignore Mon Jul 21 20:59:06 2014 -0500 @@ -1,2 +1,3 @@ syntax: glob *.pyc +hwm.ini
--- a/doc/ChangeLog Mon Jul 21 20:54:24 2014 -0500 +++ b/doc/ChangeLog Mon Jul 21 20:59:06 2014 -0500 @@ -19,3 +19,4 @@ ******************************************************************************** 2014-07-21 John Schneiderman <Licensing _AT_ CodeGNU _DOT_ com> 0.1.0 - Ability to create a new repository. +- Configuration settings read from an INI file.
--- a/doc/TODO Mon Jul 21 20:54:24 2014 -0500 +++ b/doc/TODO Mon Jul 21 20:59:06 2014 -0500 @@ -37,4 +37,3 @@ - User tutorials. - Generate default ignore file using XML. - Actually parse the hgweb.config file to work with it. -- Read configuration settings from a configuration file
--- a/src/configuration.py Mon Jul 21 20:54:24 2014 -0500 +++ b/src/configuration.py Mon Jul 21 20:59:06 2014 -0500 @@ -19,18 +19,47 @@ #** along with this program. If not, see <http://www.gnu.org/licenses/>. *** #******************************************************************************* +""" + IMPORTS +""" +from ConfigParser import SafeConfigParser + + class Manager(object): """ Manages the configurations for HgWebManager """ - - # The path to the hg command. + # The configuration file parser. + __parser = None + # The path and file name of the hg command. HgCommand = None - RepositoryBase = None + # The base directory path for the HgWeb repositories. + RepositoryPath = None + # The base directory path to the HgWeb web-server. HgWebPath = None + # The user-name of the Mercurial web-manager. HgUser = None - def __init__(self): - """ TODO: Loads the values from the configuration file.""" - self.HgUser = "hg" - self.HgCommand = "/usr/bin/hg" - self.RepositoryBase = "/var/hg/repos" - self.HgWebPath = "/var/www/hgweb" + 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. + """ + 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/manager.py Mon Jul 21 20:54:24 2014 -0500 +++ b/src/manager.py Mon Jul 21 20:59:06 2014 -0500 @@ -33,7 +33,7 @@ import stat import shutil print "Generating repository:" + repository.StorageName - repoBase = settings.RepositoryBase + os.sep + repository.StorageName + repoBase = settings.RepositoryPath + os.sep + repository.StorageName config = repoBase + os.sep + ".hg" + os.sep + "hgrc" # Create the requested repository.