示例#1
0
 def loadbabblersfromdb( babbler ):
 #--------------------------------------------------------------------------
     """
     Read saved babbler table from database and load them into 'self.babblers'.
     
     Calls 'babbler.loadbabblers' to process the data received from the disk.
     """
     db = CouchDBManager("localhost", "5984", "gossip_crackertable")
     try:            
         documents = db.getdocumentlist()
         for doc in documents:
             if doc != "self":
                 data = db.read(doc)
                 babbler.loadbabbler(doc, simplejson.loads(data))
     except KeyboardInterrupt:
         raise
     except:
         traceback.print_exc()
示例#2
0
 def loadconfiguration():
 #------------------------------------------------------------------------- 
     """
     Load configuration file in JSON notation specifying debug options, 
     list of host/port which to listen to and paths to certification files.
     
     For example configuration data see 'database_setup.py'.
     
     Anything missing will cause error the ensure a proper configuration 
     in order to be able to work correctly.
     
     :raise Exception: any error will be printed as traceback and raised
                         without further description
     """
     
     try:
         db = CouchDBManager("localhost", "5984", "gossip_crackertable")
         jsondata = db.read("self")
         
         config = simplejson.loads(jsondata)
         
         config["debug"] = int(config["debug"])
         config["verbose"]  = int(config["verbose"])
         config["maxconv"] = int(config["maxconv"])
         
         if not isinstance(config["host"], list) or not isinstance(config["port"], list):
             raise ValueError("Host and port must be provided as a list in the configuration file.")
     
         if not config.has_key("version"):
             config["version"] = 1
     except KeyboardInterrupt:
         raise
     except:
         traceback.print_exc()
         
         raise Exception("Configuration file couldn't be loaded")
     
     return config