コード例 #1
0
#!/usr/bin/env python
from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand
from apps import create_app
from apps.models import db
from apps.models.User import login_manager
from apps.models import User, Role, Comment

# Flask app config:
app = create_app('videodata')
manager = Manager(app)  # add Flask-Script
migrate = Migrate(
    app, db
)  # add Flask-Migrate to manage database // user python run db init to create Migrate Database
manager.add_command('db', MigrateCommand)


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


if __name__ == '__main__':
    login_manager.init_app(app)
    manager.add_command(
        "shell", Shell(make_context=make_shell_context))  # add shell env
    manager.run()
コード例 #2
0
from sys import exit
from decouple import config

from apps.config import config_dict
from apps import create_app, db

# WARNING: Don't run with debug turned on in production!
DEBUG = config('DEBUG', default=True, cast=bool)

# The configuration
get_config_mode = 'Debug' if DEBUG else 'Production'

try:

    # Load the configuration using the default values
    app_config = config_dict[get_config_mode.capitalize()]

except KeyError:
    exit('Error: Invalid <config_mode>. Expected values [Debug, Production] ')

app = create_app(app_config)
Migrate(app, db)

if DEBUG:
    app.logger.info('DEBUG       = ' + str(DEBUG))
    app.logger.info('Environment = ' + get_config_mode)
    app.logger.info('DBMS        = ' + app_config.SQLALCHEMY_DATABASE_URI)

if __name__ == "__main__":
    app.run()
コード例 #3
0
ファイル: app.py プロジェクト: tsx2/tpp
from flask import Flask
from flask_script import Manager,Server
from flask_migrate import MigrateCommand


from apps import create_app
from apps.settings import DEVELOP

app=create_app(DEVELOP)

manager=Manager(app)
manager.add_command('start',Server(port=8000))
manager.add_command('db',MigrateCommand)

if __name__ == '__main__':
    manager.run()
コード例 #4
0
ファイル: manager.py プロジェクト: JasonZeroes/flask_test
from apps import create_app

config_str = "apps.settings.DevCMSConfig"
app = create_app(config_str)

if __name__ == '__main__':
    with app.app_context():
        from apps.models import db
        db.create_all()
    app.run()
コード例 #5
0
def fn():
    app = create_app('develop')  # 创建一个app用于检测
    tool = Tool()
    tool.get_data()
コード例 #6
0
ファイル: manage.py プロジェクト: gcallsen/stripped-stormpath
import os
from apps import create_app
from flask.ext.script import Server, Shell, Manager
from flask.ext.stormpath import StormpathManager
# from rhodb.database import db
from apps import db

def create_manager(app, db):
    """ This function creates and configures a Flask-Script manager object.
    """
    manager = Manager(app)

    manager.add_command("runserver", Server())

    def make_shell_context():
        return dict(app=app, db=db)
    manager.add_command("shell", Shell(make_context=make_shell_context))

    return manager

# Expose app & manager
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = create_manager(app, db)

# If main, run the manager.
#
if __name__ == "__main__":
    manager.run()
コード例 #7
0
ファイル: base.py プロジェクト: gollumHome/exchange_currency
    def create_app(self):
        from celerys.tasks import celery

        celery.config_from_object(config["testing2"])
        app = create_app("testing2")
        return app
コード例 #8
0
 def setUpClass(cls):
     cls.app = create_app(TestConfig)
     cls.app.app_context().push()
     cls.db = db
コード例 #9
0
# -*- coding:utf-8 -*-
import os
from apps import create_app
from flask_script import Manager
from flask_migrate import MigrateCommand

config_name = os.environ.get('FLASK_CONFIG') or 'default'
# config_name =  'default'
app = create_app(config_name)

manager = Manager(app)

manager.add_command('db',MigrateCommand)
if __name__ == '__main__':
    manager.run()
コード例 #10
0
ファイル: main.py プロジェクト: Takashi-kun/takoyaki-memo
# -*- coding: utf-8 -*-

import apps
import config

app = apps.create_app(config)

# This is only used when running locally. When running live, gunicorn runs
# the application.
if __name__ == '__main__':
    app.run(host='192.168.50.12', port=8080, debug=True)
コード例 #11
0
ファイル: run.py プロジェクト: HongDanni/myFlaskProject
# -*-coding:utf8-*-
from apps import create_app
from conf import conf

app = create_app()  # 获取flask实例

if __name__ == '__main__':
    # 启动服务;是否开启调试模式、监听IP和端口在conf.py里设置
    app.run(debug=conf.DEBUG, port=conf.PORT, host=conf.HOST)
コード例 #12
0
# Python
from os import getenv
from os.path import dirname, isfile, join

# Third
from dotenv import load_dotenv

# Apps

_ENV_FILE = join(dirname(__file__), ".env")

if isfile(_ENV_FILE):
    load_dotenv(dotenv_path=_ENV_FILE)
from apps import create_app, celery
from apps.celery_utils import init_celery

app = create_app(getenv("FLASK_ENV") or "default")
init_celery(celery, app)
コード例 #13
0
ファイル: wsgi.py プロジェクト: ap13p/elearn
#!/usr/bin/python
import os

# virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtenv = os.path.join(os.getenv('OPENSHIFT_PYTHON_DIR', '.'), 'virtenv')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
    pass
#
# IMPORTANT: Put any additional includes below this line.  If placed above this
# line, it's possible required libraries won't be in your searchable path
#

from apps import create_app
application = create_app()

#
# Below for testing only
#
if __name__ == '__main__':
    if os.getenv('LOCAL', False):
        application.run()
    else:
        from wsgiref.simple_server import make_server
        httpd = make_server('localhost', 8051, application)
        # Wait for a single request, serve it and quit.
        httpd.serve_forever()
コード例 #14
0
ファイル: manage.py プロジェクト: python-0/logs
from flask_script import Manager, Shell, Server
from flask_migrate import Migrate, MigrateCommand
from flask_login import login_required

from apps import create_app, db
from apps.models import User

app = create_app('development')
manager = Manager(app)
migrate = Migrate(app, db)
server = Server(host="0.0.0.0")


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

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


@app.route('/secret')
@login_required
def secret():
    return "only authenticated users are allowed"

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

コード例 #15
0
from os import getenv
from os.path import dirname, isfile, join

from dotenv import load_dotenv

_ENV_FILE = join(dirname(__file__), '.env')

if isfile(_ENV_FILE):
    load_dotenv(dotenv_path=_ENV_FILE)

from apps import create_app

app = create_app(getenv('FLASK_ENV') or 'default')

if __name__ == '__main__':
    host = 'localhost'
    ip = '0.0.0.0'
    port = app.config['APP_PORT']
    debug = app.config['DEBUG']

    app.run(host=host, debug=debug, port=port, use_reloader=debug)
コード例 #16
0
from apps import create_app

app = create_app('dev')

if __name__ == '__main__':
    app.run()
コード例 #17
0
# -*- coding: utf-8 -*-

from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from apps.Library import db
from apps import create_app

from apps.Moduel.MySQL import notice
from apps.Moduel.MySQL import user

app = create_app()

Migrate(app, db)

# 添加数据库相关命令行
manager = Manager(app)
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manager.run()
コード例 #18
0
ファイル: manager.py プロジェクト: MincoX/flaskServer
import datetime
from threading import Lock

from flask_script import Manager, Server

import settings
# from common import logger
from apps import create_app

MODEL = 'product'
app = create_app(MODEL)

manager = Manager(app)
manager.add_command(
    "runserver",
    Server(settings.config_map[MODEL].HOST, settings.config_map[MODEL].PORT))

if __name__ == '__main__':
    app.run(host=settings.config_map[MODEL].SERVER_HOST,
            port=settings.config_map[MODEL].PORT,
            debug=settings.config_map[MODEL].DEBUG)
