Ejemplo n.º 1
0
def start(server, host, port, workers, config, daemon):
    """Starts a production ready wsgi server.
    TODO: Figure out a way how to forward additional args to gunicorn
          without causing any errors.
    """
    if server == "gunicorn":
        try:
            from gunicorn.app.base import Application

            class FlaskBBApplication(Application):
                def __init__(self, app, options=None):
                    self.options = options or {}
                    self.application = app
                    super(FlaskBBApplication, self).__init__()

                def load_config(self):
                    config = dict([
                        (key, value) for key, value in iteritems(self.options)
                        if key in self.cfg.settings and value is not None
                    ])
                    for key, value in iteritems(config):
                        self.cfg.set(key.lower(), value)

                def load(self):
                    return self.application

            options = {
                "bind": "{}:{}".format(host, port),
                "workers": workers,
                "daemon": daemon,
            }
            FlaskBBApplication(create_app(config=config), options).run()
        except ImportError:
            raise FlaskBBCLIError(
                "Cannot import gunicorn. "
                "Make sure it is installed.",
                fg="red")

    elif server == "gevent":
        try:
            from gevent import __version__
            from gevent.pywsgi import WSGIServer
            click.secho("* Starting gevent {}".format(__version__))
            click.secho("* Listening on http://{}:{}/".format(host, port))
            http_server = WSGIServer((host, port), create_app(config=config))
            http_server.serve_forever()
        except ImportError:
            raise FlaskBBCLIError(
                "Cannot import gevent. "
                "Make sure it is installed.",
                fg="red")
Ejemplo n.º 2
0
def make_app(script_info):
    config_file = getattr(script_info, "config_file", None)

    if config_file is not None:
        # check if config is a file or a module that has to be imported
        if not os.path.exists(os.path.abspath(config_file)):
            try:
                import_string(config_file)
            except ImportStringError:
                logger.warning("Can't import config from '{}'. Falling back "
                               "to default config.".format(config_file))
                config_file = None
        else:
            logger.debug("Using config from: {}".format(config_file))

    else:
        # this walks back to flaskbb/ from flaskbb/flaskbb/cli/main.py
        # can't use current_app.root_path because it's not (yet) available
        config_dir = os.path.dirname(os.path.dirname(
            os.path.dirname(__file__)))
        config_file = os.path.join(config_dir, "flaskbb.cfg")

        if not os.path.exists(config_file):
            logger.warning("No config file specified. Falling back to default "
                           "config".format(config_file))
            config_file = None
        else:
            logger.debug(
                "Found config file 'flaskbb.cfg' in {}.".format(config_dir))
    return create_app(config_file)
Ejemplo n.º 3
0
def start(server, host, port, workers, config, daemon):
    """Starts a production ready wsgi server.
    TODO: Figure out a way how to forward additional args to gunicorn
          without causing any errors.
    """
    if server == "gunicorn":
        try:
            from gunicorn.app.base import Application

            class FlaskBBApplication(Application):
                def __init__(self, app, options=None):
                    self.options = options or {}
                    self.application = app
                    super(FlaskBBApplication, self).__init__()

                def load_config(self):
                    config = dict([
                        (key, value) for key, value in iteritems(self.options)
                        if key in self.cfg.settings and value is not None
                    ])
                    for key, value in iteritems(config):
                        self.cfg.set(key.lower(), value)

                def load(self):
                    return self.application

            options = {
                "bind": "{}:{}".format(host, port),
                "workers": workers,
                "daemon": daemon,
            }
            FlaskBBApplication(create_app(config=config), options).run()
        except ImportError:
            raise FlaskBBCLIError("Cannot import gunicorn. "
                                  "Make sure it is installed.", fg="red")

    elif server == "gevent":
        try:
            from gevent import __version__
            from gevent.pywsgi import WSGIServer
            click.secho("* Starting gevent {}".format(__version__))
            click.secho("* Listening on http://{}:{}/".format(host, port))
            http_server = WSGIServer((host, port), create_app(config=config))
            http_server.serve_forever()
        except ImportError:
            raise FlaskBBCLIError("Cannot import gevent. "
                                  "Make sure it is installed.", fg="red")
Ejemplo n.º 4
0
def make_app():
    ctx = click.get_current_context(silent=True)
    script_info = None
    if ctx is not None:
        script_info = ctx.obj

    config_file = getattr(script_info, "config_file", None)
    instance_path = getattr(script_info, "instance_path", None)
    return create_app(config_file, instance_path)
