Esempio n. 1
0
from flask import current_app

from flask.cli import FlaskGroup, with_appcontext
from flask_migrate import MigrateCommand

from reminder import create_app
from reminder.reminder_app.models import db

cli = FlaskGroup(create_app=create_app)
cli.add_command('db', MigrateCommand)


@cli.command('create_db')
@with_appcontext
def create_db():
    db.init_app(current_app)
    db.drop_all()
    db.create_all()
    db.session.commit()


if __name__ == "__main__":
    cli()
Esempio n. 2
0
import db
import db.dump
import db.dump_manage
import db.exceptions
import db.stats
import db.user
import webserver
import similarity.manage
import similarity.script

ADMIN_SQL_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             'admin', 'sql')

cli = FlaskGroup(add_default_commands=False,
                 create_app=webserver.create_app_flaskgroup)
cli.add_command(shell_command)


@cli.command()
@click.option("--host", "-h", default="0.0.0.0", show_default=True)
@click.option("--port", "-p", default=8080, show_default=True)
def runserver(host, port):
    """Run a development server."""
    reload_on_files = current_app.config['RELOAD_ON_FILES']
    current_app.run(host=host,
                    port=port,
                    extra_files=reload_on_files,
                    threaded=True)


@cli.command()
Esempio n. 3
0
import click
from flask import current_app
from flask.cli import FlaskGroup, run_command
from maple import create_app
from maple.blog.db import Article, Category, Tag, TimeLine
from maple.extension import cache, db
from maple.model import User
from maple.storage.shell import Shell as StorageShell
from werkzeug.contrib.fixers import ProxyFix

app = create_app('config')
app.wsgi_app = ProxyFix(app.wsgi_app)

cli = FlaskGroup(add_default_commands=False, create_app=lambda r: app)
cli.add_command(run_command)

try:
    from flask_migrate import Migrate
    migrate = Migrate(app, db)
except ImportError:
    pass

DEFAULT_HOST = 'http://static.localhost:8001'
DEFAULT_KEY = ''


@cli.command('shell', short_help='Starts an interactive shell.')
def shell_command():
    ctx = current_app.make_shell_context()
    interact(local=ctx)
Esempio n. 4
0
File: shell.py Progetto: cryptk/opsy
from opsy.exceptions import DuplicateError
from opsy.utils import load_plugins, print_error, print_notice
from opsy.auth.models import Role, User, Permission


DEFAULT_CONFIG = '%s/opsy.ini' % os.path.abspath(os.path.curdir)


def create_opsy_app(info):
    return create_app(os.environ.get('OPSY_CONFIG', DEFAULT_CONFIG))


cli = FlaskGroup(create_app=create_opsy_app,  # pylint: disable=invalid-name
                 add_default_commands=False,
                 help='The Opsy management cli.')
cli.add_command(run_command)


@cli.command('run-scheduler')
def run_scheduler():
    """Run the scheduler."""
    scheduler = create_scheduler(current_app)
    try:
        current_app.logger.info('Starting the scheduler...')
        scheduler.start()
    except (KeyboardInterrupt, SystemExit):
        scheduler.shutdown()
        current_app.logger.info('Stopping the scheduler...')


@cli.command('shell')
Esempio n. 5
0
from flask.cli import FlaskGroup, shell_command

import db
import db.dump
import db.dump_manage
import db.exceptions
import db.stats
import db.user
import webserver
from db.testing import DatabaseTestCase

ADMIN_SQL_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             'admin', 'sql')

cli = FlaskGroup(add_default_commands=False, create_app=webserver.create_app)
cli.add_command(shell_command)


@cli.command()
@click.option("--host", "-h", default="0.0.0.0", show_default=True)
@click.option("--port", "-p", default=8080, show_default=True)
def runserver(host, port):
    """Run a development server."""
    reload_on_files = current_app.config['RELOAD_ON_FILES']
    current_app.run(host=host, port=port, extra_files=reload_on_files)


