Пример #1
0
def live(port=5000):
    from livereload import Server
    server = Server(manager.create_app())
    server.watch('assets/*.js', 'make -C assets build')
    server.watch('assets/page/*.js', 'make -C assets build')
    server.watch('assets/stylus', 'make -C assets stylus')
    server.serve(port)
Пример #2
0
    def handle(self, app, host, port, use_debugger, use_reloader, threaded, processes, **kwargs):
        use_bugman = kwargs.pop('use_bugman')
        if use_bugman and not 'bugman' in self.app.config['INSTALLED_EXTENSIONS']:
            self.app.config['INSTALLED_EXTENSIONS'].append('bugman')
        elif not use_bugman and 'bugman' in self.app.config['INSTALLED_EXTENSIONS']:
            self.app.config['INSTALLED_EXTENSIONS'].remove('bugman')

        self.app.config['VERBOSE_MONGODB'] = kwargs.pop('verbose_mongodb')

        if kwargs.pop('profile'):
            from werkzeug.contrib.profiler import ProfilerMiddleware
            app.wsgi_app = ProfilerMiddleware(app.wsgi_app, file('profile.data', 'w'))

        app = configure_app(app)
        Server.handle(self, app, host, port, use_debugger, use_reloader, threaded, processes, False)
Пример #3
0
    def get_options(self):
        options = Server.get_options(self)

        options += (Option('-m', '--verbose_mongodb',
                           action='store_true',
                           dest='verbose_mongodb',
                           default=False),)

        options += (Option('--profile',
                           action='store_true',
                           dest='profile',
                           help='Init python profiler',
                           default=False),)

        exp = 'bugman' in self.app.config['INSTALLED_EXTENSIONS']
        if exp:
            options += (Option('-b', '--no-bugman',
                               action='store_false',
                               dest='use_bugman',
                               help='Deactivate Flask-Bugman',
                               default=exp),)

        else:
            options += (Option('-b', '--bugman',
                               action='store_true',
                               dest='use_bugman',
                               help='Activate Flask-Bugman',
                               default=exp),)
        return options
Пример #4
0
Файл: cli.py Проект: drivet/yawt
def create_manager(app=None):
    """Create the command line manager"""
    app_supplied = True
    if not app:
        app = create_app()
        app_supplied = False
    manager = Manager(app)

    server = Server(use_debugger=True, use_reloader=True)
    server.description = 'runs the yawt local server.'
    manager.add_command('runserver', server)
    manager.add_command('newsite', NewSite())
    manager.add_command('walk', Walk())

    if app_supplied:
        _handle_cli_init(manager)
    else:
        with app.test_request_context():
            _handle_cli_init(manager)

    return manager
Пример #5
0
# Not Needed, this is done with the mpapi app
# manager.add_command('db', MigrateCommand)


@manager.command
def addDefaultAdmin():
    print 'Adding Default Admin Account to DB'
    if addDefaultAdminAccount():
        print 'Default Admin Account has been added to DB'
    else:
        print 'Error Adding Default Admin Account to DB'


@manager.command
def migrateClientsToGroup():
    print 'Migrate Clients to Default Group'
    addUnassignedClientsToGroup()
    print 'Clients have been migrated to Default Group'


# Override default runserver with options from config.py
manager.add_command(
    'runserver',
    Server(host=app.config['SRV_HOST'], port=app.config['SRV_PORT']))

# Add gunicorn command to the manager
manager.add_command("gunicorn", GunicornServer())

if __name__ == '__main__':
    manager.run()
Пример #6
0
from application import app, manager
from flask_script import Server
import www

#web server

manager.add_command(
    "runserver",
    Server(host='0.0.0.0', port=app.config['SERVER_PORT'], use_reloader=True))


def main():
    manager.run()


if __name__ == '__main__':
    try:
        import sys
        sys.exit(main())
    except Exception as e:
        import traceback
        traceback.print_exc()
Пример #7
0
# -*- coding: utf-8 -*-
'''数据库迁移配置'''
import sys

from flask_script import (Manager, Server)
from flask_migrate import (Migrate, MigrateCommand)

from run import start_server