コード例 #19
0
from flask_script import Manager

from apps import (create_app)
from src.config import app_config

application = create_app(app_config)

manager = Manager(application)


@manager.command
def runserver():
    application.run(host='0.0.0.0', port='8080', debug=True)


if __name__ == '__main__':
    manager.run()
コード例 #20
0
# -*- coding: utf-8 -*-

#import queue
from multiprocessing import Queue
from flask import jsonify, g
# from apps import create_app
import apps
from apps.Log.LogToDB import LogToDB
from apps.utils.functions import getGUID

app = apps.create_app()


@app.route('/')
def show():
    return 'hello world', 200


@app.before_request
def before_request(*args, **kwargs):
    g.LogQueue = Queue()
    g.LogGuid = getGUID()
    LogToDB(g.LogQueue, g.LogGuid)

    app.logger.info('Started')


@app.after_request
def after_request(response):
    """ Logging after every request. """
    # This avoids the duplication of registry in the log,
コード例 #21
0
# -*- coding: utf-8 -*-
# from gevent import monkey; monkey.patch_all()
import logging.handlers
from abc import ABC
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
# from gunicorn.app.base import BaseApplication
# from gunicorn.six import iteritems
from multiprocessing import cpu_count
from apps import create_app, db
from config import config
# from apps.models import db
app = create_app(config)

manager = Manager(app)

migrate = Migrate(app, db)

manager.add_command('db', MigrateCommand)

# class StandaloneApplication(BaseApplication, ABC):
#     """
#     gunicorn服务器启动类
#     """
#
#     def __init__(self, application, options):
#         self.application = application
#         self.options = options or {}
#         super(StandaloneApplication, self).__init__()
#
#     def load_config(self):
コード例 #22
0
# -*- coding: utf-8 -*-

from apps import create_app

application = create_app()

if __name__ == '__main__':
    ip = '0.0.0.0'
    port = application.config['APP_PORT']
    debug = application.config['DEBUG']

    application.run(host=ip,
                    debug=debug,
                    port=port,
                    threaded=True,
                    use_reloader=debug)
コード例 #23
0
ファイル: manage.py プロジェクト: lixin0326/flask_orm
from flask import Flask
from apps import create_app
from flask_script import Manager, Server
from flask_migrate import MigrateCommand

manage = Manager(app=create_app())

manage.add_command('run', Server(host='127.0.0.1', port=8080, threaded=True))

manage.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manage.run()
コード例 #24
0
ファイル: base_testcase.py プロジェクト: intest-tech/qaadmin
 def create_app(self):
     from apps import create_app
     return create_app()
コード例 #25
0
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from apps import create_app
from apps.ext import db
from apps.user.model import *
from apps.loan.model import *

app = create_app()  # 创建flask app
manager = Manager(app=app)  # 命令管理app

# 配置 migrate 数据库命令管理工具关联  既影响app  又能让manager进行命令管理
migrate = Migrate(app=app, db=db)  # 关联app  操作数据库
manager.add_command('db', MigrateCommand)  # 命令交给manager管理


@manager.command
def init():  # 自定义启动命令
    print('manager defined app init command')


if __name__ == '__main__':
    manager.run()
コード例 #26
0
ファイル: celery_workers.py プロジェクト: Zionus/Aqua
import os
from apps import celery, create_app
#app = create_app(os.getenv('FLASK_CONFIG') or 'default')
app = create_app('default')
app.app_context().push()
コード例 #27
0
except ImportError:
    coverage = COV = None

if os.path.exists('.env'):
    print('Importing environment from .env...')
    for line in open('.env'):
        var = line.strip().split('=')
        if len(var) == 2:
            os.environ[var[0]] = var[1]

from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand

from apps import create_app, db

app = create_app(os.getenv('FLASK_CONFIG') or 'default')

# This import must be put behind app initialization to avoid TypeError because
# `register_blueprints` function uses app logger which requires app to be
# created first.
from apps.common.utils.initialize import load_models, register_blueprints  # NOQA

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


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