Ejemplo n.º 5
0
Archivo: app.py Proyecto: 0xsKu/flaskbb
def application():
    """application with context."""
    app = create_app(Config)

    ctx = app.app_context()
    ctx.push()

    yield app

    ctx.pop()
Ejemplo n.º 6
0
def application():
    """application with context."""
    app = create_app(Config)

    ctx = app.app_context()
    ctx.push()

    yield app

    ctx.pop()
Ejemplo n.º 7
0
def make_app(script_info):
    print "yjl file name:", __name__, '----make_app'
    config_file = getattr(script_info, "config_file")
    if config_file is not None:
        # check if config file exists
        if os.path.exists(os.path.abspath(config_file)):
            click.secho("[+] Using config from: {}".format(
                os.path.abspath(config_file)),
                        fg="cyan")
        # config file doesn't exist, maybe it's a module
        else:
            try:
                import_string(config_file)
                click.secho("[+] Using config from: {}".format(config_file),
                            fg="cyan")
            except ImportStringError:
                click.secho("[~] Config '{}' doesn't exist. "
                            "Using default config.".format(config_file),
                            fg="red")
                config_file = None
    else:
        # lets look for a config file in flaskbb's root folder
        # TODO: are there any other places we should look for the config?
        # Like somewhere in /etc/?

        # this walks back to flaskbb/ from flaskbb/flaskbb/cli/main.py
        # can't use current_app.root_path because it's not (yet) available
        config_dir = os.path.dirname(os.path.dirname(
            os.path.dirname(__file__)))
        config_file = os.path.join(config_dir, "flaskbb.cfg")
        if os.path.exists(config_file):
            click.secho(
                "[+] Found config file 'flaskbb.cfg' in {}".format(config_dir),
                fg="yellow")
            click.secho("[+] Using config from: {}".format(config_file),
                        fg="cyan")
        else:
            config_file = None
            click.secho("[~] Using default config.", fg="yellow")

    return create_app(config_file)
Ejemplo n.º 8
0
def make_app(script_info):
    config_file = getattr(script_info, "config_file")
    if config_file is not None:
        # check if config file exists
        if os.path.exists(os.path.abspath(config_file)):
            click.secho("[+] Using config from: {}".format(
                        os.path.abspath(config_file)), fg="cyan")
        # config file doesn't exist, maybe it's a module
        else:
            try:
                import_string(config_file)
                click.secho("[+] Using config from: {}".format(config_file),
                            fg="cyan")
            except ImportStringError:
                click.secho("[~] Config '{}' doesn't exist. "
                            "Using default config.".format(config_file),
                            fg="red")
                config_file = None
    else:
        click.secho("[~] Using default config.", fg="yellow")

    return create_app(config_file)
Ejemplo n.º 9
0
def make_app(script_info):
    config_file = getattr(script_info, "config_file")
    if config_file is not None:
        # check if config file exists
        if os.path.exists(os.path.abspath(config_file)):
            click.secho("[+] Using config from: {}".format(
                        os.path.abspath(config_file)), fg="cyan")
        # config file doesn't exist, maybe it's a module
        else:
            try:
                import_string(config_file)
                click.secho("[+] Using config from: {}".format(config_file),
                            fg="cyan")
            except ImportStringError:
                click.secho("[~] Config '{}' doesn't exist. "
                            "Using default config.".format(config_file),
                            fg="red")
                config_file = None
    else:
        # lets look for a config file in flaskbb's root folder
        # TODO: are there any other places we should look for the config?
        # Like somewhere in /etc/?

        # this walks back to flaskbb/ from flaskbb/flaskbb/cli/main.py
        # can't use current_app.root_path because it's not (yet) available
        config_dir = os.path.dirname(
            os.path.dirname(os.path.dirname(__file__))
        )
        config_file = os.path.join(config_dir, "flaskbb.cfg")
        if os.path.exists(config_file):
                click.secho("[+] Found config file 'flaskbb.cfg' in {}"
                            .format(config_dir), fg="yellow")
                click.secho("[+] Using config from: {}".format(config_file),
                            fg="cyan")
        else:
            config_file = None
            click.secho("[~] Using default config.", fg="yellow")

    return create_app(config_file)
Ejemplo n.º 10
0
from flask import current_app
from flask.ext.script import Manager, Shell, Server

