def get_options(self): return (Option('site'),) + BaseShell.get_options(self)
from app import create_app from config import DevConfig, ProdConfig from app.user import User, UserDetail, ADMIN, USER, ACTIVE #env = os.environ.get('APP_ENV', 'prod') # {dev, prod} #app = create_app(eval('%sConfig' % env.capitalize())) #manager = Manager(app) app = create_app() manager = Manager(app) #manager = Manager(create_app()) #app = create_app() manager.add_command("run", Server(host=app.config['HOST'], port=app.config['PORT'])) manager.add_command("shell", Shell()) @manager.command def initdb(): """Init/reset database.""" if not prompt_bool("Are you sure? You will lose all your data!"): return db.drop_all() db.create_all() demo = User( username=u'demo', email='*****@*****.**',
'/usr/share/postgresql/8.4/contrib/postgis_comments.sql', 'db/schema.sql', 'db/extras.sql', 'db/functions.sql', 'db/sample.sql' ] def _make_context(): return dict(db=app.db) def prepare_context(): ctx = app.test_request_context() ctx.push() app.preprocess_request() manager.add_command("shell", Shell(make_context=_make_context)) ## MEMCACHED ## @manager.command def memcached(keys=False, stats=False, clear=False): """List memcached stored keys and server stats""" if 'CACHE_MEMCACHED_SERVERS' in app.config: servers = app.config['CACHE_MEMCACHED_SERVERS'] pp = pprint.PrettyPrinter(indent=4) for server in servers: host, port = server.split(':') mem = MemcachedStats(host, port) print '%s' % '=' * 80 print 'SERVER: %s:%s' % (host, port)
#-*-coding:utf-8-*- import os, sys sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) import logging logging.basicConfig(level=logging.INFO) from flaskext.script import Manager, Shell from scriptfan import app, db, oid, config_app, dispatch_handlers, dispatch_apps manager = Manager(app, with_default_commands=False) def _make_context(): return dict(app=app, db=db, oid=oid) manager.add_command('shell', Shell(make_context=_make_context)) @manager.option('-c', '--config', dest='config', help='Configuration file name', default='scriptfan.cfg') def runserver(config): config_app(app, config) dispatch_handlers(app) dispatch_apps(app) app.run(host='0.0.0.0') @manager.option('-c', '--config', dest='config', help='Configuration file name', default='scriptfan.cfg') def initdb(config='scriptfan.cfg'): config_app(app, config) try: db.drop_all() db.create_all()