Example #1
0
def start_server():
    options = init_tornado_options()
    # init socket options
    socket.setdefaulttimeout(options.socket_timeout)
    # server settings for application
    app_settings = {
        'debug': options.debug,
        'template_path': os.path.join(os.path.dirname(__file__), 'template'),
        'static_path': os.path.join(os.path.dirname(__file__), 'static'),
        'cookie_secret': 'ngYrl3h4TRGF9KM6zb5x2Q/v5sH8T0BbsOisjQIL95Q='
    }
    # cookie_secret generated by "base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes)"

    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    log_file = 'sys.log'
    # timelog = logging.handlers.TimedRotatingFileHandler(log_file, 'midnight', 1, 0)
    # logger.addHandler(timelog)

    datefmt = '%Y-%m-%d %H:%M:%S'
    fmt = '%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s'
    formatter = LogFormatter(color=True, datefmt=datefmt, fmt=fmt)
    root_log = logging.getLogger()
    for logHandler in root_log.handlers:
        logHandler.setFormatter(formatter)

    logging.info('options: {}'.format(options.items()))

    # set default handler, just response 404
    router = list()
    # load routing
    load_routings(router=router)
    # else
    router.append((ur'/.*', handlers.APINotFoundHandler))
    # setting to handlers
    handlers.APIBaseHandler.static_config.update(config.config)

    def shutdown(sig, frame):
        logging.info("shutting down on signal:%s", sig)
        tornado.ioloop.IOLoop.instance().stop()

    signal.signal(signal.SIGINT, shutdown)
    signal.signal(signal.SIGTERM, shutdown)

    # create tornado application and httpserver
    application = tornado.web.Application(router, **app_settings)
    httpserver = tornado.httpserver.HTTPServer(application)
    httpserver.bind(options.port, backlog=options.backlog)
    httpserver.start(1 if options.debug else options.workers)
    # ioloop start
    tornado.ioloop.IOLoop.instance().start()
Example #2
0
import json

from fastapi.testclient import TestClient

from app.app import app
import unittest
from urllib.parse import quote, quote_plus

from app import logger
import logging

logger.setLevel(logging.DEBUG)
from siibra import logger

logger.setLevel(logging.DEBUG)

client = TestClient(app)

ICBM_152_SPACE_ID = 'minds/core/referencespace/v1.0.0/dafcffc5-4826-4bf1-8ff6-46b8a31ff8e2'
ATLAS_ID = 'juelich/iav/atlas/v1.0.0/1'
PARCELLATION_ID = 'minds%2Fcore%2Fparcellationatlas%2Fv1.0.0%2F94c1125b-b87e-45e4-901c-00daee7f2579-290'
INVALID_PARCELLATION_ID = 'INVALID_PARCELLATION_ID'
REGION_NAME = 'Ch 123 (Basal Forebrain) - left hemisphere'
REGION_ID = 'minds%2Fcore%2Fparcellationregion%2Fv1.0.0%2Fbb111a95-e04c-4987-8254-4af4ed8b0022'
REGION_BASAL = 'basal forebrain'
REGION_AREA_3B_RIGHT = 'Area 3b (PostCG) right'
HOC1_LEFT_REGION_NAME = 'Area hOc1 (V1, 17, CalcS) left'
HOC1_RIGHT_REGION_NAME = 'Area+hOc1+%28V1%2C+17%2C+CalcS%29+right'
SF_AMY_LEFT_NAME = 'SF (Amygdala) left '
HOC1_REGION_ID = 'minds%2Fcore%2Fparcellationregion%2Fv1.0.0%2F5151ab8f-d8cb-4e67-a449-afe2a41fb007'
INVALID_REGION_NAME = 'INVALID_REGION'
Example #3
0
print(f"Set Default App Language ...")
setattr(app.config, 'CURRENT_LANGUAGE', None)

print(f"Set Global multilanguage strings ...")

# GV -------------------------------------------------------------------

# GV Global JINJA 2 Functions
app.jinja_env.globals.update(has_access=has_access)
# GV -------------------------------------------------------------------

if __name__ == '__main__':
    app_ctx = app.app_context()
    app_ctx.push()

    logger.setLevel(C.log_level)
    db.logger = logger

    if logger is not None:
        db.logger = logger
        logger.info("****** Butler Server *****************xxx")
        logger.info(" * %s: as '%s' Using configuration: '%s'" %
                    (sys.argv[0], getpass.getuser(), config_file))
        logger.info(" * %s: db connection is '%s'" % (sys.argv[0], db))
        logger.info("*****************************************")
        for variable in os.environ:
            logger.debug("%s=%s" % (variable, os.environ.get(variable)))
        logger.debug("logger                = %s" % logger)
        logger.debug("mail                  = %s" % mail)
        logger.debug("db                    = %s" % db)
        logger.debug("db.logger             = %s" % db.logger)
Example #4
0
 def update_log_level(self):
         settings_level = self.json_map.get('log_level', self.log_level)
         syslog('setting log level from {} to {}'.format(self.log_level, settings_level))
         logger.setLevel(log_levels[settings_level])