Example #1
0
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. caliSurfApp.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # initialize the cache
    cache.init_app(app)

    # initialize the debug tool bar
    debug_toolbar.init_app(app)

    # initialize SQLAlchemy
    # db.init_app(app)

    # login_manager.init_app(app)

    # register our blueprints
    app.register_blueprint(rest_service, url_prefix="/api")
    app.register_blueprint(main)

    return app
Example #2
0
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. neogameserver.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    admin = Admin(app, name="neogameserver", template_mode="bootstrap3")
    admin.add_view(NeoModelView(User, db.session))
    admin.add_view(NeoModelView(Subscription, db.session))
    admin.add_view(NeoModelView(MinecraftProduct, db.session))
    admin.add_view(NeoModelView(VentriloProduct, db.session))
    admin.add_view(NeoModelView(OrderProduct, db.session))
    admin.add_view(NeoModelView(HostServer, db.session))
    admin.add_view(NeoModelView(Port, db.session))

    # initialize the cache
    cache.init_app(app)

    # initialize the debug tool bar
    debug_toolbar.init_app(app)

    # initialize SQLAlchemy
    db.init_app(app)

    login_manager.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    # register our blueprints
    app.register_blueprint(main)
    app.register_blueprint(adminviews)

    return app
Example #3
0
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. squall.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # initialize the cache
    cache.init_app(app)

    # initialize the debug tool bar
    debug_toolbar.init_app(app)

    # initialize SQLAlchemy
    db.init_app(app)
    login_manager.init_app(app)

    # initialize MongoDB
    mongo.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    # register our blueprints
    app.register_blueprint(main)
    app.register_blueprint(algorithms, url_prefix="/algorithms")
    app.register_blueprint(data, url_prefix="/data")
    app.register_blueprint(experiments, url_prefix="/experiments")
    app.register_blueprint(tags, url_prefix="/tags")

    return app
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. hearthstone.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # init the cache
    cache.init_app(app)

    # init SQLAlchemy
    db.init_app(app)

    api.init_app(app)

    mongo.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)

    # register our blueprints
    from controllers.main import main

    app.register_blueprint(main)

    import controllers.restful

    controllers.restful.register(api)

    return app
Example #5
0
def create_app(instance_path="", env="prod"):
    """Create the app."""
    app_name = ".".join(__name__.split(".")[0:2])

    instance_path = instance_path or os.path.join(sys.prefix, "var", app_name + "-instance")
    try:
        if not os.path.exists(instance_path):
            os.makedirs(instance_path)
    except Exception:
        pass

    app = Flask(
        app_name,
        instance_path=instance_path,
        instance_relative_config=True,
        static_folder=os.path.join(instance_path, "static"),
    )

    app.config["ENV"] = env
    env_object = "iiif.base.config.{0}Config".format(env.capitalize())
    app.config.from_object(env_object)
    app.config.from_envvar("iiif_ENV_SRC", silent=True)
    app.config.from_pyfile("application.cfg", silent=True)

    # Ignore slashes
    app.url_map.strict_slashes = False

    # Add the proxies
    Registry(app=app)
    app.extensions["registry"].update(packages=PackageRegistry(app))
    app.extensions["registry"].update(
        extensions=ExtensionRegistry(app), blueprints=BlueprintAutoDiscoveryRegistry(app=app)
    )
    ConfigurationRegistry(app)
    _setup_app_errors(app)
    return app
@app.route("/email/", methods=['POST'])
def email():
	emailHandler = EmailRequestHandler(config)
	response = emailHandler.process(request)
	return response

# For Dev purpose only
@app.route("/test/", methods=['GET'])
def test():
	if app.config["ENV"] == "dev":
		f = open('./test/test.html', 'r')
		content = f.read()
		return Response(content, status=200, mimetype="text/html")
	else:
		return Response("{\"message\": \"Page not allowed to access\"}", status=404)

# Main Service
if __name__ == "__main__":
	config = ConfigLoader()
	if config.isLoaded():
		# get environment
		app.config["ENV"] = config.getEnv()
		print "Environment: "+ app.config["ENV"].upper()
		if app.config["ENV"].lower() == "prod":
			app.run(host= '0.0.0.0')
		elif app.config["ENV"].lower() == "dev":
			app.run(debug=True)
	else:
		print "Failed to load the config. Can't start the Service."
from flask import Flask
import os


__all__ = ["app"]


app = Flask(__name__)
app.config["ENV"] = os.environ.get("FLASK_ENV", "prod")
app.config.from_object("amzstorefront.settings.%sConfig" % app.config["ENV"].capitalize())


import views
Example #8
0
    if id in process_dict and process_dict[id].is_alive():
        process_dict[id].need_stop = True
        print("force stopped")
        sse.publish({"msg": "force stopped!"}, type='result')
    return "success"
# @app.route('/command_worker/stop/<id>')
# def command_stop(id):
#     global process_dict
#     "command_stop".p()
#     if id in process_dict and process_dict[id].is_alive():
#         process_dict[id].p()
#         process_dict[id].terminate()
#         print("force stopped")
#         sse.publish({"msg": "force stopped!"}, type='result')
#     return "success"



if __name__ == '__main__':
    from gevent.wsgi import WSGIServer
    app.debug = True
    app.log_output = True
    app.config["ENV"] = "development"
    # app.logger.pp()
    # app.config.pp()
    address = ('localhost', 8000)
    http_server = WSGIServer(address, app, log=app.logger)
    print("Server running on port {}:{}. Ctrl+C to quit".format(*address))

    http_server.serve_forever()