<commit_before>"""
    marvin.management
    ~~~~~~~~~~~~~~~~~

    Configures the manager, and acts as an entry point for the manage command.

"""
# pylint: disable=invalid-name
from . import create_app, db
from .models import Stream, Entry, Movie

from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand

from os import path

app = create_app()
migrate = Migrate(app, db)
manager = Manager(app)

manager.add_command('db', MigrateCommand)

@manager.command
def runserver(): # pragma: no cover
    """ Start a devserver on port 5000 """
    config_file = path.abspath(path.join(path.dirname(__file__), '..', 'dev_config.py'))
    dev_app = create_app(config_file=config_file)
    init_db()
    dev_app.run()


@manager.command
def delete_streams_and_entries(wipe_movies=False):
    """ Delete all streams and entries.

    After deletion it will reset movie stream counts to 0. Can optionally also
    delete all movies, if the --wipe_movies flag is used. """

    all_streams = Stream.query.all()
    for stream in all_streams:
        db.session.delete(stream)
    all_entries = Entry.query.all()
    for entry in all_entries:
        db.session.delete(entry)

    if wipe_movies:
        all_movies = Movie.query.all()
        for movie in all_movies:
            db.session.delete(movie)

    else:
        # Just reset the stream counts
        movies_with_stream_count = Movie.query.filter(Movie.number_of_streams > 0).all()
        for movie in movies_with_stream_count:
            movie.number_of_streams = len([s for s in movie.streams if s.public])
            db.session.add(movie)
    db.session.commit()


@manager.command
def init_db():
    """ Create the database. Will not migrate if one already exists. """
    with app.test_request_context():
        db.create_all()<commit_msg>Add mgmt command to recount streams<commit_after>"""
    marvin.management
    ~~~~~~~~~~~~~~~~~

    Configures the manager, and acts as an entry point for the manage command.

"""
# pylint: disable=invalid-name
from . import create_app, db
from .models import Stream, Entry, Movie

from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand

from os import path

app = create_app()
migrate = Migrate(app, db)
manager = Manager(app)

manager.add_command('db', MigrateCommand)

@manager.command
def runserver(): # pragma: no cover
    """ Start a devserver on port 5000 """
    config_file = path.abspath(path.join(path.dirname(__file__), '..', 'dev_config.py'))
    dev_app = create_app(config_file=config_file)
    init_db()
    dev_app.run()


@manager.command
def delete_streams_and_entries(wipe_movies=False):
    """ Delete all streams and entries.

    After deletion it will reset movie stream counts to 0. Can optionally also
    delete all movies, if the --wipe_movies flag is used. """

    all_streams = Stream.query.all()
    for stream in all_streams:
        db.session.delete(stream)
    all_entries = Entry.query.all()
    for entry in all_entries:
        db.session.delete(entry)

    if wipe_movies:
        all_movies = Movie.query.all()
        for movie in all_movies:
            db.session.delete(movie)
    else:
        # Just reset the stream counts
        reset_movie_stream_counts()
    db.session.commit()


@manager.command
def reset_movie_stream_counts():
    movies_with_stream_count = Movie.query.filter(Movie.number_of_streams > 0).all()
    for movie in movies_with_stream_count:
        movie.number_of_streams = len([s for s in movie.streams if s.public])
    db.session.commit()



@manager.command
def init_db():
    """ Create the database. Will not migrate if one already exists. """
    with app.test_request_context():
        db.create_all()
{'fraction_non_alphanumeric': 0.10740938166311301, 'fraction_numerical': 0.0031982942430703624, 'mean_word_length': 3.3588850174216027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3177544', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1146, 'n_words': 328}