Example #1
0
def launch_browser(host, port, root):
    if host == '0.0.0.0':
        host = 'localhost'
    
    try:
        webbrowser.open('http://%s:%i%s' % (host, port, root))
    except Exception, e:
        logger.error("Could not launch browser: %s" % e)
Example #2
0
def initialize(options={}):
    
    cherrypy.config.update({
                'log.screen':            False,
                'server.thread_pool':     10,
                'server.socket_port':     options['http_port'],
                'server.socket_host':     options['http_host'],
                'engine.autoreload_on':    False,
        })

    conf = {
        '/': {
            'tools.staticdir.root': os.path.join(minstrel.ROOT, 'www')
        },
        '/images':{
            'tools.staticdir.on': True,
            'tools.staticdir.dir': "images"
        },
        '/css':{
            'tools.staticdir.on': True,
            'tools.staticdir.dir': "css"
        },
        '/js':{
            'tools.staticdir.on': True,
            'tools.staticdir.dir': "js"
        },
        '/favicon.ico':{
            'tools.staticfile.on': True,
            'tools.staticfile.filename': "images/favicon.ico"
        }
    }
    
    if options['http_pass'] != "":
        
        conf['/'].update({
            'tools.auth_basic.on': True,
            'tools.auth_basic.realm': 'Minstrel',
            'tools.auth_basic.checkpassword':  cherrypy.lib.auth_basic.checkpassword_dict(
                    {options['http_user']:options['http_pass']})
        })
        

    # Prevent time-outs
    cherrypy.engine.timeout_monitor.unsubscribe()
    
    logger.info("HTTP ROOT: " + options['http_root'])
    
    cherrypy.tree.mount(MinstrelInterface(), options['http_root'], config = conf)
    
    try:
        cherrypy.process.servers.check_port(options['http_host'], options['http_port'])
        cherrypy.server.start()
    except IOError:
        logger.error("Could not bind to port {0} - Is Minstrel already running?".format(options['http_port']))
        sys.exit(0)
    
    cherrypy.server.wait()