Beispiel #1
0
#!/usr/bin/env python
import os
from app import create_app, db
from app.models import User, Role
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand
''', Mig'''

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)


def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role)


manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)


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


if __name__ == '__main__':
    manager.run()
Beispiel #2
0
from flask_script import Shell, Manager
from run import create_app, db
from apps.v1.model import Character, YM, SM, Phrase, Character1,Phrase1,Joke

app = create_app()
manager = Manager(app)


def _make_context():
    return dict(app=app, db=db, Character=Character, YM=YM, SM=SM, Phrase=Phrase, Character1=Character1,Joke=Joke)


manager.add_command('shell', Shell(make_context=_make_context, use_ipython=True))


@manager.command
def test():
    # sm = SM.objects.all()
    # sm = [s.sm for s in sm]
    # ym = YM.objects.all()
    # ym = [y.ym for y in ym]
    # print(ym)
    c = Phrase.objects.all()
    index = 0
    for i in c:
        # csm = i.csm_id
        print(i.c1_id)
        Phrase1(id=i.id, phrase=i.phrase, c1=i.c1_id, c2=i.c2_id, c3=i.c3_id, c4=i.c4_id,c5=i.c5_id,c6=i.c6_id,c7=i.c7_id).save()
        print('угг', index + 1, ' ->ok')
        index += 1
Beispiel #3
0
import os
from app import db, create_app
from app.models import User, Post, Tag, Category, Employee, Feedback
from flask_script import Manager, Shell
from flask_migrate import MigrateCommand

app = create_app(os.getenv('FLASK_ENV') or 'config.DevelopementConfig')
manager = Manager(app)


def make_shell_context():
    return dict(app=app,
                db=db,
                User=User,
                Post=Post,
                Tag=Tag,
                Category=Category,
                Employee=Employee,
                Feedback=Feedback)


manager.add_command('shell', Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manager.run()
Beispiel #4
0
#!/usr/bin/env python3
import os
from app import create_app, db
from app.models import User, Role, Post
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager, Shell

app = create_app(os.getenv('BLOGZ_CONFIG') or 'default')
manager = Manager(app)  #为flask框架提供命令行支持
migrate = Migrate(app, db)


def make_shell_context():  #导入实例和模型
    return dict(app=app, db=db, User=User, Role=Role, Post=Post)


manager.add_command(
    "shell", Shell(make_context=make_shell_context))  #挂接回调函数用于建立shell的上下文
manager.add_command('db', MigrateCommand)  #用于支持命令行db操作

if __name__ == '__main__':
    manager.run()
#MigrateCommand类仅在需要通过flask脚本扩展公开数据库迁移命令时使用

app = create_app(os.getenv('FLASK_CONFIG') or 'default') #创建程序实例
manager = Manager(app) # #初始化扩展,Manager类追踪所有在命令行中调用的命令和处理过程的调用运行情况
migrate = Migrate(app, db)##初始化扩展,要迁移的两个参数是应用程序实例和flask sqlachemy数据库实例。

def make_shell_context():
    return dict(app=app, db=db, User=User,Role=Role)

@manager.command #@manage.command 作用是通过命令行可以访问这个方法
def test():
    """Run the unit test."""
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)
    #unittest.TextTestRunner(verbosity=2).run(suite)运行用例,
    # TextTestRunner类将用例执行的结果以text形式输出,
    # verbosity默认值为1,不限制完整结果,即单个用例成功输出’.’,失败输出’F’,错误输出’E’;
    # verbosity=2将输出完整的信息,verbosity=2是指测试结果的输出的详细程度,有0-6级,

#添加脚本命令
manager.add_command("shell", Shell(make_context=make_shell_context()))#自动导入对象
#自定义命令一,命令是shell,manager是Manager的实例,
# 调用add_command方法的效果是, 在终端使用shell命令后会调用Shell(make_context=make_shell_context), 
#  Shell的作用就是调用make_shell_context函数得到对象字典, 然后再遍历字典导入对象。
manager.add_command('db', MigrateCommand) #数据库迁移,MigrateCommand
# 自定义命令二,命令是db

if __name__ == '__main__':
    manager.run() #调用manager.run()启动Manager实例接收命令行中的命令
Beispiel #6
0
def eventAll():
    logger.debug('all event')
    q_event = Event.query
    l_events = list()
    for event in q_event:
        l_events.append(
            dict(id=event.id,
                 time_start=event.time_start,
                 time_end=event.time_end,
                 title=event.title,
                 photo='http://placehold.it/300x200',
                 content=event.content.split('<hr />')[0]))

    return jsonify(l_events)


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

manager.add_command('shell', Shell(make_context=lambda: {'app': app}))
manager.add_command('db', MigrateCommand)
manager.add_command('show-urls', ShowUrls)
manager.add_command('clean', Clean)

#from app.gallery.views import *

from app.gallery.views import mod as frm
app.register_blueprint(frm)

from app.gallery.models import SuperUser

server = socket_server(host, port)

# bind app % manager
app = create_app()
manager = Manager(app)


# shell setting
def app_info():
    return dict(app=app, db=db)


# insert command
manager.add_command("shell", Shell(make_context=app_info))
manager.add_command("runserver", server)


# customer command (maybe later...)
@manager.command
def insert_users():
    name = input("your name: ")
    print(name)


if __name__ == "__main__":
    manager.run()
    # python SevManager.py runserver -d -r
    # d: debug
    # r: reload !
Beispiel #8
0
from flask_script import Command, Manager, Shell

from jasmine_app import create_app
from migrate import run

app = create_app()
manager = Manager(app)

manager.add_command("shell", Shell())
manager.add_command("migrate", Command(run))

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