예제 #1
0
    def __init__(self,
                 app,
                 hostname='localhost',
                 port=9000,
                 pidfile='/var/run/decanter.pid',
                 development=False):
        self.app = app
        self.hostname = hostname
        self.port = int(port)
        self.pidfile = pidfile
        self.config = Config()

        if 'timezone' in self.config:
            os.environ['TZ'] = self.config.timezone

        if 'memfile_max' in self.config:
            bottle.Request.MEMFILE_MAX = self.config.memfile_max

        # remove all default bottle plugins
        bottle.uninstall(True)
        bottle.debug(self.config.debug)

        # install plugins
        self.install_plugins(config=self.config)
        if self.config.debug or not development:
            stdout = os.popen('tty').read().strip()
            stderr = os.popen('tty').read().strip()

        if not development:
            super(Decanter, self).__init__(pidfile,
                                           stdout=stdout,
                                           stderr=stderr)
예제 #2
0
    def __init__(self, app, hostname='localhost', port=9000,
                 pidfile='/var/run/decanter.pid', development=False):
        self.app = app
        self.hostname = hostname
        self.port = int(port)
        self.pidfile = pidfile
        self.config = Config()

        if 'timezone' in self.config:
            os.environ['TZ'] = self.config.timezone

        if 'memfile_max' in self.config:
            bottle.Request.MEMFILE_MAX = self.config.memfile_max

        # remove all default bottle plugins
        bottle.uninstall(True)
        bottle.debug(self.config.debug)

        # install plugins
        self.install(plugins=self.config.plugins)
        if self.config.debug or not development:
            stdout = os.popen('tty').read().strip()
            stderr = os.popen('tty').read().strip()

        if not development:
            super(Decanter, self).__init__(
                pidfile, stdout=stdout, stderr=stderr)
