* Move logging init to main app twisty
authorMark Hammond <mhammond@skippinet.com.au>
Wed, 11 Mar 2009 22:23:00 +1100
branchtwisty
changeset 72 c384433be638842c633c018a90aa57bf20933751
parent 71 3e37c73cb0001578c8390b4fa7168dd6b44d7251
child 73 39999bb623c8bc9bf41d48514b3a93ddd1b867f4
push id1
push userroot
push dateWed, 08 Apr 2009 01:46:05 +0000
* Move logging init to main app * Use '_id', a-la couch, for the account id
server/python/junius/config.py
--- a/server/python/junius/config.py
+++ b/server/python/junius/config.py
@@ -5,19 +5,19 @@ import ConfigParser, logging, os, os.pat
 class Config(object):
   COUCH_DEFAULTS = {'host': 'localhost', 'port': 5984, 'name': 'raindrop'}
   def __init__(self):
     self.parser = ConfigParser.SafeConfigParser()
 
     self.couches = {'local': self.COUCH_DEFAULTS.copy()}
     self.accounts = {}
 
-    # configuration and logging.  two great flavors that go together.
-    logging.basicConfig()
-    logging.getLogger().setLevel(logging.DEBUG) # XXX - read this from config.
+    # XXX - this seems wrong: most of the time the 'config' - particularly the
+    # list of accounts etc - will come from the DB.  The config file should only
+    # be used during bootstrapping.
     self.load()
 
 
   def dictifySection(self, section_name, defaults=None, name=None):
     '''
     Given a config section name, suck up its contents into a dictionary.  Poor
     man's type detection turns lowercase true/false into the boolean of that
     type, things that can be int()ed into ints, and otherwise things get to
@@ -50,18 +50,23 @@ class Config(object):
     for section_name in self.parser.sections():
       if section_name.startswith(COUCH_PREFIX):
         couch_name = section_name[len(COUCH_PREFIX):]
         self.couches[couch_name] = self.dictifySection(section_name,
                                                        self.COUCH_DEFAULTS)
 
       if section_name.startswith(ACCOUNT_PREFIX):
         account_name = section_name[len(ACCOUNT_PREFIX):]
-        self.accounts[account_name] = self.dictifySection(section_name, None,
-                                                          account_name)
+        acct = self.accounts[account_name] = \
+                    self.dictifySection(section_name, None, account_name)
+        if 'id' in acct:
+          acct['_id'] = acct['id']
+          del acct['id']
+        else:
+          acct['_id'] = acct['username']
 
     self.local_couch = self.couches['local']
     self.remote_couch = self.couches.get('remote') # may be None
 
 CONFIG = None
 def get_config():
   global CONFIG
   if CONFIG is None: