Example #1
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    parser = argparse.ArgumentParser()
    parser.add_argument('--port', '-p', type=int, default="2367", help="Port to start the server with.")
    parser.add_argument('--bind', '-b', default="0.0.0.0", help="IP to bind the server to.")
    parser.add_argument('--conf', '-c', default=DEFAULT_CONFIG_PATH, help="Path to configuration file.")
    parser.add_argument('--verbose', '-v', action='count', default=0, help='Log level: v=warning, vv=info, vvv=debug.')
    parser.add_argument('--debug', '-d', action='store_true', default=False, help='Indicates whether to run wight api in debug mode.')
    options = parser.parse_args(args)

    log_level = LOGS[options.verbose].upper()
    logging.basicConfig(level=getattr(logging, log_level), format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    if not isabs(options.conf):
        logging.debug("Configuration file {0} is not absolute. Converting to abspath".format(options.conf))
        options.conf = abspath(options.conf)

    logging.info("Loading configuration file at {0}...".format(options.conf))

    config = Config.load(path=options.conf, conf_name=split(options.conf)[-1], lookup_paths=[
        os.curdir,
        expanduser('~'),
        '/etc/',
    ])

    logging.info("Using configuration file at {0}.".format(config.config_file))

    application = WightApp(config, log_level, options.debug)
    server = HTTPServer(application, xheaders=True)

    server.bind(options.port, options.bind)
    server.start(config.NUMBER_OF_FORKS)

    logging.info('-- Wight API started listening in %s:%d --' % (options.bind, options.port))
    try:
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        logging.info('')
        logging.info('-- Wight API closed by user interruption --')
Example #2
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    parser = argparse.ArgumentParser()
    parser.add_argument('--port',
                        '-p',
                        type=int,
                        default="2367",
                        help="Port to start the server with.")
    parser.add_argument('--bind',
                        '-b',
                        default="0.0.0.0",
                        help="IP to bind the server to.")
    parser.add_argument('--conf',
                        '-c',
                        default=DEFAULT_CONFIG_PATH,
                        help="Path to configuration file.")
    parser.add_argument('--verbose',
                        '-v',
                        action='count',
                        default=0,
                        help='Log level: v=warning, vv=info, vvv=debug.')
    parser.add_argument(
        '--debug',
        '-d',
        action='store_true',
        default=False,
        help='Indicates whether to run wight api in debug mode.')
    options = parser.parse_args(args)

    log_level = LOGS[options.verbose].upper()
    logging.basicConfig(
        level=getattr(logging, log_level),
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    if not isabs(options.conf):
        logging.debug(
            "Configuration file {0} is not absolute. Converting to abspath".
            format(options.conf))
        options.conf = abspath(options.conf)

    logging.info("Loading configuration file at {0}...".format(options.conf))

    config = Config.load(path=options.conf,
                         conf_name=split(options.conf)[-1],
                         lookup_paths=[
                             os.curdir,
                             expanduser('~'),
                             '/etc/',
                         ])

    logging.info("Using configuration file at {0}.".format(config.config_file))

    application = WightApp(config, log_level, options.debug)
    server = HTTPServer(application, xheaders=True)

    server.bind(options.port, options.bind)
    server.start(config.NUMBER_OF_FORKS)

    logging.info('-- Wight API started listening in %s:%d --' %
                 (options.bind, options.port))
    try:
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        logging.info('')
        logging.info('-- Wight API closed by user interruption --')
Example #3
0
 def get_app(self):
     cfg = Config(HEALTHCHECK_TEXT="works")
     return self.create_api_app(cfg)
Example #4
0
 def create_api_app(self, config=None):
     if not config:
         config = Config()
     config.MONGO_PORT = 7778
     return WightApp(config=config)
Example #5
0
    def create_web_app(self, config=None):
        if not config:
            config = Config()

        return WightWebApp(config=config)