if __name__ == '__main__':
    # 解析参数
    parser = Server().create_parser()
    ns = vars(parser.parse_known_args(sys.argv)[0])
    host = ns.get('host', '127.0.0.1')
    port = ns.get('port', 5556)
    is_debug = ns.get('use_debugger', False)
    is_threaded = ns.get('threaded', False)
    # 获取应用(app)
    run_cfg = {
        'host': host,
        'port': port,
        'debug': is_debug,
        'threaded': is_threaded
    }
    app = start_server(run_cfg, is_deploy=True)
    # 命令配置
    migrate = Migrate(app, app.db)
    manager = Manager(app)
    manager.add_command('db', MigrateCommand)
    manager.run()
Пример #8
0
# coding:utf-8
# author:james
# datetime:2019/9/11 14:07
import traceback

from flask_script import Server

from application import manager, app

import www

manager.add_command('runserver',
                    Server(port=app.config['SERVER_PORT'], use_debugger=True))


def main():
    manager.run()


if __name__ == '__main__':

    try:
        import sys
        sys.exit(main())
    except Exception as e:
        traceback.print_exc()
Пример #9
0
## -*- coding: utf-8 -*-

from flask_script import Manager, Server
from flask_migrate import Migrate, MigrateCommand
from app import app, db

# Enable flask-migrate
migrate = Migrate(app, db)

# Enable flask-manager
manager = Manager(app)
manager.add_command('db', MigrateCommand)
manager.add_command("threaded", Server(threaded=True))

if __name__ == '__main__':
    manager.run()
Пример #10
0
from flask_script import Manager, Server, Command
from app import create_app
from db import db

server = Server(host='0.0.0.0')
manager = Manager(create_app)


class CreateDB(Command):
    def run(self):
        db.create_all()


class DropDB(Command):
    def run(self):
        db.drop_all()


manager.add_command('runserver', server)
manager.add_command('create_db', CreateDB)
manager.add_command('drop_db', DropDB)

if __name__ == '__main__':
    manager.run()
Пример #11
0
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager, Server

from cal import app
from models import db

manager = Manager(app)

migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)

server_command = Server(host='0.0.0.0',
                        port=5000,
                        use_debugger=True,
                        use_reloader=True)
manager.add_command('runserver', server_command)

if __name__ == '__main__':
    manager.run()
Пример #12
0
else:
    app = create_app(DevConfig)

HERE = os.path.abspath(os.path.dirname(__file__))
TEST_PATH = os.path.join(HERE, 'tests')

manager = Manager(app)


def _make_context():
    """Return context dict for a shell session so you can access
    app, db, and the User model by default.
    """
    return {'app': app, 'db': db, 'User': User}


@manager.command
def test():
    """Run the tests."""
    import pytest
    exit_code = pytest.main([TEST_PATH, '--verbose'])
    return exit_code


manager.add_command('server', Server())
manager.add_command('shell', Shell(make_context=_make_context))
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manager.run()
Пример #13
0
app = Flask(__name__)
app.json_encoder = MyJSONEncoder
app.config['DEBUG'] = True
app.config[
    'SQLALCHEMY_DATABASE_URI'] = "postgresql://*****:*****@localhost:5432/crs"
#"postgresql://*****:*****@localhost:5438/crs"
#os.environ['SQLALCHEMY_DATABASE_URI']
app.debug = False
CORS(app)
db.init_app(app)
db.app = app
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
manager.add_command('runserver', Server(host='0.0.0.0', port=5000))


@manager.command
def load_questions():
    pass


@app.route('/register', methods=["POST"])
def register():

    data = json.loads(request.data)
    user_data = data.get("user", None)
    username = user_data.get("username", None)
    email = user_data.get("email", None)
    saved_user = None
Пример #14
0
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 30 18:03:42 2018

