<commit_before>"""Add new mdapi rule.

Revision ID: 38c9c18d342e
Revises: <PASSWORD>
Create Date: 2015-11-13 13:49:25.020563

"""

# revision identifiers, used by Alembic.
revision = '38c9c18d342e'
down_revision = '<PASSWORD>'

from alembic import op
import sqlalchemy as sa

path = 'fmn.rules:mdapi_repo_update'
target = "Events on packages that I own"

import fmn.lib
import fmn.lib.models

import fedmsg

# Running this script actually produces fedmsg messages (since the db changes.)
# Start fedmsg in active mode so that it talks to a fedmsg-relay
try:
    fedmsg.init(active=True)
except ValueError:
    pass


def upgrade():
    engine = op.get_bind().engine
    session = sa.orm.scoped_session(sa.orm.sessionmaker(bind=engine))

    valid_paths = fmn.lib.load_rules(root='fmn.rules')

    filters = session.query(fmn.lib.models.Filter).filter_by(name=target).all()
    print "Found %i filters" % len(filters)

    modified = 0
    for filt in filters:
        if len(filt.rules) < 15:
            # Someone has changed this filter dramatically, so let's not mess
            # with it.
            print "Avoiding %r on %r.  Only %i rules present." % (
                filt, filt.preference, len(filt.rules))
            continue

        modified += 1
        filt.add_rule(session, valid_paths, path, negated=True)

    print "Modified %i filters, total" % modified
    session.commit()


def downgrade():
    engine = op.get_bind().engine
    session = sa.orm.scoped_session(sa.orm.sessionmaker(bind=engine))

    valid_paths = fmn.lib.load_rules(root='fmn.rules')

    rules = session.query(fmn.lib.models.Rule).filter_by(code_path=path).all()
    print "Found %i rules" % len(rules)

    for rule in rules:
        rule.filter.remove_rule(session, path)

    session.commit()<commit_msg>Fix an older fmn downgrade script.<commit_after>"""Add new mdapi rule.

Revision ID: 38c9c<PASSWORD>
Revises: <PASSWORD>
Create Date: 2015-11-13 13:49:25.020563

"""

# revision identifiers, used by Alembic.
revision = '3<PASSWORD>'
down_revision = '<PASSWORD>'

from alembic import op
import sqlalchemy as sa

path = 'fmn.rules:mdapi_repo_update'
target = "Events on packages that I own"

import fmn.lib
import fmn.lib.models

import fedmsg

# Running this script actually produces fedmsg messages (since the db changes.)
# Start fedmsg in active mode so that it talks to a fedmsg-relay
try:
    fedmsg.init(active=True)
except ValueError:
    pass


def upgrade():
    engine = op.get_bind().engine
    session = sa.orm.scoped_session(sa.orm.sessionmaker(bind=engine))

    valid_paths = fmn.lib.load_rules(root='fmn.rules')

    filters = session.query(fmn.lib.models.Filter).filter_by(name=target).all()
    print "Found %i filters" % len(filters)

    modified = 0
    for filt in filters:
        if len(filt.rules) < 15:
            # Someone has changed this filter dramatically, so let's not mess
            # with it.
            print "Avoiding %r on %r.  Only %i rules present." % (
                filt, filt.preference, len(filt.rules))
            continue

        modified += 1
        filt.add_rule(session, valid_paths, path, negated=True)

    print "Modified %i filters, total" % modified
    session.commit()


def downgrade():
    engine = op.get_bind().engine
    session = sa.orm.scoped_session(sa.orm.sessionmaker(bind=engine))

    valid_paths = fmn.lib.load_rules(root='fmn.rules')

    rules = session.query(fmn.lib.models.Rule).filter_by(code_path=path).all()
    print "Found %i rules" % len(rules)

    for rule in rules:
        rule.filter.remove_rule(session, path, rule.id)

    session.commit()
{'fraction_non_alphanumeric': 0.11316079295154186, 'fraction_numerical': 0.018722466960352423, 'mean_word_length': 3.229336437718277, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '2269037', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1177, 'n_words': 319}