Python app.app 模块,run() 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用app.app.run()

项目:Hermes    作者:nmpiazza    | 项目源码 | 文件源码
def parse_and_run(args=None):
    sslBaseDir = path.join(BASE_DIR, 'ssl')

    p = ArgumentParser()
    p.add_argument('--bind', '-b', action='store', help='the address to bind to', default='127.0.0.1')
    p.add_argument('--port', '-p', action='store', type=int, help='the port to listen on', default=8080)
    p.add_argument('--debug', '-d', action='store_true', help='enable debugging (use with caution)', default=False)
    p.add_argument('--ssl', '-s', action='store_true', help='enable ssl', default=False)

    args = p.parse_args(args)
    if args.ssl:
        ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
        ctx.load_cert_chain(path.join(sslBaseDir, 'server.crt'), path.join(sslBaseDir, 'server.key'))
        app.config['SESSION_TYPE'] = 'filesystem'

        app.run(host=args.bind, port=args.port, debug=args.debug, ssl_context=ctx)
    else:
        app.run(host=args.bind, port=args.port, debug=args.debug)
项目:eventit    作者:alfredgg    | 项目源码 | 文件源码
def test(coverage=False):
    import unittest2
    import os
    import coverage as _coverage
    cov = None
    if coverage:
        cov = _coverage.coverage(branch=True, include='./*')
        cov.start()
    tests = unittest2.TestLoader().discover('tests')
    unittest2.TextTestRunner(verbosity=2).run(tests)
    if cov:
        cov.stop()
        cov.save()
        print('Coverage Summary:')
        cov.report()
        basedir = os.path.abspath(os.path.dirname(__file__))
        covdir = os.path.join(basedir, 'tmp/coverage')
        cov.html_report(directory=covdir)
        print('HTML version: file://%s/index.html' % covdir)
        cov.erase()


# TODO: Implement options
项目:oadoi    作者:Impactstory    | 项目源码 | 文件源码
def stuff_before_request():
    g.request_start_time = time()
    g.hybrid = False
    if 'hybrid' in request.args.keys():
        g.hybrid = True
        logger.info(u"GOT HYBRID PARAM so will run with hybrid.")

    # don't redirect http api in some cases
    if request.url.startswith("http://api."):
        return
    if "staging" in request.url or "localhost" in request.url:
        return

    # redirect everything else to https.
    new_url = None
    try:
        if request.headers["X-Forwarded-Proto"] == "https":
            pass
        elif "http://" in request.url:
            new_url = request.url.replace("http://", "https://")
    except KeyError:
        # logger.info(u"There's no X-Forwarded-Proto header; assuming localhost, serving http.")
        pass

    # redirect to naked domain from www
    if request.url.startswith("https://www.oadoi.org"):
        new_url = request.url.replace(
            "https://www.oadoi.org",
            "https://oadoi.org"
        )
        logger.info(u"URL starts with www; redirecting to " + new_url)

    if new_url:
        return redirect(new_url, 301)  # permanent



# convenience function because we do this in multiple places
项目:plexivity    作者:mutschler    | 项目源码 | 文件源码
def compile():
    "compile translations"
    os.system(pybabel + ' compile -d app/translations')

#run with ssl certs
项目:plexivity    作者:mutschler    | 项目源码 | 文件源码
def ssl():
    from OpenSSL import SSL
    ctx = SSL.Context(SSL.SSLv23_METHOD)
    ctx.use_privatekey_file('ssl.key')
    ctx.use_certificate_file('ssl.cert')
    app.run(ssl_context=ctx)
项目:plexivity    作者:mutschler    | 项目源码 | 文件源码
def run_app():
    from subprocess import Popen
    import sys
    os.chdir(os.path.abspath(os.path.dirname(__file__)))
    path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "manage.py")
    args = [sys.executable, path, "db"]
    if not os.path.exists(os.path.join(config.DATA_DIR, "plexivity.db")):
        from app import db
        db.create_all()
        args.append("stamp")
        args.append("head")
    else:
        args.append("upgrade")

    Popen(args)

    helper.startScheduler()

    if config.USE_SSL:
        helper.generateSSLCert()
        try:
            from OpenSSL import SSL
            context = SSL.Context(SSL.SSLv23_METHOD)
            context.use_privatekey_file(os.path.join(config.DATA_DIR, "plexivity.key"))
            context.use_certificate_file(os.path.join(config.DATA_DIR, "plexivity.crt"))
            app.run(host="0.0.0.0", port=config.PORT, debug=False, ssl_context=context)
        except:
            logger.error("plexivity should use SSL but OpenSSL was not found, starting without SSL")
            app.run(host="0.0.0.0", port=config.PORT, debug=False)
    else:
        app.run(host="0.0.0.0", port=config.PORT, debug=False)
项目:plexivity    作者:mutschler    | 项目源码 | 文件源码
def run(self):
        # Define your tasks here
        # Anything written in python is permitted
        # For example you can clean up your server logs every hour
        run_app()
项目:k8scntkSamples    作者:weehyong    | 项目源码 | 文件源码
def create():
    print("Initialising")
    init()
    application.run(host='127.0.0.1', port=5000)
项目:CSH_image_labeling    作者:Paprika69    | 项目源码 | 文件源码
def main():
    initialize_app(app)
    app.jinja_env.auto_reload = True
    app.run(debug=True)
项目:software-assessment-framework    作者:softwaresaved    | 项目源码 | 文件源码
def main():
    # Set up logging
    logging.basicConfig(format='%(asctime)s - %(levelname)s %(funcName)s() - %(message)s',
                        filename=config.log_file_name,
                        level=config.log_level)
    logging.info('-- Starting the Software Assessment Framework --')

    app.config['WTF_CSRF_ENABLED'] = False
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    app.run(host=config.host, port=config.port, debug=True)
项目:eventit    作者:alfredgg    | 项目源码 | 文件源码
def runserver():
    from eventit.eventit import app
    app.run(
        host="0.0.0.0",
        port=8080,
        debug=True
    )

# TODO: Create admin user
项目:LTHCourseStatistics    作者:TabTabTab    | 项目源码 | 文件源码
def main(argv):
    from app import app
    app.debug = "debug" in argv or IS_DEBUG
    app.run(port=5006)
项目:sutd-timetable    作者:randName    | 项目源码 | 文件源码
def runserver(host, port, debug):
    """Run server"""
    app.run(host=host, port=port, debug=debug)