<s> import sys <EOL> import logging <EOL> from framework . auth . core import get_user <EOL> from framework . transactions . context import TokuTransaction <EOL> from website . project . model import Node <EOL> from website . app import init_app <EOL> from scripts import utils as script_utils <EOL> logger = logging . getLogger ( __name__ ) <EOL> def do_migration ( records , dry = False ) : <EOL> for user in records : <EOL> logger . info ( '<STR_LIT>' . format ( user . _id ) ) <EOL> if not dry : <EOL> with TokuTransaction ( ) : <EOL> migrate_project_contributed ( user ) <EOL> user . is_disabled = True <EOL> user . save ( ) <EOL> logger . info ( '<STR_LIT>' . format ( '<STR_LIT>' if dry else '<STR_LIT>' , len ( records ) ) ) <EOL> def migrate_project_contributed ( user ) : <EOL> count = <NUM_LIT:0> <EOL> for node_id in user . contributed : <EOL> node = Node . load ( node_id ) <EOL> if node . _primary_key in user . unclaimed_records : <EOL> del user . unclaimed_records [ node . _primary_key ] <EOL> node . contributors . remove ( user . _id ) <EOL> node . clear_permission ( user ) <EOL> if user . _id in node . visible_contributor_ids : <EOL> node . visible_contributor_ids . remove ( user . _id ) <EOL> node . save ( ) <EOL> count += <NUM_LIT:1> <EOL> logger . info ( '<STR_LIT>' . format ( user . _id , node . _id ) ) <EOL> logger . info ( '<STR_LIT>' . format ( user . _id , count ) ) <EOL> def get_targets ( ) : <EOL> users = [ ] <EOL> user1 = get_user ( email = '<STR_LIT>' ) <EOL> if user1 : <EOL> users . append ( user1 ) <EOL> user2 = get_user ( email = '<STR_LIT>' ) <EOL> if user2 : <EOL> users . append ( user2 ) <EOL> return users <EOL> def main ( ) : <EOL> init_app ( routes = False ) <EOL> dry = '<STR_LIT>' in sys . argv <EOL> if not dry : <EOL> script_utils . add_file_logger ( logger , __file__ ) <EOL> do_migration ( get_targets ( ) , dry ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
