<s> """<STR_LIT>""" <EOL> import sys <EOL> import logging <EOL> from scripts import utils as scripts_utils <EOL> from modularodm import Q <EOL> from website . app import init_app <EOL> from website . models import ExternalAccount <EOL> logger = logging . getLogger ( __name__ ) <EOL> def get_targets ( ) : <EOL> return ExternalAccount . find ( Q ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) | Q ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> name_map = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def migrate_extaccount ( acct , dry = True ) : <EOL> if not acct . provider_name : <EOL> logger . info ( '<STR_LIT>' . format ( acct . _id ) ) <EOL> provider_name = name_map [ acct . provider ] <EOL> logger . info ( '<STR_LIT>' . format ( acct . _id ) ) <EOL> if not dry : <EOL> acct . provider_name = provider_name <EOL> acct . save ( ) <EOL> return True <EOL> return False <EOL> def main ( dry = True ) : <EOL> count = <NUM_LIT:0> <EOL> for each in get_targets ( ) : <EOL> migrated = migrate_extaccount ( each , dry = dry ) <EOL> if migrated : <EOL> count += <NUM_LIT:1> <EOL> logger . info ( '<STR_LIT>' . format ( count ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> dry = '<STR_LIT>' in sys . argv <EOL> if not dry : <EOL> scripts_utils . add_file_logger ( logger , __file__ ) <EOL> init_app ( routes = False , set_backends = True ) <EOL> main ( dry = dry ) </s>
