Exemplo n.º 1
0
def autoinstall(zip, dir, app_name):
    """
    This function essentially just takes a tar file from the data file within a
    zip executable and expands it into the users home directory.
    """
    prompt_text = 'It does not appear that %s has been installed.  Would you like to do so now? [y/n]' % \
                  (app_name)
    if not prompt_yesno(prompt_text):
        print '%s must be installed to continue.  Halting.' % (app_name)
        sys.exit(1)

    tar_mem = cStringIO.StringIO(zip.read('data/kpuser.tar'))
    kpuser_file = tarfile.open(name="-", fileobj=tar_mem, mode='r')
    kpuser_file.extractall(path=dir)

    kpuser_file.close()
    tar_mem.close()

    info('%s is now done installing.' % (app_name), _logger_suffix)
Exemplo n.º 2
0
def autoinstall(zip, dir, app_name):
    """
    This function essentially just takes a tar file from the data file within a
    zip executable and expands it into the users home directory.
    """
    prompt_text = 'It does not appear that %s has been installed.  Would you like to do so now? [y/n]' % \
                  (app_name)
    if not prompt_yesno(prompt_text):
        print '%s must be installed to continue.  Halting.' % (app_name)
        sys.exit(1)
    
    tar_mem = cStringIO.StringIO( zip.read('data/kpuser.tar') )
    kpuser_file = tarfile.open(name="-", fileobj=tar_mem, mode='r')
    kpuser_file.extractall(path=dir)
    
    kpuser_file.close()
    tar_mem.close()
    
    info('%s is now done installing.' % (app_name), _logger_suffix)
Exemplo n.º 3
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()