<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Flask-Diamond (c) <NAME>

import sys
import traceback
sys.path.insert(0, '.')

from flask.ext.script import Manager, Shell, Server
from flask.ext.migrate import Migrate, MigrateCommand
import alembic
import alembic.config

from flask_diamond import create_app, db, security, models
app = create_app()


def _make_context():
    return dict(app=app, db=db, user_datastore=security.datastore)

migrate = Migrate(app, db, directory="flask_diamond/migrations")

manager = Manager(app)
manager.add_command("shell", Shell(make_context=_make_context))
manager.add_command("runserver", Server(port=app.config['PORT']))
manager.add_command("publicserver", Server(port=app.config['PORT'], host="0.0.0.0"))
manager.add_command('db', MigrateCommand)


@manager.option('-e', '--email', help='email address')
@manager.option('-p', '--password', help='password')
def adduser(email, password):
    "add a user to the database"
    models.User.create(email=email, password=password)


@manager.command
def init_db():<commit_msg>useradd and userdel<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Flask-Diamond (c) <NAME>

import sys
import traceback
sys.path.insert(0, '.')

from flask.ext.script import Manager, Shell, Server
from flask.ext.migrate import Migrate, MigrateCommand
import alembic
import alembic.config

from flask_diamond import create_app, db, security, models
app = create_app()


def _make_context():
    return dict(app=app, db=db, user_datastore=security.datastore)

migrate = Migrate(app, db, directory="flask_diamond/migrations")

manager = Manager(app)
manager.add_command("shell", Shell(make_context=_make_context))
manager.add_command("runserver", Server(port=app.config['PORT']))
manager.add_command("publicserver", Server(port=app.config['PORT'], host="0.0.0.0"))
manager.add_command('db', MigrateCommand)


@manager.option('-e', '--email', help='email address')
@manager.option('-p', '--password', help='password')
@manager.option('-a', '--admin', help='make user an admin user', action='store_true', default=None)
def useradd(email, password, admin):
    "add a user to the database"
    from LabDaemon import Models
    if admin:
        roles = ["Admin"]
    else:
        roles = ["User"]
    Models.User.register(
        email=email,
        password=password,
        confirmed=True,
        roles=roles
    )


@manager.option('-e', '--email', help='email address')
def userdel(email):
    "delete a user from the database"
    from LabDaemon import Models
    obj = Models.User.find(email=email)
    obj.delete()


@manager.command
def init_db():
{'fraction_non_alphanumeric': 0.1532349602724177, 'fraction_numerical': 0.004540295119182747, 'mean_word_length': 5.050343249427917, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5848505', 'n_tokens_mistral': 887, 'n_tokens_neox': 862, 'n_words': 200}