Mercurial > p > roundup > code
comparison roundup/config.py @ 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 | 13719594278b |
comparison
equal
deleted
inserted
replaced
| 481:a261b0bbba43 | 482:fdee2ff82b40 |
|---|---|
| 4 import string | 4 import string |
| 5 | 5 |
| 6 class Error(Exception): | 6 class Error(Exception): |
| 7 pass | 7 pass |
| 8 | 8 |
| 9 class UnknownInstanceLocation(Error): | |
| 10 pass | |
| 11 | |
| 12 class NoInstanceConfigFile(Error): | |
| 13 pass | |
| 14 | |
| 9 def debug_mode(): | 15 def debug_mode(): |
| 10 """ | 16 """ |
| 11 Returns the basic debug mode/level. | 17 Returns the basic debug mode/level. |
| 12 """ | 18 """ |
| 13 return os.environ.get('ROUNDUP_DEBUG', 0) | 19 return os.environ.get('ROUNDUP_DEBUG', 0) |
| 14 | 20 |
| 15 def load_base_config(): | 21 def loadBaseConfig(): |
| 16 """ | 22 """ |
| 17 Loads the base configuration for Roundup. | 23 Loads the base configuration for Roundup. |
| 18 """ | 24 """ |
| 19 | 25 |
| 20 c = ConfigParser.ConfigParser() | 26 c = ConfigParser.ConfigParser() |
| 62 self.base_path = base_path | 68 self.base_path = base_path |
| 63 | 69 |
| 64 def get(self, group, attr): | 70 def get(self, group, attr): |
| 65 return self.conf.get(group, attr) | 71 return self.conf.get(group, attr) |
| 66 | 72 |
| 67 def load_instances_config(self): | 73 def loadInstances(self): |
| 68 filename = string.strip(self.conf.get('base', 'instances')) | 74 filename = string.strip(self.conf.get('base', 'instances')) |
| 69 | 75 |
| 70 # if it looks like an absolute path, leave it alone; otherwise, | 76 # if it looks like an absolute path, leave it alone; otherwise, |
| 71 # add on the base path. | 77 # add on the base path. |
| 72 if filename[0] == '/' or filename[0] == '\\': | 78 if filename[0] == '/' or filename[0] == '\\': |
| 104 instance_names[dir] = name | 110 instance_names[dir] = name |
| 105 | 111 |
| 106 self.instance_dirs = instance_dirs | 112 self.instance_dirs = instance_dirs |
| 107 self.instance_names = instance_names | 113 self.instance_names = instance_names |
| 108 | 114 |
| 109 def get_instance_names(self): | 115 def getNames(self): |
| 110 return self.instance_dirs.keys() | 116 return self.instance_dirs.keys() |
| 111 | 117 |
| 112 def get_instance_name(self, dir): | 118 def getNameFromDir(self, dir): |
| 113 return self.instance_names[dir] | 119 if self.instance_names.has_key(dir): |
| 120 return self.instance_names[dir] | |
| 121 else: | |
| 122 raise UnknownInstanceLocation(dir) | |
| 114 | 123 |
| 115 def get_instance_dir(self, name): | 124 def getDirFromName(self, name): |
| 116 return self.instance_dirs[name] | 125 return self.instance_dirs[name] |
| 117 | 126 |
| 118 def load_instance_config(self, name): | 127 def loadConfig(self, name): |
| 119 instance_dir = self.get_instance_dir(name) | 128 instance_dir = self.getDirFromName(name) |
| 120 | 129 |
| 121 defaults_file = self.conf.get(name, 'defaults') | 130 defaults_file = self.conf.get(name, 'defaults') |
| 131 if not os.path.exists(defaults_file): | |
| 132 raise NoInstanceConfigFile("defaults file %s does not exist"%(defaults_file,)) | |
| 133 | |
| 122 config_file = self.conf.get(name, 'config') | 134 config_file = self.conf.get(name, 'config') |
| 135 if not os.path.exists(config_file): | |
| 136 raise NoInstanceConfigFile("%s does not exist"%(config_file,)) | |
| 123 | 137 |
| 124 defaults_dictionary = { 'homedir' : instance_dir, | 138 defaults_dictionary = { 'homedir' : instance_dir, |
| 125 'instance_name' : name, | 139 'instance_name' : name, |
| 126 } | 140 } |
| 127 | 141 |
| 151 | 165 |
| 152 def get(self, group, attr): | 166 def get(self, group, attr): |
| 153 return self.conf.get(group, attr) | 167 return self.conf.get(group, attr) |
| 154 | 168 |
| 155 if __name__ == '__main__': | 169 if __name__ == '__main__': |
| 156 base_config = load_base_config() | 170 base_config = loadBaseConfig() |
| 157 instances_config = base_config.load_instances_config() | 171 instances = base_config.loadInstances() |
| 158 | 172 |
| 159 for k in instances_config.get_instance_names(): | 173 for k in instances.getNames(): |
| 160 print "%s:%s"%(k, instances_config.get_instance_dir(k),) | 174 print "%s:%s"%(k, instances.getDirFromName(k),) |
