@@ -0,0 +1,1393 @@
+import logging%0Aimport sys%0A%0Afrom modularodm import Q%0A%0Afrom framework.auth.core import User%0Afrom framework.transactions.context import TokuTransaction%0Afrom scripts import utils as script_utils%0Afrom website.app import init_app%0A%0Alogger = logging.getLogger(__name__)%0A%0Adef get_possible_spam_users():%0A    users = User.find(%0A        Q('system_tags', 'nin', %5B'confirmed_spam', 'confirmed_ham', 'spam_threshold'%5D) &%0A        Q('date_disabled', 'ne', None) &%0A        Q('is_registered', 'eq', False)%0A    )%0A    logger.info('Found %7B%7D possible spam users'.format(users.count()))%0A    return users%0A%0Adef migrate():%0A    spam_count = 0%0A    spammy = get_possible_spam_users()%0A    for user in spammy:%0A        if any((n.is_spam for n in user.contributor_to)):%0A            logger.info('Confirmed user %7B%7D as SPAM'.format(user._id))%0A            user.system_tags.append('confirmed_spam')%0A            user.save()%0A            spam_count += 1%0A        else:%0A            logger.info('User %7B%7D smells like HAM'.format(user._id))%0A    logger.info('Flagged %7B%7D users as SPAM'.format(spam_count))%0A%0Adef main():%0A    dry_run = '--dry' in sys.argv%0A    if not dry_run:%0A        script_utils.add_file_logger(logger, __file__)%0A    init_app(set_backends=True, routes=False)%0A    with TokuTransaction():%0A        migrate()%0A        if dry_run:%0A            raise Exception('Dry Run -- Aborting Transaction')%0A%0Aif __name__ == '__main__':%0A    main()%0A

Add migration script