コード例 #1
0
ファイル: tests.py プロジェクト: alekzvik/flask-script
 def test_run_with_default_command(self):
     manager = Manager(self.app)
     manager.add_command('simple', SimpleCommand())
     try:
         manager.run(default_command='simple')
     except SystemExit, e:
         assert e.code==0
コード例 #2
0
ファイル: test_script.py プロジェクト: olt/flask-assets
    def test_call(self):
        # Setup the webassets.script with a mock main() function,
        # so we can check whether our call via Flask-Script actually
        # goes through.
        def dummy_main(argv, *a, **kw):
            self.last_script_call = argv
            return 0
        from webassets import script
        old_main = script.main
        script.main = dummy_main

        try:
            mgmt = Manager(self.app)
            mgmt.add_command('assets', ManageAssets(self.env))

            try:
                # -h is a great test as that is something Flask-Script might
                # want to claim for itself.
                sys.argv = ['./manage.py', 'assets', '-h']
                mgmt.run()
            except SystemExit:
                # Always raised, regardless of success or failure of command
                pass
            assert self.last_script_call == ['-h']
        finally:
            script.main = old_main
コード例 #3
0
ファイル: tests.py プロジェクト: alekzvik/flask-script
    def test_run_no_name(self):

        manager = Manager(self.app)
        sys.argv = ["manage.py"]
        try:
            manager.run()
        except SystemExit, e:
            assert e.code == 1
コード例 #4
0
ファイル: tests.py プロジェクト: alekzvik/flask-script
    def test_run_not_existing(self):

        manager = Manager(self.app)
        sys.argv = ["manage.py", "simple"]
        try:
            manager.run()
        except SystemExit, e:
            assert e.code == 1
コード例 #5
0
ファイル: tests.py プロジェクト: sbook/flask-script
 def test_command_with_custom_handle_method(self):
     manager = Manager(self.app)
     manager.add_command("handle", CommandWithCustomHandle())
     sys.argv = ["manage.py", "handle", "pos1", "pos2", "--bar"]
     try:
         manager.run()
     except SystemExit, e:
         assert e.code == 0
コード例 #6
0
ファイル: tests.py プロジェクト: alekzvik/flask-script
 def test_run_catch_all(self):
     manager = Manager(self.app)
     manager.add_command("catch", CommandWithCatchAll())
     sys.argv = ["manage.py", "catch", "pos1", "--foo", "pos2", "--bar"]
     try:
         manager.run()
     except SystemExit, e:
         assert e.code == 0
コード例 #7
0
ファイル: tests.py プロジェクト: alekzvik/flask-script
    def test_run_existing_bind_later(self):

        manager = Manager(self.app)
        sys.argv = ["manage.py", "simple"]
        try:
            manager.run({'simple':SimpleCommand()})
        except SystemExit, e:
            assert e.code == 0
コード例 #8
0
ファイル: tests.py プロジェクト: alekzvik/flask-script
    def test_run_dynamic_options(self):

        manager = Manager(self.app)
        manager.add_command("simple", CommandWithDynamicOptions('Fred'))
        sys.argv = ["manage.py", "simple"]
        try:
            manager.run()
        except SystemExit, e:
            assert e.code == 0
コード例 #9
0
ファイル: tests.py プロジェクト: alekzvik/flask-script
    def test_run_good_options(self):

        manager = Manager(self.app)
        manager.add_command("simple", CommandWithOptions())
        sys.argv = ["manage.py", "simple", "--name=Joe"]
        try:
            manager.run()
        except SystemExit, e:
            assert e.code == 0
コード例 #10
0
ファイル: tests.py プロジェクト: alekzvik/flask-script
    def test_run_existing(self):

        manager = Manager(self.app)
        manager.add_command("simple", SimpleCommand())
        sys.argv = ["manage.py", "simple"]
        try:
            manager.run()
        except SystemExit, e:
            assert e.code == 0
コード例 #11
0
ファイル: tests.py プロジェクト: alekzvik/flask-script
    def test_run_bad_options(self):

        manager = Manager(self.app)
        manager.add_command("simple", CommandWithOptions())
        sys.argv = ["manage.py", "simple", "--foo=bar"]
        try:
            sys_stderr_orig = sys.stderr
            sys.stderr = StringIO.StringIO()
            manager.run()
        except SystemExit, e:
            assert e.code == 2
コード例 #12
0
ファイル: test_script.py プロジェクト: aisipos/flask-assets
    def test_call_auto_env(self):
        """Regression test: Passing the environment to the ManageAssets command
        is optional, it can be auto-detected."""
        mgmt = Manager(self.app)
        mgmt.add_command('assets', ManageAssets())

        try:
            # Used to raise an error due to the env not being properly set.
            sys.argv = ['./manage.py', 'assets', 'rebuild']
            mgmt.run()
        except SystemExit:
            # Always raised, regardless of success or failure of command
            pass
コード例 #13
0
    def test_call_auto_env(self):
        """Regression test: Passing the environment to the ManageAssets command
        is optional, it can be auto-detected."""
        mgmt = Manager(self.app)
        mgmt.add_command('assets', ManageAssets())

        try:
            # Used to raise an error due to the env not being properly set.
            sys.argv = ['./manage.py', 'assets', 'build']
            mgmt.run()
        except SystemExit:
            # Always raised, regardless of success or failure of command
            pass
コード例 #14
0
ファイル: test_script.py プロジェクト: aisipos/flask-assets
    def test_call(self):
        # Setup the webassets.script with a mock main() function,
        # so we can check whether our call via Flask-Script actually
        # goes through.
        test_inst = self
        class DummyArgparseImplementation(GenericArgparseImplementation):
            def run_with_argv(self, argv):
                test_inst.last_script_call = argv
                return 0

        mgmt = Manager(self.app)
        mgmt.add_command('assets',
                ManageAssets(self.env, impl=DummyArgparseImplementation))

        try:
            # -h is a great test as that is something Flask-Script might
            # want to claim for itself.
            sys.argv = ['./manage.py', 'assets', '-h']
            mgmt.run()
        except SystemExit:
            # Always raised, regardless of success or failure of command
            pass
        assert self.last_script_call == ['-h']
コード例 #15
0
    def test_call(self):
        # Setup the webassets.script with a mock main() function,
        # so we can check whether our call via Flask-Script actually
        # goes through.
        test_inst = self

        class DummyArgparseImplementation(GenericArgparseImplementation):
            def run_with_argv(self, argv):
                test_inst.last_script_call = argv
                return 0

        mgmt = Manager(self.app)
        mgmt.add_command(
            'assets', ManageAssets(self.env, impl=DummyArgparseImplementation))

        try:
            # -h is a great test as that is something Flask-Script might
            # want to claim for itself.
            sys.argv = ['./manage.py', 'assets', '-h']
            mgmt.run()
        except SystemExit:
            # Always raised, regardless of success or failure of command
            pass
        assert self.last_script_call == ['-h']
コード例 #16
0
ファイル: __init__.py プロジェクト: pombredanne/moin2
def main(default_command='moin', wiki_config=None):
    """
    console_script entry point
    """
    from MoinMoin.app import create_app
    from flaskext.script import Manager, Server

    manager = Manager(create_app)
    manager.add_option('-c', '--config', dest='config', required=False, default=wiki_config)
    manager.add_option('-i', '--index-create', action='store_true', dest='create_index', required=False, default=False)
    manager.add_option('-s', '--storage-create', action='store_true', dest='create_storage', required=False, default=False)
    manager.add_command("moin", Server(host='127.0.0.1', port=8080))

    from MoinMoin.script.maint import index
    manager.add_command("index-create", index.IndexCreate())
    manager.add_command("index-build", index.IndexBuild())
    manager.add_command("index-update", index.IndexUpdate())
    manager.add_command("index-destroy", index.IndexDestroy())
    manager.add_command("index-move", index.IndexMove())
    manager.add_command("index-optimize", index.IndexOptimize())
    manager.add_command("index-dump", index.IndexDump())
    from MoinMoin.script.maint import serialization
    manager.add_command("save", serialization.Serialize())
    manager.add_command("load", serialization.Deserialize())
    from MoinMoin.script.account.create import Create_User
    manager.add_command("account_create", Create_User())
    from MoinMoin.script.account.disable import Disable_User
    manager.add_command("account_disable", Disable_User())
    from MoinMoin.script.account.resetpw import Set_Password
    manager.add_command("account_password", Set_Password())
    from MoinMoin.script.maint.reduce_revisions import Reduce_Revisions
    manager.add_command("maint_reduce_revisions", Reduce_Revisions())
    from MoinMoin.script.maint.set_meta import Set_Meta
    manager.add_command("maint_set_meta", Set_Meta())
    from MoinMoin.script.maint import modify_item
    manager.add_command("item-get", modify_item.GetItem())
    manager.add_command("item-put", modify_item.PutItem())
    from MoinMoin.script.maint.modified_systemitems import Modified_SystemItems
    manager.add_command("maint_modified_systemitems", Modified_SystemItems())
    from MoinMoin.script.migration.moin19.import19 import ImportMoin19
    manager.add_command("import19", ImportMoin19())

    from MoinMoin.script.maint.moinshell import MoinShell
    manager.add_command("shell", MoinShell())

    return manager.run(default_command=default_command)
コード例 #17
0
ファイル: manage.py プロジェクト: jamesward/flaskbars
from flaskext.script import Manager
from web import db, app

manager = Manager(app)


@manager.command
def createDbSchema():
    db.create_all()


if __name__ == "__main__":
    manager.run()
コード例 #18
0
ファイル: manage.py プロジェクト: kura/postfix-mgmt
    else:
        domains = Domain.query.all()
    for d in domains:
        print "Addresses for %s:" % d.name
        for a in Address.query.filter_by(domain=d):
            print "- %s@%s active:%s" % (a.username, a.domain.name, a.active)

def add_address(**values):
    domain = prompt_choices("Domain (%s@DOMAIN)" % values['username'], (d.name for d in Domain.query.order_by('-name')))
    passwd = prompt_pass("Password")

@manager.option("-a", "--active", dest="active", default=False)
@manager.option("-e", "--email", dest="email")
@manager.option("-m", "--method", dest="method", choices=('list', 'add', 'edit', 'del'), required=True)
def admin(**values):
    if values['method'] == "add":
        add_admin(**values)

def add_admin(**values):
    values['password'] = prompt_pass("Password")
    request.form = AdminAddForm(MultiDict(values))
    if not validate_fields(request.form):
        print_field_errors(values['email'], request.form)
    a = Admin(values['email'], create_password(values['password']), values['active'])
    db.session.add(a)
    db.session.commit()
    print "Admin '%s' successfully added" % values['email'] 

if __name__ == "__main__":
    manager.run()
コード例 #19
0

@script.command
def rerender_entries(source_tag=None):
    """Rerender stream entries."""
    from jmoiron.stream.models import Entry
    if source_tag:
        entries = Entry.find({'source_tag': source_tag})
    else:
        entries = Entry.find()
    for e in entries:
        e.save()


@script.shell
def shell_context():
    from jmoiron.blog.models import Post
    from jmoiron.auth.models import User

    return {
        'app': app,
        'db': db,
        'cache': None,
        'Post': Post,
        'User': User,
    }


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

from flaskext.script import Manager, Server, Shell, prompt_bool
from example import app
from example.extensions import db

# 脚本管理
script_manager = Manager(app)
script_manager.add_command('runserver', Server('0.0.0.0', port=5000))

def _make_context():
    return { 'db':db }
script_manager.add_command("shell", Shell(make_context=_make_context))

@script_manager.command
def createall():
    "Creates database tables"
    db.create_all()

@script_manager.command
def dropall():
    "Drops all database tables"
    if prompt_bool("Are you sure ? You will lose all your data !"):
        db.drop_all()

if __name__ == '__main__':
    script_manager.run()
コード例 #21
0
ファイル: blogen.py プロジェクト: alexex/blogen
@static.register_generator
def postindex_url_generator():
	pagination=paginate(posts, page=1)
	i = 1
	while i <= pagination.pages:
		yield 'postindex', {'page': i}
		i = i+1


# cli-interface
@cli.command
def setup():
	print "Setting necessary folders up."
	folders = ['pages', 'posts', 'static']
	for folder in folders:
		os.mkdir(folder)
	print "Setup finished."

@cli.command
def build():
	print "building static website.."
	with warnings.catch_warnings():
		warnings.simplefilter("ignore")
		static.freeze()
	print "finished!"

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