Exemplo n.º 1
0
Arquivo: shell.py Projeto: cryptk/opsy
from opsy.flask_extensions import db
from opsy.app import create_app, create_scheduler
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...')
Exemplo n.º 2
0
    BABEL_TRANSLATION_DIRECTORIES = os.path.abspath(
        os.path.join(
            os.path.dirname(__file__), os.pardir, 'flask_maple',
            'translations'))


app = Flask(__name__)
app.config.from_object(config)
db.init_app(app)

admin = Admin(name='devops', template_mode='bootstrap3')
for model in [User, Group]:
    admin.add_view(ModelView(model, db.session, category='user'))
admin.init_app(app)

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


@cli.command('shell', short_help='Starts an interactive shell.')
def shell_command():
    ctx = current_app.make_shell_context()
    interact(local=ctx)


@cli.command()
def runserver():
    app.run()


@cli.command()
Exemplo n.º 3
0
#!/usr/bin/env python
import glob
import os
import shutil
import subprocess
import click
from flask.cli import FlaskGroup
from backend.config import DevelopmentConfig
from backend.api import db, create_app
from backend.api.models import User

app = create_app(DevelopmentConfig())

cli = FlaskGroup(
    add_app_option=False,
    create_app=lambda _: app,
    help='Time tracker CLI',
)


@cli.command(with_appcontext=False)
def clean():
    """Cleans build files."""
    shutil.rmtree('./dist', ignore_errors=True)
    for path in glob.iglob('./backend/**/__pycache__', recursive=True):
        shutil.rmtree(path, ignore_errors=True)


@cli.command()
def create_db():
    """Create database"""
Exemplo n.º 4
0
from flask.cli import FlaskGroup
from project import create_app, db

from project.api.models import User

import unittest
import coverage

COV = coverage.coverage(branch=True,
                        include='project/*',
                        omit=['project/tests/*', 'project/config.py'])
COV.start()

app = create_app()
cli = FlaskGroup(create_app=create_app)


@cli.command()
def recreate_db():
    db.drop_all()
    db.create_all()
    db.session.commit()


@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
Exemplo n.º 5
0
from flask.cli import FlaskGroup

from bsdetector import app

cli = FlaskGroup(app)

if __name__ == "__main__":
    cli()
Exemplo n.º 6
0
from __future__ import print_function
from flask.cli import FlaskGroup
from db import dump
import shutil
import click
import re
import os
import webserver

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


@cli.command()
@click.option("--location",
              "-l",
              default=os.path.join(os.getcwd(), 'export'),
              show_default=True,
              help="Directory where dumps need to be created")
@click.option("--threads", "-t", type=int)
@click.option("--rotate", "-r", is_flag=True)
@click.pass_context
def full(ctx, location, threads, rotate):
    """This command creates:
    1. New incremental dump record (+ incremental dumps unless it's the first record)
    2. Full database dump
    3. Full JSON dump

    Archive rotation is enabled by default for full dumps.
    """
    try:
Exemplo n.º 7
0
import click
import json
import os

from datetime import datetime
from flask.cli import FlaskGroup
from flask_migrate import MigrateCommand

from project import create_app, db, guard
from project.user.models import User
from project.listing.models import Listing, Room, Address, Amenity, ListingImage, Preference, Restriction
from project.review.models import Review

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


@cli.command('recreate_db')
def recreate_db():
    db.drop_all()
    db.create_all()
    db.session.commit()


def populate_users():
    with open('data/people.json') as f:
        data = json.load(f)
        for person in data:
            u = User(first_name=person['first_name'],
Exemplo n.º 8
0
"""The application launch script"""

from flask.cli import FlaskGroup
from app import flask_app
from app.database import db
from db.seeds.user import seed_user
from db.seeds.role_permission import seed_role, seed_permission,\
                                        map_role_to_permission

cli = FlaskGroup(flask_app)


@cli.command("reset_tables")
def reset_tables():
    """
    Drop and re-create all tables
    """
    db.drop_all()
    db.create_all()


@cli.command("seed")
def seed():
    """
    Generate seed/fake data for application database
    """
    seed_role()
    seed_permission()
    map_role_to_permission()
    seed_user()
Exemplo n.º 9
0
def test_disable_dotenv_from_env(monkeypatch, runner):
    monkeypatch.chdir(test_path)
    monkeypatch.setitem(os.environ, "FLASK_SKIP_DOTENV", "1")
    runner.invoke(FlaskGroup())
    assert "FOO" not in os.environ
Exemplo n.º 10
0
from werkzeug.contrib.fixers import ProxyFix
from code import interact
from getpass import getpass

from forums import create_app
from forums.extension import db, cache, search
from forums.api.user.models import User

import click
import os
import sys

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


@cli.command('shell', short_help='Starts an interactive shell.')
def shell_command():
    ctx = current_app.make_shell_context()
    interact(local=ctx)