changeset 568:7eb5ecda4667

Fix many bugs in new forest config usage.
author Simon Cross <hodgestar@gmail.com>
date Tue, 20 Nov 2012 23:18:46 +0200
parents 16344424dfcc
children c296d10bd5f9
files mamba/forest.py
diffstat 1 files changed, 19 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mamba/forest.py	Tue Nov 20 22:08:05 2012 +0200
+++ b/mamba/forest.py	Tue Nov 20 23:18:46 2012 +0200
@@ -13,14 +13,14 @@
 import json
 
 app = Flask(__name__)
-app.config = None  # set later
 
 
 def path(ctype):
+    main = app.config.forest.main
     if ctype == "curated":
-        return os.path.join(app.config['LEVEL_FOLDER'], 'curated')
+        return os.path.join(main.level_folder, 'curated')
     elif ctype == "uncurated":
-        return os.path.join(app.config['LEVEL_FOLDER'], 'uncurated')
+        return os.path.join(main.level_folder, 'uncurated')
     abort(404, "Not found")
 
 
@@ -104,12 +104,13 @@
 
 
 def inform_cia(filename, log, branch='uncurated'):
-    if app.config.cia is None:
+    if app.config.forest.cia is None:
         return
+    cia = app.config.forest.cia
     msg = CIA_MSG_TEMPLATE % {
         'mamba_version': MAMBA_VERSION,
         'mamba_url': MAMBA_URL,
-        'project': app.config.cia.project,
+        'project': cia.project,
         'module': 'level-server',
         'branch': branch,
         'timestamp': int(time.time()),
@@ -118,12 +119,12 @@
         'file': filename,
         'log': log,
         }
-    srv = xmlrpclib.Server(app.config.cia.url)
+    srv = xmlrpclib.Server(cia.url)
     srv.hub.deliver(msg)
 
 
 def format_irker_message(project, filename, log, branch='uncurated'):
-    return "%(project)s: %(branch)s * %(filename): %(log)s" % {
+    return "%(project)s: %(branch)s * %(filename)s: %(log)s" % {
         "project": project,
         "filename": filename,
         "log": log,
@@ -132,9 +133,9 @@
 
 
 def inform_irker(filename, log, branch='uncurated'):
-    if app.config.irker is None:
+    if app.config.forest.irker is None:
         return
-    irker = app.config.irker
+    irker = app.config.forest.irker
     privmsg = format_irker_message(irker.project, filename, log, branch)
     message = json.dumps({"to": irker.channels, "privmsg": privmsg})
     try:
@@ -155,9 +156,13 @@
         self._config.read(filenames)
         self.main = self._parse("main")
         self.irker = self._parse("irker")
+        self.cia = self._parse("cia")
 
     def _parse(self, section):
-        conf = dict(self._config.items(section))
+        if self._config.has_section(section):
+            conf = dict(self._config.items(section))
+        else:
+            conf = {}
         return getattr(self, "_parse_%s" % section)(conf)
 
     def _parse_main(self, conf):
@@ -165,6 +170,7 @@
         main.host = conf.get('host', '0.0.0.0')
         main.port = int(conf['port'])
         main.level_folder = conf['level_folder']
+        return main
 
     def _parse_irker(self, conf):
         if 'project' not in conf:
@@ -176,7 +182,7 @@
         irker.channels = conf['channels']
         return irker
 
-    def _parse_cia(self, conf, cia):
+    def _parse_cia(self, conf):
         if 'project' not in conf:
             return None
         cia = self.SubConfig()
@@ -207,8 +213,8 @@
         print USAGE
         sys.exit(1)
 
-    app.config = ForestConfig([sys.argv[1]])
-    main = app.config.main
+    app.config.forest = ForestConfig([sys.argv[1]])
+    main = app.config.forest.main
 
     for ctype in ("curated", "uncurated"):
         folder = os.path.join(main.level_folder, ctype)