예제 #3
0
def run_rest_server(manager, debug, num_processes, num_threads):
    """Runs the REST server."""
    logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)

    host = manager.config['server']['rest_host']
    port = manager.config['server']['rest_port']

    install(SaveEnvironmentPlugin(manager))
    install(CheckJsonPlugin())
    install(oauth2_provider.check_oauth())
    install(CookieAuthenticationPlugin())
    install(UserVerifiedPlugin())
    install(PublicUserPlugin())
    install(ErrorAdapter())

    # Replace default JSON plugin with one that handles datetime objects
    # Note: ErrorAdapter must come before JSONPlugin to catch serialization errors
    uninstall(JSONPlugin())
    install(JSONPlugin(json_dumps=DatetimeEncoder().encode))

    # JsonApiPlugin must come after JSONPlugin, to inspect and modify response
    # dicts before they are serialized into JSON
    install(JsonApiPlugin())

    for code in range(100, 600):
        default_app().error(code)(error_handler)

    root_app = Bottle()
    root_app.mount('/rest', default_app())

    # Look for templates in codalab-worksheets/views
    bottle.TEMPLATE_PATH = [
        os.path.join(
            os.path.dirname(
                os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
            'views')
    ]

    # Increase the request body size limit to 8 MiB
    bottle.BaseRequest.MEMFILE_MAX = 8 * 1024 * 1024

    # We use gunicorn to create a server with multiple processes, since in
    # Python a single process uses at most 1 CPU due to the Global Interpreter
    # Lock.
    sys.argv = sys.argv[:1]  # Small hack to work around a Gunicorn arg parsing
    # bug. None of the arguments to cl should go to
    # Gunicorn.
    run(
        app=root_app,
        host=host,
        port=port,
        debug=debug,
        server='gunicorn',
        workers=num_processes,
        worker_class='gthread',
        threads=num_threads,
        worker_tmp_dir='/tmp',  # don't use globally set tempdir
        timeout=5 * 60,
    )
예제 #4
0
def run_rest_server(manager, debug, num_processes, num_threads):
    """Runs the REST server."""
    host = manager.config['server']['rest_host']
    port = manager.config['server']['rest_port']

    install(SaveEnvironmentPlugin(manager))
    install(CheckJsonPlugin())
    install(LoggingPlugin())
    install(oauth2_provider.check_oauth())
    install(CookieAuthenticationPlugin())
    install(UserVerifiedPlugin())
    install(PublicUserPlugin())
    install(ErrorAdapter())

    # Replace default JSON plugin with one that handles datetime objects
    # Note: ErrorAdapter must come before JSONPlugin to catch serialization errors
    uninstall(JSONPlugin())
    install(JSONPlugin(json_dumps=DatetimeEncoder().encode))

    # JsonApiPlugin must come after JSONPlugin, to inspect and modify response
    # dicts before they are serialized into JSON
    install(JsonApiPlugin())

    for code in xrange(100, 600):
        default_app().error(code)(error_handler)

    root_app = Bottle()
    root_app.mount('/rest', default_app())

    # Look for templates in codalab-worksheets/views
    bottle.TEMPLATE_PATH = [
        os.path.join(
            os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'views'
        )
    ]

    # Increase the request body size limit to 8 MiB
    bottle.BaseRequest.MEMFILE_MAX = 8 * 1024 * 1024

    # We use gunicorn to create a server with multiple processes, since in
    # Python a single process uses at most 1 CPU due to the Global Interpreter
    # Lock.
    sys.argv = sys.argv[:1]  # Small hack to work around a Gunicorn arg parsing
    # bug. None of the arguments to cl should go to
    # Gunicorn.
    run(
        app=root_app,
        host=host,
        port=port,
        debug=debug,
        server='gunicorn',
        workers=num_processes,
        worker_class='gthread',
        threads=num_threads,
        worker_tmp_dir='/tmp',  # don't use globally set tempdir
        timeout=5 * 60,
    )
예제 #5
0
def create_rest_app(manager=CodaLabManager()):
    """Creates and returns a rest app."""
    install(SaveEnvironmentPlugin(manager))
    install(CheckJsonPlugin())
    install(oauth2_provider.check_oauth())
    install(CookieAuthenticationPlugin())
    install(UserVerifiedPlugin())
    install(PublicUserPlugin())
    install(ErrorAdapter())

    # Replace default JSON plugin with one that handles datetime objects
    # Note: ErrorAdapter must come before JSONPlugin to catch serialization errors
    uninstall(JSONPlugin())
    install(JSONPlugin(json_dumps=DatetimeEncoder().encode))

    # JsonApiPlugin must come after JSONPlugin, to inspect and modify response
    # dicts before they are serialized into JSON
    install(JsonApiPlugin())

    for code in range(100, 600):
        default_app().error(code)(error_handler)

    root_app = Bottle()
    root_app.mount('/rest', default_app())

    # Look for templates in codalab-worksheets/views
    bottle.TEMPLATE_PATH = [
        os.path.join(
            os.path.dirname(
                os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
            'views')
    ]

    # Increase the request body size limit to 8 MiB
    bottle.BaseRequest.MEMFILE_MAX = 8 * 1024 * 1024
    return root_app
 def __init__(self, json_dumps=json_dumps):
     uninstall('json')
     self.json_dumps = json_dumps
예제 #7
0
 def __init__(self, json_dumps=json_dumps):
     uninstall('json')
     self.json_dumps = json_dumps
예제 #8
0
import httplib
httplib.responses[422] = 'Unprocessable Entity'

import bottle
app = application = bottle.app()
app.catchall = True

import version
import codec
#import http
#import model
import config
import database
#import gitlab
#import response
#import aaa
#import provider

config.loadconfig(app)
database.start(app)

# install better json plugin
bottle.uninstall(bottle.JSONPlugin)
class ExtraJSONPlugin(bottle.JSONPlugin):
	def __init__(self):
		super(ExtraJSONPlugin, self).__init__(json_dumps=codec.json_codec.encode)
bottle.install(ExtraJSONPlugin())

# roll the bones
import rest
예제 #9
0
 def __init__(self, json_dumps=json.dumps, json_util=json_util.default):
     uninstall('json')
     self.json_dumps = json_dumps
     self.json_util = json_util
예제 #10
0
 def __init__(self, dumps=dumps):
     uninstall('json')
     self.dumps = dumps
예제 #11
0
 def __init__(self, json_dumps=json_dumps):
     bottle.uninstall("json")
     self.json_dumps = json_dumps