@cli.command()
@click.option("--force",
              "-f",
              is_flag=True,
Esempio n. 6
0
#!/usr/bin/env python3

from flask.cli import FlaskGroup

from main import app
from commands.demo import cli_hello
from commands.db import reset_db, seed_db

cli = FlaskGroup(app)

cli.add_command(reset_db)
cli.add_command(seed_db)
cli.add_command(cli_hello)

if __name__ == "__main__":
    cli()
Esempio n. 7
0
# @cli.command()
# def test():
#     """Runs the tests without code coverage"""
#     tests = unittest.TestLoader().discover('project/tests', pattern='test*.py')
#     result = unittest.TextTestRunner(verbosity=2).run(tests)
#     if result.wasSuccessful():
#         return 0
#     sys.exit(result)

# @cli.command()
# def cov():
#     """Runs the unit tests with coverage."""
#     tests = unittest.TestLoader().discover('project/tests')
#     result = unittest.TextTestRunner(verbosity=2).run(tests)
#     if result.wasSuccessful():
#         COV.stop()
#         COV.save()
#         print('Coverage Summary:')
#         COV.report()
#         COV.html_report()
#         COV.erase()
#         return 0
#     sys.exit(result)

cli.add_command(run_cli)
cli.add_command(test_cli)

if __name__ == "__main__":
    cli()
Esempio n. 8
0
import os

from dotenv import find_dotenv, load_dotenv
from flask.cli import FlaskGroup

from .. import make_app
from .attachments import commands as attachment_commands
from .database import commands as db_commands
from .pages import commands as page_commands
from .users import commands as user_commands


def create_app(_unused):  # pragma: no cover
    os.environ['FLASK_ENV'] = 'dev'
    return make_app()


cli = FlaskGroup(create_app=create_app, help='Zarządzanie aplikacją BIP')

cli.add_command(db_commands.db_ops)
cli.add_command(user_commands.user_ops)
cli.add_command(page_commands.page_ops)
cli.add_command(page_commands.label_ops)
cli.add_command(attachment_commands.attachment_ops)


def main():  # pragma: no cover
    load_dotenv(find_dotenv())
    cli()
Esempio n. 9
0
"""app main function."""
from flask import Flask
from flask.cli import FlaskGroup

from app.core.cli import greet
from app.core.router import urls_example


def create_app():
    """create_app function."""
    app = Flask(__name__)
    # app.config.from_object('config')

    @app.shell_context_processor
    def _shell_context():
        return {"app": app}

    with app.app_context():
        app.register_blueprint(urls_example)

    @app.route("/", methods=["GET"])
    def _index():
        return {"status": 200, "message": "espresso v1.0"}, 200

    return app


cli = FlaskGroup(create_app=create_app)

cli.add_command(greet)
Esempio n. 10
0
@click.pass_context
def recreate(ctx):

    db_url = conf.SQLALCHEMY_DATABASE_URI
    engine = sqlalchemy.create_engine(db_url)
    engine.execute(
        f"drop view if exists {conf.FRAC_SCHEDULE_TABLE_NAME}_most_recent_by_api10;"
    )
    engine.execute(f"drop table if exists {conf.FRAC_SCHEDULE_TABLE_NAME};")
    ctx.invoke(init)


def main(argv=sys.argv):
    """
    Args:
        argv (list): List of arguments
    Returns:
        int: A return code
    Does stuff.
    """

    cli()
    return 0


cli.add_command(run_cli)
cli.add_command(db_cli)

if __name__ == "__main__":
    cli()
Esempio n. 11
0
#!/usr/bin/env python
import click
from flask.cli import FlaskGroup
from friday.commands import commands


def create_app(_=None):
    from friday import make_app
    return make_app()


cli = FlaskGroup(create_app=create_app)
for src in commands.sources:
    cli.add_command(src)

if __name__ == '__main__':
    cli()
Esempio n. 12
0
    current_limit_per_ip = cache.get(ratelimit.ratelimit_per_ip_key)
    current_limit_window = cache.get(ratelimit.ratelimit_window_key)

    current_app.logger.info("Current values:")
    if current_limit_per_ip is None and current_limit_window is None:
        current_app.logger.info("No values set, showing limit defaults")
        current_limit_per_ip = ratelimit.ratelimit_per_ip_default
        current_limit_window = ratelimit.ratelimit_window_default
    current_app.logger.info("Requests per IP: %s" % current_limit_per_ip)
    current_app.logger.info("Window size (s): %s" % current_limit_window)

    if per_ip is not None and window_size is not None:
        if per_ip / float(window_size) < 1:
            current_app.logger.info(
                "Warning: Effective rate limit is less than 1 query per second"
            )

        ratelimit.set_rate_limits(per_ip, per_ip, window_size)
        current_app.logger.info("New ratelimit parameters set:")
        current_app.logger.info("Requests per IP: %s" % per_ip)
        current_app.logger.info("Window size (s): %s" % window_size)


# Please keep additional sets of commands down there
cli.add_command(db.dump_manage.cli, name="dump")
cli.add_command(similarity.manage.cli, name="similarity")

if __name__ == '__main__':
    cli()