manager.add_command("shell", Shell(make_context=make_shell_context))
コード例 #28
0
 def __init__(self, enforce_csrf_checks=True, *args, **kwargs):
     self.enforce_csrf_checks = enforce_csrf_checks
     from apps import create_app
     self.app = create_app()
コード例 #29
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
コード例 #30
0
ファイル: manage.py プロジェクト: tiantaozhang/site-basics
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import logging
from logging.handlers import TimedRotatingFileHandler
from flask import jsonify
from flask_script import Manager, Shell, Server
from apps import create_app
from apps.exception import TTException

FLASK_CONFIG = os.getenv("FLASK_CONFIG", "default")
app = create_app(FLASK_CONFIG)

# logger config
handler = TimedRotatingFileHandler(app.config['APP_LOG_FILE'],
                                   when='D',
                                   backupCount=15)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
app.logger.addHandler(handler)


@app.errorhandler(TTException)
def handle_http_exception(error):
    """细化处理请求错误,返回响应
    :param error: HTTPException instance
    :return: response
    """
コード例 #31
0
from vibora.tests import TestSuite

from apps import create_app

app = create_app('testing')


class HomeTestCase(TestSuite):
    def setUp(self):
        self.client = app.test_client()

    async def test_home(self):
        response = await self.client.get('/v1/home')
        self.assertEqual(response.content, b'{"hello":"world"}')
コード例 #32
0
import os
from apps import db, migrate, create_app
from apps.ocr.models import (
    ClientBaseConfigure,
    UserInfor,
    PicInfor,
    PdfInfor,
)

env = os.environ.get('WEBAPP_ENV', 'dev')
app = create_app('config.%sConfig' % env.capitalize())


@app.shell_context_processor
def make_shell_context():
    return dict(
        app=app,
        db=db,
        ClientConfig=ClientBaseConfigure,
        User=UserInfor,
        PicInfor=PicInfor,
        PdfInfor=PdfInfor,
        migrate=migrate,
    )
コード例 #33
0
@desc:
@author:
@contact:
@file:manage.py
@time:2020/8/24 16:08;
"""
from flask_script import Manager
from apps import create_app
from flask_migrate import MigrateCommand
from apps.models import Posts
from apps.models import User
from apps.exts import db
import time


app = create_app('default')
manager = Manager(app)
manager.add_command('db',MigrateCommand)


@manager.command
def create_test_post():
    # 内容 作者
    for x in range(1,200):
        content = '内容:%s' % x
        author = User.query.first()
        post = Posts(content=content,author=author)
        time.sleep(0.2)
        db.session.add(post)
        db.session.commit()
コード例 #34
0
from apps import create_app

app = create_app(config_name="default")
if __name__ == "__main__":
    app.run()
コード例 #35
0
# !/usr/bin/env python
# coding:utf-8
# author bai
from flask_script import Manager

from apps import create_app


app = create_app()

manage = Manager(app)

if __name__ == '__main__':
    app.run(debug=False)


コード例 #36
0
ファイル: manage.py プロジェクト: Zionus/Aqua
#python uploads.py runserver -p 80 
#!/usr/bin/env python
from flask_script import Manager,prompt_bool
from apps import create_app
from apps.utils import story as story


app = create_app( 'dev' )
manager = Manager(app)

'''
from flask_migrate import Migrate,MigrateCommand
from apps import db,create_app
from apps.models import User,Bookmark ,Tag,Post,Role,Follow



#app = create_app(os.getenv('ATLAS_ENV') or  'dev' )

migrate = Migrate(app,db)

manager.add_command('db',MigrateCommand)

@manager.command
def insert_data():
    couchk = User(username="******", email="*****@*****.**", password="******")
    db.session.add(couchk)

    def add_bookmark(url, description, tags):
        db.session.add(Bookmark(url=url, description=description,  user_id=couchk.id,
                                tags=tags))