Exemplo n.º 1
0
    def start(self, blocking=True):
        """Configure and start the server."""
        self.configure()
        config = {'db_url':self.config['db_url'],
                  'map_file':self.config['map_file']}
        # can be something to consider
        obj = WebServerManager(config) # mount the web server manager
        if self.config.get('profiler', 0):
            from pyquerybuilder.web.profiler import cachegrind
            cherrypy.tools.cachegrind = cherrypy.Tool('before_handler', \
                    cachegrind, priority=100)
            toolconfig = {'/' : {'tools.cachegrind.on' : True}, }
            tree.mount(obj, '/', toolconfig)
        else:
            tree.mount(obj, '/')

        # mount static document directory
        dirs = self.config['doc_dir'].split('/html')
        doc_config = {'/':
                       { 'tools.staticdir.root': dirs[0],
                         'tools.staticdir.dir': 'html',
                         'tools.staticdir.on': True,}}
        tree.mount(None, '/doc', doc_config)

        engine.start()
        if  blocking:
            engine.block()
Exemplo n.º 2
0
    def start(self, blocking=True):
        """Configure and start the server."""
        self.configure()
        url_base = self.config['web_server']['url_base']
        config = self.config.get('web_server', {})
        config['engine'] = engine
        # import DASWebServices after we run self.configure which register secmodv2
        from DAS.web.das_web_srv import DASWebService
        obj = DASWebService(self.config)
        tree.mount(obj, url_base)  # mount web server

        self.setup_kws_server()

        print("### DAS web server, PID=%s" % self.pid)
        print(pformat(tree.apps))
        print(pformat(self.config))
        pid = PIDFile(engine, self.pid)
        pid.subscribe()
        engine.start()
        print("### DAS server runs with %s threads" \
                % threading.active_count())
        threads = threading.enumerate()
        try:
            threads.sort()
        except:
            pass
        for thr in threads:
            print(thr)
        if blocking:
            engine.block()
Exemplo n.º 3
0
    def start(self, blocking=True):
        """Configure and start the server."""
        self.configure()
        url_base = self.config['web_server']['url_base']
        config = self.config.get('web_server', {})
        config['engine'] = engine
        obj = DASWebService(self.config)
        tree.mount(obj, url_base) # mount web server

        self.setup_kws_server()

        print "### DAS web server, PID=%s" % self.pid
        print pformat(tree.apps)
        print pformat(self.config)
        pid = PIDFile(engine, self.pid)
        pid.subscribe()
        engine.start()
        print "### DAS server runs with %s threads" \
                % threading.active_count()
        threads = threading.enumerate()
        threads.sort()
        for thr in threads:
            print thr
        if  blocking:
            engine.block()
Exemplo n.º 4
0
def startup(config):
    server.socket_host = config.web_address
    server.socket_port = config.web_port
    tree.mount(index)
    info('starting server on %s:%d' % (config.web_address, config.web_port))
    engine.start()
    engine.block()
Exemplo n.º 5
0
    def start(self, blocking=True):
        """Configure and start the server."""
        self.configure()
        url_base = self.config['web_server']['url_base']
        config = self.config.get('web_server', {})
        config['engine'] = engine
        # import DASWebServices after we run self.configure which register secmodv2
        from DAS.web.das_web_srv import DASWebService
        obj = DASWebService(self.config)
        tree.mount(obj, url_base) # mount web server

        self.setup_kws_server()

        print("### DAS web server, PID=%s" % self.pid)
        print(pformat(tree.apps))
        print(pformat(self.config))
        pid = PIDFile(engine, self.pid)
        pid.subscribe()
        engine.start()
        print("### DAS server runs with %s threads" \
                % threading.active_count())
        threads = threading.enumerate()
        try:
            threads.sort()
        except:
            pass
        for thr in threads:
            print(thr)
        if  blocking:
            engine.block()
Exemplo n.º 6
0
def run_interactive():
    """The same as cherrypy.quickstart, but don't block."""
    from cherrypy import engine
    
    # This is what quickstart does but we don't block
    engine.signals.subscribe()
    engine.start()
