def setup(init_fn, **ctx): def init_app(): return configure(**ctx) mgr = script.Manager(init_app) mgr.add_command( 'runserver', flask.ext.script.Server(host=os.environ.get('LD32_HOST'), port=int(os.environ.get('LD32_PORT', 5000)))) @mgr.command def list_routes(): import urllib app = flask.current_app output = [] for rule in app.url_map.iter_rules(): methods = ','.join(rule.methods) line = "{:50s} {:20s} {}".format(rule.endpoint, methods, rule) output.append(line) for line in sorted(output): print(line) ld32.setup(mgr, **ctx) return mgr
def handle(self, *args, **kwargs): if self.__commands: # Resolve command list. namespaced_commands = defaultdict(lambda: []) for name, command in self.__commands: namespace = getattr(command, 'namespace', None) if namespace: namespaced_commands[namespace].append((name, command)) continue super().add_command(name, command) # Clear command list. self.__commands = [] # Resolve namespaced commands. for namespace in namespaced_commands: manager = script.Manager() for name, command in namespaced_commands[namespace]: manager.add_command(name, command) super().add_command(namespace, manager) # Continue on with handling the command. super().handle(*args, **kwargs)
# -*- coding:utf-8 -*- from flask.ext import script import commands if __name__ == "__main__": from main import app_factory import config manager = script.Manager(app_factory) manager.add_option("-c", "--config", dest="config", required=False, default=config.Dev) manager.add_command("test", commands.Test()) manager.add_command("create_db", commands.CreateDB()) manager.add_command("drop_db", commands.DropDB()) manager.run()
from decimal import Decimal import time import datetime as dt import flask from flask.ext import script from flask.ext.migrate import Migrate, MigrateCommand, _get_config, stamp from alembic.migration import MigrationContext from alembic.script import ScriptDirectory import six from .. import create_app, db, migrate, models, auth, killmail from .datetime import utc if six.PY3: unicode = str manager = script.Manager(create_app) class AbsolutePathAction(argparse.Action): """Custom argparse.Action that transforms path strings into absolute paths. """ def __call__(self, parser, namespace, values, option_string=None): current_absolute = os.path.abspath(os.getcwd()) if isinstance(values, str): new_values = os.path.join(current_absolute, values) else: new_values = [] for value in values: real_path = os.path.join(current_absolute, values) new_values.append(real_path) setattr(namespace, self.dest, new_values)
import os from flask.ext import script from animeta import app, db manager = script.Manager(app) # Override the default `runserver` command, to monitor the change of # the configuration file. # XXX: `Config.root_path` is an undocumented attribute. config_path = os.path.join(app.config.root_path, 'config.py') runserver = script.Server(extra_files=[config_path]) manager.add_command('runserver', runserver) db_manager = script.Manager() @db_manager.command def create_all(): db.create_all() @db_manager.command def drop_all(): if script.prompt_bool('This action will DESTROY ALL DATA. Continue'): db.drop_all() manager.add_command('db', db_manager) if __name__ == '__main__': manager.run()
import websocket import json import re import random import time import struct import base64 from flask.ext import script from sirius.emulate import protocol_fragments as pf def sub_opts(app, **kwargs): pass manager = script.Manager( sub_opts, usage="Emulate a real printer, websockets and all.") class State: """Keep track of printer state. Only one per process so global state is OK.""" online = True needs_key = True device_address = None bridge_address = None def heartbeat(ws): while True: if (State.online, State.needs_key) == (True, True): ws.send(pf.ENCRYPTION_KEY_REQUIRED % dict(bridge_address=State.bridge_address,
from flask.ext import script from werkzeug.wsgi import DispatcherMiddleware from www import main from subprocess import call def build_application(): base = Flask(__name__, static_folder=None) base.config.from_object('defaults') base.config.from_envvar('CONFIG') base.wsgi_app = DispatcherMiddleware(base.wsgi_app, { '': main.build_app(config=base.config) }) return base manager = script.Manager(build_application) def sync_command(*args, **kwargs): return ( 'AWS_ACCESS_KEY_ID={AWS_ACCESS_KEY_ID} ' 'AWS_SECRET_ACCESS_KEY={AWS_SECRET_ACCESS_KEY} ' 'aws s3 sync {target} {destination} --region {region} ' '--delete --cache-control "max-age=604800, public, no-transform" ' ).format(**kwargs) @manager.command def collect(verbose=True): for root, application in app.wsgi_app.mounts.iteritems(): if 'collect' in application.extensions:
#!/usr/bin/env python3 import getpass import os import subprocess from flask.ext import script import flask from app import models import config import app _app = app.app_factory(config.config[os.getenv("AC_CONFIG") or "development"]) manager = script.Manager(_app) class _AddAPIUser(script.Command): option_list = script.Option("username") def __init__(self, app): super(script.Command.__init__()) self.app = app def run(self, username): while True: password = getpass.getpass(prompt="Enter Password: "******"Confirm Password: "******"Passwords did not match. Please try again.")
def main(): manager = script.Manager(app) manager.run()
#!python from flask.ext import script import plyus import config plyus.create_flask_app(config.dev) manager = script.Manager(plyus.app) @manager.command def create_db(): from plyus import db db.create_all() @manager.command def run(): plyus.app.run(debug=True) @manager.command def diagram(): from sqlalchemy_schemadisplay import create_schema_graph from plyus import db # Database host = 'localhost' engine = 'postgresql' database = 'database' username = '******'