Mercurial > p > roundup > code
changeset 482:fdee2ff82b40 config-0-4-0-branch
Miscellaneous improvements
* Altered function names in roundup.config to bE NeAtEr rather_than_ugly;
* Created some extra roundup.config exceptions to let people know what's
going on;
* Modified instance_config.py to use those exceptions, so that syntax errors
or other exceptions did *not* trigger the same behavior as import
while in the templates/ directory.
* Modified roundup.cgi to use the same neater function names, plus did some
minor cleanup.
| author | Titus Brown <titus@users.sourceforge.net> |
|---|---|
| date | Thu, 03 Jan 2002 08:28:17 +0000 |
| parents | a261b0bbba43 |
| children | 912029653c1c |
| files | cgi-bin/roundup.cgi roundup/config.py roundup/templates/classic/instance_config.py |
| diffstat | 3 files changed, 49 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/cgi-bin/roundup.cgi Thu Jan 03 04:28:21 2002 +0000 +++ b/cgi-bin/roundup.cgi Thu Jan 03 08:28:17 2002 +0000 @@ -16,7 +16,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: roundup.cgi,v 1.22.2.1 2002-01-03 02:12:05 titus Exp $ +# $Id: roundup.cgi,v 1.22.2.2 2002-01-03 08:28:15 titus Exp $ # python version check import sys @@ -41,18 +41,13 @@ # ROUNDUP_DEBUG is a debug level, currently only 0 (OFF) and 1 (ON) are # used in the code. Higher numbers means more debugging output. -# This indicates where the Roundup instance lives -ROUNDUP_INSTANCE_HOMES = { -# 'dev' : '/u/t/dev/roundup/instance' -} +import roundup.config +base_config = roundup.config.loadBaseConfig() +instances = base_config.loadInstances() -### @CTB config file. -import roundup.config -base_config = roundup.config.load_base_config() -instances_config = base_config.load_instances_config() - -for name in instances_config.get_instance_names(): - ROUNDUP_INSTANCE_HOMES[name] = instances_config.get_instance_dir(name) +ROUNDUP_INSTANCE_HOMES = {} +for name in instances.getNames(): + ROUNDUP_INSTANCE_HOMES[name] = instances.getDirFromName(name) # Where to log debugging information to. Use an instance of DevNull if you # don't want to log anywhere. @@ -208,6 +203,11 @@ # # $Log: not supported by cvs2svn $ +# Revision 1.22.2.1 2002/01/03 02:12:05 titus +# +# +# Initial ConfigParser implementation. +# # Revision 1.22 2001/12/13 00:20:01 richard # . Centralised the python version check code, bumped version to 2.1.1 (really # needs to be 2.1.2, but that isn't released yet :)
--- a/roundup/config.py Thu Jan 03 04:28:21 2002 +0000 +++ b/roundup/config.py Thu Jan 03 08:28:17 2002 +0000 @@ -6,13 +6,19 @@ class Error(Exception): pass +class UnknownInstanceLocation(Error): + pass + +class NoInstanceConfigFile(Error): + pass + def debug_mode(): """ Returns the basic debug mode/level. """ return os.environ.get('ROUNDUP_DEBUG', 0) -def load_base_config(): +def loadBaseConfig(): """ Loads the base configuration for Roundup. """ @@ -64,7 +70,7 @@ def get(self, group, attr): return self.conf.get(group, attr) - def load_instances_config(self): + def loadInstances(self): filename = string.strip(self.conf.get('base', 'instances')) # if it looks like an absolute path, leave it alone; otherwise, @@ -106,20 +112,28 @@ self.instance_dirs = instance_dirs self.instance_names = instance_names - def get_instance_names(self): + def getNames(self): return self.instance_dirs.keys() - def get_instance_name(self, dir): - return self.instance_names[dir] + def getNameFromDir(self, dir): + if self.instance_names.has_key(dir): + return self.instance_names[dir] + else: + raise UnknownInstanceLocation(dir) - def get_instance_dir(self, name): + def getDirFromName(self, name): return self.instance_dirs[name] - def load_instance_config(self, name): - instance_dir = self.get_instance_dir(name) + def loadConfig(self, name): + instance_dir = self.getDirFromName(name) defaults_file = self.conf.get(name, 'defaults') + if not os.path.exists(defaults_file): + raise NoInstanceConfigFile("defaults file %s does not exist"%(defaults_file,)) + config_file = self.conf.get(name, 'config') + if not os.path.exists(config_file): + raise NoInstanceConfigFile("%s does not exist"%(config_file,)) defaults_dictionary = { 'homedir' : instance_dir, 'instance_name' : name, @@ -153,8 +167,8 @@ return self.conf.get(group, attr) if __name__ == '__main__': - base_config = load_base_config() - instances_config = base_config.load_instances_config() + base_config = loadBaseConfig() + instances = base_config.loadInstances() - for k in instances_config.get_instance_names(): - print "%s:%s"%(k, instances_config.get_instance_dir(k),) + for k in instances.getNames(): + print "%s:%s"%(k, instances.getDirFromName(k),)
--- a/roundup/templates/classic/instance_config.py Thu Jan 03 04:28:21 2002 +0000 +++ b/roundup/templates/classic/instance_config.py Thu Jan 03 08:28:17 2002 +0000 @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: instance_config.py,v 1.10.2.1 2002-01-03 02:12:05 titus Exp $ +# $Id: instance_config.py,v 1.10.2.2 2002-01-03 08:28:17 titus Exp $ import os import roundup.config @@ -23,12 +23,12 @@ # roundup home is this package's directory INSTANCE_HOME=os.path.dirname(__file__) -base_config = roundup.config.load_base_config() -instances_config = base_config.load_instances_config() +base_config = roundup.config.loadBaseConfig() +instances = base_config.loadInstances() try: - instance_name = instances_config.get_instance_name(INSTANCE_HOME) - instance_config = instances_config.load_instance_config(instance_name) + instance_name = instances.getNameFromDir(INSTANCE_HOME) + instance_config = instances.loadConfig(instance_name) # The SMTP mail host that roundup will use to send mail MAILHOST = instance_config.get('mail', 'host') @@ -71,7 +71,7 @@ # Where to place the email signature EMAIL_SIGNATURE_POSITION = instance_config.get('base', 'email_signature_position') -except: # probably in init +except roundup.config.UnknownInstanceLocation: # in 'init' DATABASE = None TEMPLATES = None ADMIN_EMAIL = '' @@ -100,6 +100,11 @@ # # $Log: not supported by cvs2svn $ +# Revision 1.10.2.1 2002/01/03 02:12:05 titus +# +# +# Initial ConfigParser implementation. +# # Revision 1.10 2001/11/26 22:55:56 richard # Feature: # . Added INSTANCE_NAME to configuration - used in web and email to identify