Exemplo n.º 7
0
    def start(self, blocking=True):
        """Configure and start the server."""
        self.configure()
        config['engine'] = engine

        WebSocketPlugin(engine).subscribe()
        cherrypy.tools.websocket = WebSocketTool()
        
        base_url = config.get('ws_base_url', '/websocket')
        wsconfig = {'/ws' :{
                           'tools.websocket.on': True,
                           'tools.websocket.handler_cls': DBSWebSocketHandler
                           }}
        tree.mount(self, base_url, wsconfig) # mount WebSocket service
        obj = DataService()
        tree.mount(obj, '/dbs') # mount another data service
        print "Applications:", pformat(tree.apps)
        print "Configuration:", pformat(self.config)

        pid = PIDFile(engine, self.pid)
        pid.subscribe()

        engine.start()
        print "### number of threads with web engine %s" \
                % threading.active_count()
        if  blocking:
            engine.block()
Exemplo n.º 8
0
 def start(self):
     conf = self._config.as_dict()
     ssl_conf = self.__configure_ssl()
     conf.update(ssl_conf)
     self._logger.info("Starting server with config: {}".format(conf))
     cherrypy.config.update(conf)
     engine.start()
     self._logger.info("Server started")
     engine.block()
Exemplo n.º 9
0
 def start(self, blocking=True):
     """Configure and start the server."""
     self.configure()
     config = {} # can be something to consider
     obj = WebServerManager(config) # mount the web server manager
     tree.mount(obj, '/')
     engine.start()
     if  blocking:
         engine.block()
Exemplo n.º 10
0
def run_server(app):
    app_logged = TransLogger(application=app)
    tree.graft(app_logged, '/')
    config.update({
        'engine.autoreload.on': True,
        'log.screen': True,
        'server.socket_port': 5432,
        'server.socket_host': '0.0.0.0'
    })
    engine.start()
    engine.block()
Exemplo n.º 11
0
 def launch_app(app, host="local",port=8080,prefix='/'):
     app.prefix = prefix
     webapp = app.getRoot()
     if host!="local":
         cherrypy.server.socket_host = '0.0.0.1'
     cherrypy.server.socket_port = port
     tree.mount(webapp,prefix)
     if hasattr(engine, "signal_handler"):
         engine.signal_handler.subscribe()
     if hasattr(engine, "console_control_handler"):
         engine.console_control_handler.subscribe()
     engine.start()
     webbrowser.open("http://127.0.0.1:8080")    
     engine.block()
Exemplo n.º 12
0
    def start(self, blocking=True):
        """Configure and start the server."""
        self.configure()
        url_base = self.config['web_server']['url_base']
        config = self.config.get('web_server', {})
        config['engine'] = engine
        obj = DASWebService(self.config)
        tree.mount(obj, url_base) # mount web server

        # DBS/Phedex Service
        if  self.config.has_key('dbs_phedex') and \
            self.config['dbs_phedex']['urls']:
            uri  = self.config['mongodb']['dburi']
            urls = {}
            for url in self.config['dbs_phedex']['urls']:
                if  url.find('phedex') != -1:
                    urls['phedex'] = url
                else:
                    urls['dbs'] = url
            expire = self.config['dbs_phedex'].get('expire', 3600)
            obj = DBSPhedexService(uri, urls, expire)
            tree.mount(obj, '/dbs_phedex')
            print "### DAS web server mounted /dbs_phedex service"

        print "### DAS web server, PID=%s, #threads=%s" \
                % (self.pid, threading.active_count())
#        for thr in threading.enumerate():
#            print thr
        print pformat(tree.apps)
        print pformat(self.config)
        pid = PIDFile(engine, self.pid)
        pid.subscribe()
        engine.start()
        print "### number of threads with web engine %s" \
                % threading.active_count()
        if  blocking:
            engine.block()