@author: Camille
"""

#!/usr/bin/env python

from src import create_app
from flask_script import Manager
from flask_script import Server

app = create_app()
manager = Manager(app)
manager.add_command("runserver", Server(use_debugger=True, host='0.0.0.0'))

if __name__ == '__main__':
    manager.run()
Пример #15
0
from app.models import User, App, AppVersionInfo, Group  # 在这里导入,不然创建的database没有表, 20170603
from flask_script import Manager, Server, Shell
from flask_migrate import Migrate, MigrateCommand
from config import base_dir
# from OpenSSL import SSL

# context = SSL.Context(SSL.SSLv23_METHOD) #TLSv1_2_METHOD
key_path = base_dir + '/static/server.key'
crt_path = base_dir + '/static/server.crt'
context = (crt_path, key_path)

app = create_app('default')
manager = Manager(app)
migrate = Migrate(app, db)
server = Server(host='0.0.0.0',
                port=5000,
                use_debugger=True,
                ssl_context=context)


def make_shell_context():
    return dict(app=app,
                db=db,
                User=User,
                App=App,
                AppVersionInfo=AppVersionInfo,
                Group=Group)


manager.add_command("shell", Shell(make_context=make_shell_context()))
manager.add_command("runserver", server)
manager.add_command('db', MigrateCommand)
Пример #16
0
app = create_app("testing")


def _make_shell_context():
    return {
        "app": app,
        "db": db,
        "User": User,
        "Admin": Admin,
        "Activity": Activity,
        "OnlineOrder": OnlineOrder,
        "OnsiteOrder": OnsiteOrder,
    }


manager = Manager(app)
manager.add_command("runserver", Server(port=7071))
manager.add_command("shell", Shell(make_context=_make_shell_context))


@manager.command
def test():
    """ Runs the unit tests """
    import unittest
    tests = unittest.TestLoader().discover("tests/")
    unittest.TextTestRunner(verbosity=2).run(tests)


if __name__ == '__main__':
    manager.run()
Пример #17
0

#获取一个名为flask_config的环境变量为config的启动项'development': DevelopmentConfig,'testing': TestingConfig,'production': ProductionConfig,'default': DevelopmentConfig
app,api= create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)
add_router = add_route(api)



#在shell模式下预加载对象(如数据库对象db,应用程序对象app,表对象等)
def make_shell_context():
    return dict(app=app, db=db,user=User,role=Role,api=api,main_path=Main_path)
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
manager.add_command('runserver',Server(host="0.0.0.0", port=5001,threaded=True))

#创建shell模式下的快捷方法--创建数据表
@manager.command
def create():
    db.create_all()
    return '数据库已创建'

#创建shell模式下的快捷方法--删除数据表
@manager.command
def drop():
    if prompt_bool('确定要删除数据库然后跑路吗?'):
        db.drop_all()
        return '数据库删除完成'
    return '删除需谨慎!'
Пример #18
0
)
from db_test import test_assoc

def _make_context():
    return dict(
        app=create_app(config.dev_config),
        db=db,
        populate_db=populate_db
    )

app = create_app(config=config.dev_config)

migrate = Migrate(app, db)

manager = Manager(app)
manager.add_command('runserver', Server(host='0.0.0.0'))
manager.add_command('shell', Shell(make_context=_make_context))
manager.add_command('db', MigrateCommand)


@manager.command
@manager.option('-n', '--num_users', help='Number of users')
def create_db(num_users=5):
    """Creates data tables and populates them."""
    db.create_all()
    populate_db(num_users=num_users)


@manager.command
@manager.option('-n', '--num_assoc', help='Number of associations')
def create_assoc(num_assoc=5):
Пример #19
0
from app import create_app, db
from flask_script import Manager, Server
from app.models import User
from flask_migrate import Migrate, MigrateCommand

app = create_app('production')

manager = Manager(app)
migrate = Migrate(app, db)

manager.add_command('db', MigrateCommand)
manager.add_command('run', Server(use_debugger=True))


@manager.shell
def make_shell_context():
    return dict(app=app, db=db, User=User)


@manager.command
def test():
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)


def test_get_review_by_id(self, Review):

    self.new_review.save_review()
    got_reviews = Review.get_reviews(12345)
    self.assertTrue(len(got_reviews) == 1)
Пример #20
0
from app import create_app
from app.models import db, User, Post, Comment, Tag, Role
import app.models
from app.config import DevConfig

# Create thr app instance via Factory Method
app = create_app(DevConfig)
# Init manager object via app object
manager = Manager(app)

# Init migrare object via app and db object
migrate = Migrate(app, db)

# Create a new commands: server
# This command will be run the Flask development_env server
manager.add_command("server", Server(host='0.0.0.0', port=8080))
manager.add_command("db", MigrateCommand)


@manager.shell
def make_shell_context():
    return dict(app=app,
                db=db,
                User=User,
                Post=Post,
                Comment=Comment,
                Tag=Tag,
                Role=Role)


if __name__ == '__main__':
Пример #21
0
from flask_script import Manager, Server
from app import app, db, member, inorout, product, purchase

# 設置你的 app
manager = Manager(app)
# 設置 python manage.py runserver 為啟動 server 指令
server = Server(host="0.0.0.0")
manager.add_command('runserver', Server())


# 設置 python manage.py shell 為啟動交互式指令 shell 的指令
@manager.shell
def make_shell_context():
    return dict(app=app,
                db=db,
                member=member,
                inorout=inorout,
                product=product,
                purchase=purchase)


if __name__ == '__main__':
    manager.run()
Пример #22
0
import os

from flask_script import Manager, Server
from operationRoom import create_app

# default to dev config
env = os.environ.get('operationRoom_ENV', 'dev')
app = create_app('operationRoom.config.%sConfig' % env.capitalize())


manager = Manager(app)
manager.add_command("server", Server())


@manager.shell
def make_shell_context():
    return dict(
        app=app,
        db=db,
        User=User,
        Post=Post,
        Tag=Tag,
        Comment=Comment
    )


@manager.command
def test():
    """Run the unit tests"""
    import unittest
    tests = unittest.TestLoader().discover('test')
Пример #23
0
# _*_ coding:utf-8 _*_
__author__ = 'solin'
__date__ = '2019/9/22 10:44'
import sys
from application import app, manager
from flask_migrate import Migrate, MigrateCommand
from flask_script import Server
import www

manager.add_command(
    "runserver",
    Server(host="127.0.0.1",
           port=app.config["SERVER_PORT"],
           use_debugger=True,
           use_reloader=True))

# 添加迁移脚本的命令到manager中
manager.add_command('db', MigrateCommand)


def main():
    app.logger.info("*******服务已重启*******")
    manager.run()


if __name__ == "__main__":
    try:
        sys.exit(main())
    except Exception as e:
        import traceback
Пример #24
0
             "wb").write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
        open(join(cert_dir, KEY_FILE),
             "wb").write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k))

    ssl = dict()
    ssl["key"] = join(cert_dir, KEY_FILE)
    ssl["crt"] = join(cert_dir, CERT_FILE)

    return ssl


ssl = make_ssl_context()

manager = Manager(app)
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command("runserver", Server(host="0.0.0.0", port=5000))
manager.add_command(
    "runprivate",
    Server(host="127.0.0.1", port=5000, ssl_crt=ssl["crt"],
           ssl_key=ssl["key"]))


@manager.command
def db_create():
    with app.app_context():
        from migrate.versioning import api
        SQLALCHEMY_MIGRATE_REPO = app.config['SQLALCHEMY_MIGRATE_REPO']
        SQLALCHEMY_DATABASE_URI = app.config['SQLALCHEMY_DATABASE_URI']

        db.create_all()
Пример #25
0
from flask_script import Server, Manager
from flask_migrate import Migrate
from app import create_app, db

app = create_app()

migrate = Migrate(app, db)
manager = Manager(app)

server = Server(host="0.0.0.0", port=5000)

manager.add_command("runserver", server)

@manager.command
def create_database():
    db.create_all()
    db.session.commit()

if __name__ == '__main__':
    manager.run()
Пример #26
0
import os
from api import create_app
from flask_script import Manager, Server
from flask_migrate import Migrate, MigrateCommand
from models import db

app_settings = os.getenv('APP_SETTINGS', 'config.local.Development')
app = create_app(app_settings)
migrate = Migrate(app, db)
manager = Manager(app)
manager = Manager(app)
manager.add_command('db', MigrateCommand)

PORT = os.getenv("SERVE_PORT", "5003")

manager.add_command("runserver", Server(host='0.0.0.0', port=PORT))

if __name__ == '__main__':
    manager.run()
Пример #27
0
from flask_restful import Api
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager, Server
from flask_migrate import Migrate, MigrateCommand
from flask_login import LoginManager
from .models import *

#Instância do arquivo de configuração
app = Flask(__name__)
app.config.from_object('config')

#Instância do banco de dados
db = SQLAlchemy(app)
migrate = Migrate(app, db)

#Instância do banco do arquivo de gerenciamento
manager = Manager(app)
manager.add_command('db', MigrateCommand)
manager.add_command('runserver', Server(host="0.0.0.0", port=9000))

#Instância da API
api = Api(app)

#Instância da Login-Manager
lm = LoginManager(app)
lm.init_app(app)

#Não esquecer dessa linha, sem ela as tabelas não são criadas com o migrate
from app import views
from app.controllers import default_routes
Пример #28
0
import os
from app import configured_app
from flask_script import Manager, Shell, Server

app = configured_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)


def make_shell_context():
    return dict(app=app)


manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command("runserver", Server(host="0.0.0.0", port=5000))

if __name__ == '__main__':
    manager.run()
Пример #29
0
def live(port=5000):
    from livereload import Server
    server = Server(manager.create_app())
    server.serve(port)
Пример #30
0
def dev():
    '''Runs the Flask development server i.e. app.run() when all files changed'''
    from livereload import Server
    live_server = Server(app.wsgi_app)
    live_server.watch('**/*')
    live_server.serve(open_url_delay=True, debug=True, port=80)
Пример #31
0
env = os.environ.get('OK_ENV', 'dev')
app = create_app('settings/{0!s}.py'.format(env))

migrate = Migrate(app, db)
manager = Manager(app)


class RunTests(Command):
    def run(self):
        test_loader = unittest.defaultTestLoader
        test_runner = unittest.TextTestRunner()
        test_suite = test_loader.discover('tests/')
        test_runner.run(test_suite)


manager.add_command("server", Server(host='localhost'))
manager.add_command("show-urls", ShowUrls())
manager.add_command("clean", Clean())
manager.add_command('db', MigrateCommand)
manager.add_command('test', RunTests())
manager.add_command("assets", ManageAssets(assets_env))


@manager.shell
def make_shell_context():
    """ Creates a python REPL with several default imports
        in the context of the app
    """
    return dict(app=app, db=db, User=User)

Пример #32
0
from application import app, manager
from flask_script import Server
import www

#web server settings
manager.add_command(
    'runserver',
    Server(host='127.0.0.1',
           port=app.config['SERVER_PORT'],
           use_debugger=True,
           use_reloader=True))


def main():
    manager.run()


if __name__ == '__main__':
    try:
        import sys
        sys.exit(main())

    except Exception as e:
        import traceback
        traceback.print_exc()
Пример #33
0
from flask_migrate import MigrateCommand
from flask_script import Manager, Server

from app import create_app, db
from app.apis import models

app = create_app()
app.app_context().push()
manager = Manager(app)
manager.add_command('db', MigrateCommand)
manager.add_command("runserver", Server(host='0.0.0.0'))


@manager.command
def initdb():
    db.drop_all()
    db.create_all()


@manager.command
def list_routes():
    """List of all possible routes."""
    import urllib
    output = []
    for rule in app.url_map.iter_rules():

        options = {}
        for arg in rule.arguments:
            options[arg] = "[{0}]".format(arg)

        methods = ','.join(rule.methods)
Пример #34
0
    def __init__(self, app):

        Server.__init__(self)
        self.app = app
Пример #35
0
import os, sys

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from flask_script import Manager, Server
from application import create_app

app = create_app()
manager = Manager(app)

# Turn on debugger by default
manager.add_command(
    "runserver",
    Server(use_debugger=True, use_reloader=True, host='0.0.0.0', port=5000))

if __name__ == '__main__':
    manager.run()
Пример #36
0
from flask_script import Manager, Server
from flask_migrate import Migrate, MigrateCommand
from app import create_app
from v1.models import *
app = create_app('dev')
db.create_all(app=app)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command("db", MigrateCommand)
manager.add_command("runserver",
                    Server(
                        host='0.0.0.0',
                        port=5000,
                        use_debugger=False
                    ))
if __name__ == '__main__':
    manager.run()
Пример #37
0
import os

from flask_script import Manager, Server

from base_test_api.app import app

manager = Manager(app)
server = Server(host="0.0.0.0", port=os.getenv('PORT', 8080))
manager.add_command("runserver", server)

if __name__ == "__main__":
    manager.run()