示例#1
0
class BackendServer:
    """Main truemix server class"""
    def __init__(self,configfn,background,verbose):
        """Initalisation for the server"""
        print "Starting Backend Server..."
        self.conf = Configuration(configfn)

        # TODO: Implement log_filename!!
        log_filename = "/dev/null"
        self.log = Logger(verbose,self.conf.log_filename)
        self.log.message("Opening database with '%s'" % self.conf.db_engine)

        try:
            self.db = Database(self.conf.db_engine, self.conf.db_username, 
		        self.conf.db_password, self.conf.db_host, self.conf.db_database)
        except:
            self.log.message("Unable connect to database with username, \
                password, host, and database name",4)
            self.log.message("Check your configuration file \
                /etc/truemix/truemix.conf for the correct options",4)
            sys.exit(2)
            
        self.log.message("Connected to database successfully.")
        self.log.message("Initialising Logic Object")
        self.logic = Logic(self.db, self.log)
        
        self.log.message("Checking database.")
        self.logic.users_init_check() #Check to see if there are any users
        
        self.log.message("Configuring XMLRPC interface")
        #Set up the XMLRPC server
        self.xmlrpcserver = XMLRPCServer("", self.conf.port_number, self.logic)

    def main(self):
        self.log.message("Starting XMLRPC interface")
        self.xmlrpcserver.start_serving()