from flaskbb import create_app
from flaskbb.extensions import db

from flaskbb.user.models import User, Group
from flaskbb.forum.models import Post, Topic, Forum

# Use the development configuration if available
try:
    from flaskbb.configs.development import DevelopmentConfig as Config
except ImportError:
    from flaskbb.configs.default import DefaultConfig as Config

app = create_app(Config)
manager = Manager(app)

# Run local server
manager.add_command("runserver", Server("localhost", port=8080))


# Add interactive project shell
def make_shell_context():
    return dict(app=current_app, db=db)
manager.add_command("shell", Shell(make_context=make_shell_context))


@manager.command
def initdb():
    """
Ejemplo n.º 11
0
import os
from flaskbb import create_app
from flaskbb.utils.helpers import ReverseProxyPathFix

_basepath = os.path.dirname(os.path.abspath(__file__))

# will throw an error if the config doesn't exist
flaskbb = create_app(config=os.path.join(_basepath, 'flaskbb.cfg'))

#  Uncomment to use the middleware
#flaskbb.wsgi_app = ReverseProxyPathFix(flaskbb.wsgi_app)
Ejemplo n.º 12
0
from flaskbb import create_app
from flaskbb.configs.example import ProductionConfig

flaskbb = create_app(config=ProductionConfig())
Ejemplo n.º 13
0
def make_app(script_info):
    config_file = getattr(script_info, "config_file", None)
    instance_path = getattr(script_info, "instance_path", None)
    return create_app(config_file, instance_path)
Ejemplo n.º 14
0
import os
from flaskbb import create_app
from flaskbb.utils.helpers import ReverseProxyPathFix

_basepath = os.path.dirname(os.path.abspath(__file__))

# will throw an error if the config doesn't exist
flaskbb = create_app(config='flaskbb.cfg')
flaskbb.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', 'postgres://flaskbb@localhost:5432/flaskbb')

#  Uncomment to use the middleware
#flaskbb.wsgi_app = ReverseProxyPathFix(flaskbb.wsgi_app)
Ejemplo n.º 15
0
import os
from flaskbb import create_app
from flaskbb.utils.helpers import ReverseProxyPathFix

_basepath = os.path.dirname(os.path.abspath(__file__))

# will throw an error if the config doesn't exist
flaskbb = create_app(config= _basepath + '/flaskbb.cfg')

#  Uncomment to use the middleware
#flaskbb.wsgi_app = ReverseProxyPathFix(flaskbb.wsgi_app)
Ejemplo n.º 16
0
                              prompt_bool)
from flask.ext.migrate import MigrateCommand

from flaskbb import create_app
from flaskbb.extensions import db
from flaskbb.utils.populate import (create_test_data, create_welcome_forum,
                                    create_admin_user, create_default_groups,
                                    create_default_settings)

# Use the development configuration if available
try:
    from flaskbb.configs.development import DevelopmentConfig as Config
except ImportError:
    from flaskbb.configs.default import DefaultConfig as Config

app = create_app(Config)
manager = Manager(app)

# Run local server
manager.add_command("runserver", Server("localhost", port=8080))

# Migration commands
manager.add_command('db', MigrateCommand)


# Add interactive project shell
def make_shell_context():
    return dict(app=current_app, db=db)
manager.add_command("shell", Shell(make_context=make_shell_context))

Ejemplo n.º 17
0
import os
from flaskbb import create_app
from flaskbb.utils.helpers import ReverseProxyPathFix

_basepath = os.path.dirname(os.path.abspath(__file__))

# will throw an error if the config doesn't exist
flaskbb = create_app(config='flaskbb.cfg')

#  Uncomment to use the middleware
#flaskbb.wsgi_app = ReverseProxyPathFix(flaskbb.wsgi_app)
Ejemplo n.º 18
0
import os
from flaskbb import create_app

basepath = os.path.dirname(os.path.abspath(__file__))

# will throw an error if the config doesn't exist
flaskbb = create_app(config=os.path.join(basepath, 'flaskbb.cfg'))
Ejemplo n.º 19
0
from flaskbb import create_app

# will throw an error if the config doesn't exist
flaskbb = create_app(config="flaskbb.cfg")
Ejemplo n.º 20
0
def make_app(script_info):
    config_file = getattr(script_info, "config_file", None)
    instance_path = getattr(script_info, "instance_path", None)
    return create_app(config_file, instance_path)