<commit_before>import os
import logging
import random

from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand
from simpledoge import create_app, db

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

root = os.path.abspath(os.path.dirname(__file__) + '/../')

from bitcoinrpc.authproxy import AuthServiceProxy
from simpledoge.tasks import add_share, cleanup, payout
from simpledoge.models import Payout, Block, OneMinuteShare, Transaction
from flask import current_app, _request_ctx_stack

root = logging.getLogger()
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] %(message)s'))
root.addHandler(ch)
root.setLevel(logging.DEBUG)


@manager.command
def init_db():
    with app.app_context():
        db.session.commit()
        db.drop_all()
        db.create_all()


@manager.command
def power_shares():
    for i in xrange(2000000):
        add_share.delay('mrCuJ1WNXGpcBd8FA6H2cSeQLLXYuJ3qVt', 16)


@manager.option('-s', '--simulate', dest='simulate', default=True)
def cleanup_cmd(simulate):
    simulate = simulate != "0"
    cleanup(simulate=simulate)


@manager.option('-t', '--txid', dest='transaction_id')
def confirm_trans(transaction_id):
    trans = Transaction.query.filter_by(txid=transaction_id).first()
    trans.confirmed = True
    db.session.commit()


@manager.option('-s', '--simulate', dest='simulate', default=True)
def payout_cmd(simulate):
    simulate = simulate != "0"
    payout(simulate=simulate)


@manager.command
def fake_payout():
    addresses = ['mrCuJ1WNXGpcBd8FA6H2cSeQLLXYuJ3qVt',
                 'mn3gzxzs8WASz8WCr4ZTun2BmHbdEXG2tc',
                 'mg6pkcz4XdEHeD1ofpKahCAkXbpnKbL1jB',
                 'mhADrHGjRhp4U4Zjext6QwRJrVM73xvCDn']
    blockheight = 1000
    for i in xrange(blockheight):
        block = Block.create(random.choice(addresses), i, 50000, 5000, '')
        block.mature = True
        for address in addresses:
            if 0 == random.randint(0, 1):
                Payout.create(address, random.randint(1000000000, 10000000000), block)
    db.session.commit()


@manager.command
def migrate_one_min_shares_yes_really_sure():
    import datetime
    shares = OneMinuteShare.query.all()
    OneMinuteShare.query.delete()
    db.session.commit()
    for share in shares:
        new = share.minute + datetime.timedelta(hours=5)
        OneMinuteShare.create(share.user, share.shares, new)
    db.session.commit()


def make_context():
    app = _request_ctx_stack.top.app
    conn = AuthServiceProxy(
        "http://{0}:{1}@{2}:{3}/"
        .format(app.config['coinserv']['username'],
                app.config['coinserv']['password'],
                app.config['coinserv']['address'],
                app.config['coinserv']['port']))
    return dict(app=app,
                conn=conn)
manager.add_command("shell", Shell(make_context=make_context))
manager.add_command('db', MigrateCommand)


@manager.command
def runserver():
    current_app.run(debug=True, host='0.0.0.0')<commit_msg>Cleaned up some old unused management commands<commit_after>import os
import logging
import random

from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand
from simpledoge import create_app, db

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

root = os.path.abspath(os.path.dirname(__file__) + '/../')

from bitcoinrpc.authproxy import AuthServiceProxy
from simpledoge.tasks import add_share, cleanup, payout
from simpledoge.models import Payout, Block, OneMinuteShare, Transaction
from flask import current_app, _request_ctx_stack

root = logging.getLogger()
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] %(message)s'))
root.addHandler(ch)
root.setLevel(logging.DEBUG)


@manager.command
def init_db():
    with app.app_context():
        db.session.commit()
        db.drop_all()
        db.create_all()


@manager.command
def power_shares():
    for i in xrange(2000000):
        add_share.delay('mrCuJ1WNXGpcBd8FA6H2cSeQLLXYuJ3qVt', 16)


@manager.option('-s', '--simulate', dest='simulate', default=True)
def cleanup_cmd(simulate):
    simulate = simulate != "0"
    cleanup(simulate=simulate)


@manager.option('-t', '--txid', dest='transaction_id')
def confirm_trans(transaction_id):
    trans = Transaction.query.filter_by(txid=transaction_id).first()
    trans.confirmed = True
    db.session.commit()


@manager.option('-s', '--simulate', dest='simulate', default=True)
def payout_cmd(simulate):
    simulate = simulate != "0"
    payout(simulate=simulate)


def make_context():
    """ Setup a coinserver connection fot the shell context """
    app = _request_ctx_stack.top.app
    conn = AuthServiceProxy(
        "http://{0}:{1}@{2}:{3}/"
        .format(app.config['coinserv']['username'],
                app.config['coinserv']['password'],
                app.config['coinserv']['address'],
                app.config['coinserv']['port']))
    return dict(app=app, conn=conn)
manager.add_command("shell", Shell(make_context=make_context))
manager.add_command('db', MigrateCommand)


@manager.command
def runserver():
    current_app.run(debug=True, host='0.0.0.0')
{'fraction_non_alphanumeric': 0.1367231638418079, 'fraction_numerical': 0.019962335216572504, 'mean_word_length': 4.067748091603053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 2, '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': '7333558', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1759, 'n_words': 331}