<commit_before>"""\
Migrate dataset type

"""
import logging
import transaction
from pyramid.paster import get_app
from contentbase.interfaces import (
    STORAGE,
)

EPILOG = __doc__

logger = logging.getLogger(__name__)


TYPE_MAP = {
    'project': 'project',
    'composite': 'ucsc_browser_composite',
    'publication': 'publication_data',
    'reference': 'reference',
    'paired set': 'paired_set',
    'annotation': 'annotation',
}


def run(app):
    storage = app.registry[STORAGE].write

    for model in storage.__iter__('dataset'):
        dataset_type = model.properties['dataset_type']
        new_type = TYPE_MAP[dataset_type]
        model.item_type = new_type
        logger.info('Updated %s, %r -> %s', model.rid, dataset_type, new_type)


def main():
    import argparse
    parser = argparse.ArgumentParser(
        description="Migrate dataset type", epilog=EPILOG,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )
    parser.add_argument('--app-name', help="Pyramid app name in configfile")
    parser.add_argument('--abort', action='store_true', help="Rollback transaction")
    parser.add_argument('config_uri', help="path to configfile")
    args = parser.parse_args()

    logging.basicConfig()
    app = get_app(args.config_uri, args.app_name)
    # Loading app will have configured from config file. Reconfigure here:
    logging.getLogger('encoded').setLevel(logging.DEBUG)

    raised = False
    try:
        run(app)<commit_msg>Fix migrate_dataset_type<commit_after>"""\
Migrate dataset type

"""
import logging
import transaction
from pyramid.paster import get_app
from contentbase.interfaces import (
    STORAGE,
)

EPILOG = __doc__

logger = logging.getLogger(__name__)


TYPE_MAP = {
    'project': 'project',
    'composite': 'ucsc_browser_composite',
    'publication': 'publication_data',
    'reference': 'reference',
    'paired set': 'paired_set',
    'annotation': 'annotation',
}


def run(app):
    storage = app.registry[STORAGE].write

    for rid in storage.__iter__('dataset'):
        model = storage.get_by_uuid(str(rid))
        dataset_type = model.properties['dataset_type']
        new_type = TYPE_MAP[dataset_type]
        model.item_type = new_type
        logger.info('Updated %s, %r -> %s', model.rid, dataset_type, new_type)


def main():
    import argparse
    parser = argparse.ArgumentParser(
        description="Migrate dataset type", epilog=EPILOG,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )
    parser.add_argument('--app-name', help="Pyramid app name in configfile")
    parser.add_argument('--abort', action='store_true', help="Rollback transaction")
    parser.add_argument('config_uri', help="path to configfile")
    args = parser.parse_args()

    logging.basicConfig()
    app = get_app(args.config_uri, args.app_name)
    # Loading app will have configured from config file. Reconfigure here:
    logging.getLogger('encoded').setLevel(logging.DEBUG)

    raised = False
    try:
        run(app)
{'fraction_non_alphanumeric': 0.121232196091421, 'fraction_numerical': 0.0, 'mean_word_length': 3.83974358974359, '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': '3860778', 'n_tokens_mistral': 941, 'n_tokens_neox': 916, 'n_words': 204}