Exemple #1
0
def main():
    #This line is so that the HTTPRequestHandler knows what component to route requests to.
    routing = [ ['/', WSGIFactory(WsgiConfig, url_list)] ]
    server = ServerCore(protocol=HTTPProtocol(routing),
                        port=port,
                        socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1))
    print 'Serving on port %s' % (port)
    server.run()
Exemple #2
0
class JsonRpcTCPServer(JsonRPCBase):
    def __init__(self, portnumber, workers = 5, debug = 1):
        JsonRPCBase.__init__(self, workers = workers, debug = debug)
        self.portnumber = portnumber
        self.server = None
    def start(self):
        if self.debug: print ('Starting JSON-RPC server on port %s' % self.portnumber)
        self.server = ServerCore( protocol = self.jsonprotocol, port = self.portnumber )
        self.server.run()
Exemple #3
0
class JsonRpcTCPServer(JsonRPCBase):
    def __init__(self, portnumber, workers = 5, debug = 1):
        JsonRPCBase.__init__(self, workers = workers, debug = debug)
        self.portnumber = portnumber
        self.server = None
    def start(self):
        if self.debug: print 'Starting JSON-RPC server on port %s' % self.portnumber
        self.server = ServerCore( protocol = self.jsonprotocol, port = self.portnumber )
        self.server.run()
Exemple #4
0
def run_program():
    """The main entry point for the application."""
    try:
        zip = zipfile.ZipFile(sys.argv[0], 'r')

        #prompt the user if this executable is corrupt
        corrupt = zip.testzip()
        if corrupt:
            Console.prompt_corrupt(corrupt)

        initializeLogger()
        home_path = os.environ['HOME']

        #prompt the user to install the necessary software if this is the first
        #time to run Kamaelia WebServe
        if not os.path.exists(home_path + '/kp.ini'):
            autoinstall(zip, home_path, 'Kamaelia WebServe')

        zip.close()

        #Extract data from Config Files and organize it into dictionaries
        configs = ParseConfigFile('~/kp.ini', DictFormatter())
        ServerConfig = configs['SERVER']
        WsgiConfig = configs['WSGI']
        StaticConfig = configs['STATIC']

        processPyPath(ServerConfig)
        normalizeWsgiVars(WsgiConfig)

        url_list = ParseUrlFile(WsgiConfig['url_list'])
        normalizeUrlList(url_list)

        StaticConfig['homedirectory'] = os.path.expanduser(
            StaticConfig['homedirectory'])
        log = os.path.expanduser(ServerConfig['log'])
        routing = [
            [
                StaticConfig['url'],
                MinimalFactory(StaticConfig['index'],
                               StaticConfig['homedirectory'])
            ],
            ["/", WSGIFactory(WsgiConfig, url_list, log)],
        ]

        kp = ServerCore(protocol=HTTPProtocol(routing),
                        port=int(ServerConfig['port']),
                        socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR,
                                       1))

        info('Serving on port %s' % (ServerConfig['port']), _logger_suffix)
    except:
        import traceback
        print 'There was an error!  Info is in %s/error.log' % (os.getcwd())
        file = open('error.log', 'a')
        traceback.print_exc(file=file)
        file.write('\n')
        file.close()
        sys.exit(1)
    try:
        kp.run()
    except KeyboardInterrupt:
        print "Halting server!"
    except:
        #Something's gone horribly wrong and the program doesn't know what to do
        #about it.
        import traceback
        traceback.print_exc()
        print "===========FATAL ERROR==========="
    finally:
        kp.stop()
        logging.shutdown()