Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. import os
  2. import sys
  3.  
  4. import cherrypy
  5.  
  6. import headphones
  7.  
  8. from headphones.webserve import WebInterface
  9.  
  10. def initialize(options={}):
  11.  
  12.  
  13.     cherrypy.config.update({
  14.                 'log.screen':           True,
  15.                 'server.thread_pool':   10,
  16.                 'server.socket_port':   options['http_port'],
  17.                 'server.socket_host':   options['http_host'],
  18.                 'engine.autoreload_on': False,
  19.         })
  20.  
  21.     conf = {
  22.         '/': {
  23.             'tools.staticdir.root': os.path.join(headphones.PROG_DIR, 'data')
  24.         },
  25.         '/images':{
  26.             'tools.staticdir.on': True,
  27.             'tools.staticdir.dir': "images"
  28.         },
  29.         '/css':{
  30.             'tools.staticdir.on': True,
  31.             'tools.staticdir.dir': "css"
  32.         },
  33.         '/js':{
  34.             'tools.staticdir.on': True,
  35.             'tools.staticdir.dir': "js"
  36.         }
  37.     }
  38.    
  39.    
  40.     if options['http_password'] != "":
  41.         conf['/'].update({
  42.             'tools.auth_basic.on': True,
  43.             'tools.auth_basic.realm': 'Headphones',
  44.             'tools.auth_basic.checkpassword':  cherrypy.lib.auth_basic.checkpassword_dict(
  45.                     {options['http_username']:options['http_password']})
  46.         })
  47.        
  48.  
  49.     # Prevent time-outs
  50.     cherrypy.engine.timeout_monitor.unsubscribe()
  51.    
  52.     cherrypy.tree.mount(WebInterface(), options['http_root'], config = conf)
  53.    
  54.     try:
  55.         cherrypy.process.servers.check_port(options['http_host'], options['http_port'])
  56.         cherrypy.engine.start()
  57.     except IOError:
  58.         print 'Failed to start on port: %i. Is something else running?' % (options['http_port'])
  59.         sys.exit(0)
  60.  
  61.    
  62.     cherrypy.engine.wait(cherrypy.engine.states.STARTED)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement