Пример #1
0
    def manager(self):
        """Integrate a Flask-Script."""
        from flask_script import Manager, Command

        manager = Manager(usage="Migrate database.")
        manager.add_command('create', Command(self.cmd_create))
        manager.add_command('migrate', Command(self.cmd_migrate))
        manager.add_command('rollback', Command(self.cmd_rollback))
        manager.add_command('list', Command(self.cmd_list))

        return manager
Пример #2
0
 def __init__(self):
     Command.__init__(self, func=Problem.import_repository)
Пример #3
0
from flask_rq2.script import RQManager
from flask_migrate import Migrate, MigrateCommand

app = create_app()
migrate = Migrate(app, db)
migrate.configure_callbacks.append(include_url_to_config)

manager = Manager(app,
                  with_default_commands=False,
                  usage='Manage montecristo instance')


def run():
    app.run(debug=app.config['DEBUG'],
            host=app.config['HOST'],
            port=app.config['PORT'],
            threaded=True)


tests_command = Command(run_unit_tests)
tests_command.option_list[0].kwargs['nargs'] = '*'

manager.add_command('db', MigrateCommand)
manager.add_command("run", Command(run))
manager.add_command('rq', RQManager(rq))
manager.add_command("test", tests_command)
manager.add_command("shell", Shell(make_context=shel_context))

if __name__ == '__main__':
    manager.run()
Пример #4
0
def createAdmin():
    user = User.query.filter_by(
        email='*****@*****.**').first()
    if user:
        user.admin = True
        user.update()
    else:
        user = User(name="Admin",
                    email='*****@*****.**',
                    password=bcrypt.generate_password_hash(
                        'educ2020distminesec', BCRYPT_LOG_ROUNDS).decode(),
                    admin=True)
        user.insert()

    print("successfully inserted")
    print(user.id)


def dropAllPastTimetables():
    timetables = TimeTable.query.filter(TimeTable.time < datetime.now()).all()
    for timetable in timetables:
        print(timetable)
        timetable.delete()
    print("successful")


if __name__ == '__main__':
    manager = Manager(app)
    manager.add_command('creat_admin', Command(createAdmin))
    manager.add_command('delete_timetable', Command(dropAllPastTimetables))
    manager.run()
Пример #5
0
def command_entry_point():
    command_manager.run(commands={'setup_sbe_app': Command(setup_sbe_app)},)
Пример #6
0
            setattr(command, key, val)

        command.finalize_options()
        command.run()

    return _wrapper


cmd_list = ['init_catalog', 'extract_messages', 'update_catalog']
cmd_list += [cmd + '_js' for cmd in cmd_list]
cmd_list.append('compile_catalog')

for cmd_name in cmd_list:
    cmd_class = getattr(frontend, re.sub(r'_js$', '', cmd_name))

    command = Command(wrap_distutils_command(cmd_class))

    for opt, short_opt, description in cmd_class.user_options:

        long_opt_name = opt.rstrip('=')
        var_name = long_opt_name.replace('-', '_')
        opts = ['--' + long_opt_name]

        if short_opt:
            opts.append('-' + short_opt)

        command.add_option(
            Option(*opts,
                   dest=var_name,
                   action=(None if opt.endswith('=') else 'store_true'),
                   help=description,
Пример #7
0
 def __init__(self, app: Flask) -> None:
     Command.__init__(self)
     self.app = app
Пример #8
0
        command.finalize_options()
        command.run()

    return _wrapper


cmd_list = ['init_catalog', 'extract_messages', 'update_catalog']
cmd_list += [cmd + '_js' for cmd in cmd_list]
cmd_list.append('compile_catalog')


for cmd_name in cmd_list:
    cmd_class = getattr(frontend, re.sub(r'_js$', '', cmd_name))

    command = Command(wrap_distutils_command(cmd_class))

    for opt, short_opt, description in cmd_class.user_options:

        long_opt_name = opt.rstrip('=')
        var_name = long_opt_name.replace('-', '_')
        opts = ['--' + long_opt_name]

        if short_opt:
            opts.append('-' + short_opt)

        command.add_option(Option(*opts, dest=var_name,
                                  action=(None if opt.endswith('=') else 'store_true'), help=description,
                                  default=DEFAULT_OPTIONS.get(cmd_name, {}).get(var_name)))

    IndicoI18nManager.add_command(cmd_name, command)
Пример #9
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask_script import Manager, Command
from app.commands.poi2es import PoiElastic

TaskCommand = Manager()

TaskCommand.add_command('poi2es', Command(PoiElastic.create_index))

if __name__ == '__main__':
    TaskCommand.run()
Пример #10
0
 def __init__(self, app: Flask) -> None:
     Command.__init__(self)
     self.app = app
Пример #11
0
from flask_script import Command, Manager, Shell

from 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()
Пример #12
0
def command_entry_point():
    command_manager.run(commands={"setup_sbe_app": Command(setup_sbe_app)})
Пример #13
0
from flask_script import Manager, Command

PokerCommand = Manager()

from .init_db import init_db, upgrade_preflop
PokerCommand.add_command('init_db', Command(init_db))
PokerCommand.add_command('upgrade_preflop', Command(upgrade_preflop))

from .statistic import statistic_5cards, statistic_7cards, statistic_games, statistic_preflop
PokerCommand.add_command('statistic_5cards', Command(statistic_5cards))
PokerCommand.add_command('statistic_7cards', Command(statistic_7cards))
PokerCommand.add_command('statistic_games', Command(statistic_games))
PokerCommand.add_command('statistic_preflop', Command(statistic_preflop))

from .theory_prob import prob_5cards, prob_7cards, preflop
PokerCommand.add_command('prob_5cards', Command(prob_5cards))
PokerCommand.add_command('prob_7cards', Command(prob_7cards))
PokerCommand.add_command('preflop', Command(preflop))
Пример #14
0
 def get_options(self):
     return Command.get_options(self)
Пример #15
0
 def __init__(self, host='127.0.0.1', port=8000, workers=4):
     self.port = port
     self.host = host
     self.workers = workers
     Command.__init__(self)
Пример #16
0
from flask_script import Manager, Shell, Command

from app import app, db
from app.models import User

manager = Manager(app)

if __name__ == '__main__':
    def make_shell_context():
        return dict(app=app, db=db, User=User)


    def init():
        db.drop_all()
        db.create_all()
        print('Init success!')


    manager.add_command('shell', Shell(make_context=make_shell_context))
    manager.add_command('init', Command(func=init))

    manager.run()
Пример #17
0
#!/usr/bin/env python

from flask_script import Manager, Command
from flask_migrate import Migrate, MigrateCommand

from app import create_app
from tasks import run_celery
from tests.command import PytestCommand




manager = Manager(create_app)
#manager.add_option('-c', '--config', dest='config_file', required=False)
manager.add_command('db', MigrateCommand)

manager.add_command('runcelery', Command(run_celery))
manager.add_option('-c', '--config', dest='config', required=False)

if __name__ == '__main__':
    manager.run()
Пример #18
0
manager = Manager(app)


@manager.option('-s', '--setting', dest='setting', default='development')
def hello(setting):
    manager.app(setting=setting)


def test():
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=3).run(tests)


migrate = Migrate(app, db)

manager.add_command('runserver', Server(host=IP, port=SERVER_PORT))
manager.add_command('db', MigrateCommand)
manager.add_command('test', Command(test))

if __name__ == '__main__':
    handler = logging.FileHandler('./logs/flask.log', encoding='UTF-8')
    handler.setFormatter(logging.DEBUG)
    logging_format = logging.Formatter(
        '%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s'
    )
    handler.setFormatter(logging_format)
    app.logger.addHandler(handler)
    manager.run()
Пример #19
0
        def decorator(func):
            command = Command(func)
            command.capture_all_args = capture_all
            self.add_command(func.__name__, command)

            return func
Пример #20
0
 def __init__(self, app):
     Command.__init__(self)
     self.app = app
     self.dir_name = os.path.join(app.root_path, "translations")
     self.messages_file_path = os.path.join(self.dir_name, "messages.pot")