def main(argv):
  # Process configuration files and configure modules.
  idigbio_conf_path = join(current_dir, 'etc', 'idigbio.conf')
  config = ConfigParser.ConfigParser()
  config.read(idigbio_conf_path)
  api_endpoint = config.get('iDigBio', 'idigbio.api_endpoint')
  worker_thread_count = config.get('iDigBio', 'idigbio.worker_thread_count')
  disable_startup_service_check = config.get(
    'iDigBio', 'devmode_disable_startup_service_check')
  
  dataingestion.services.api_client.init(api_endpoint)
  dataingestion.services.ingestion_manager.init(worker_thread_count)
  cherrypy.config.update(join(current_dir, 'etc', 'http.conf'))
  
  engine_conf_path = join(current_dir, 'etc', 'engine.conf')
  cherrypy.config.update(engine_conf_path)
  cherrypy.config.update({"tools.staticdir.root": current_dir + "/www"})
  cherrypy.tree.mount(DataIngestionUI(), '/', config=engine_conf_path)
  cherrypy.tree.mount(DataIngestionService(), '/services',
            config=engine_conf_path)
  
  # Process command-line arguments:
  parser = argparse.ArgumentParser()
  parser.add_argument("--newdb", action="store_true", help='create a new db file')
  parser.add_argument("-d", "--debug", action="store_true")
  parser.add_argument("-q", "--quiet", action="store_true")
  args = parser.parse_args()

  if args.debug:
    debug_mode = True
    log_level = logging.DEBUG
  else:
    debug_mode = False
    log_level = logging.WARNING
    cherrypy.config.update({"environment": "production"})
  
  if args.quiet:
    quiet_mode = True
    if debug_mode:
      raise Exception("The --quiet or -q flags are not intended to be "
              "used with the --debug or -d flags.")
  else:
    quiet_mode = False

  # Configure the logging mechanisms
  # Default log level to DEBUG and filter the logs for console output.
  logging.getLogger().setLevel(logging.DEBUG)
  logging.getLogger("cherrypy").setLevel(logging.INFO) # cherrypy must be forced
  svc_log = logging.getLogger('iDigBioSvc')
  handler = logging.StreamHandler()
  handler.setFormatter(
      logging.Formatter(
          '%(asctime)s %(thread)d %(name)s %(levelname)s - %(message)s'))
  # User-specified log level only controls console output.
  handler.setLevel(log_level)
  svc_log.addHandler(handler)
  log_folder = appdirs.user_log_dir(APP_NAME, APP_AUTHOR)
  if not exists(log_folder):
    os.makedirs(log_folder)
  log_file = join(log_folder, "idigbio.ingest.log")
  print "Log file:", log_file
  handler = logging.handlers.RotatingFileHandler(log_file, backupCount=10)
  handler.setFormatter(
      logging.Formatter(
          '%(asctime)s %(thread)d %(name)s %(levelname)s - %(message)s'))
  handler.setLevel(logging.DEBUG)
  handler.doRollover()
  svc_log.addHandler(handler)
    
  # Set up the DB.
  data_folder = appdirs.user_data_dir(APP_NAME, APP_AUTHOR)
  if not exists(data_folder):
    os.makedirs(data_folder)
  db_file = join(data_folder, "idigbio.ingest.db")
  if args.newdb:
    _move_db(data_folder, db_file)
    logger.info("Creating a new DB file.")

  logger.info("Use DB file: {0}".format(db_file))
  dataingestion.services.model.setup(db_file)
  
  # Set up the user config.
  user_config_path = join(data_folder, USER_CONFIG_FILENAME)
  user_config.setup(user_config_path)
  user_config.set_user_config(
      'devmode_disable_startup_service_check', disable_startup_service_check)
  
  # Set up/start server.
  if hasattr(engine, "signal_handler"):
    engine.signal_handler.subscribe()
  if hasattr(engine, "console_control_handler"):
    engine.console_control_handler.subscribe()
  cherrypy.log("Starting...", "main")

  atexit.register(
    _logout_user_if_configured, user_config_path, data_folder, db_file)

  engine.start()
  if not debug_mode and not quiet_mode:
    # In a proper run, the text written here will be the only text output
    # the end-user sees: Keep it short and simple.
    print("Starting the iDigBio Data Ingestion Tool...")
    try:
      import webbrowser
      webbrowser.open(
          "http://127.0.0.1:{0}".format(cherrypy.config['server.socket_port']))
      logger.info("Webbrowser is opened.")
    except ImportError:
      # Gracefully fall back
      print("Open http://127.0.0.1:{0} in your webbrowser.".format(
          cherrypy.config['server.socket_port']))
    print("Close this window or hit ctrl+c to stop the local iDigBio Data "
          "Ingestion Tool.")
  engine.block()