<s> import sys <EOL> import logging <EOL> from modularodm import Q <EOL> from website . app import init_app <EOL> from scripts import utils as script_utils <EOL> from framework . transactions . context import TokuTransaction <EOL> from website . addons . dataverse . model import AddonDataverseNodeSettings <EOL> logger = logging . getLogger ( __name__ ) <EOL> def do_migration ( ) : <EOL> for node_addon in AddonDataverseNodeSettings . find ( Q ( '<STR_LIT>' , '<STR_LIT>' , None ) ) : <EOL> user_addon = node_addon . foreign_user_settings <EOL> if not user_addon . external_accounts : <EOL> logger . warning ( '<STR_LIT>' . format ( user_addon . owner . _id ) ) <EOL> continue <EOL> account = user_addon . external_accounts [ <NUM_LIT:0> ] <EOL> node_addon . set_auth ( account , user_addon . owner ) <EOL> logger . info ( '<STR_LIT>' . format ( <EOL> account . _id , node_addon . owner . _id , <EOL> ) ) <EOL> def main ( dry = True ) : <EOL> init_app ( set_backends = True , routes = False ) <EOL> with TokuTransaction ( ) : <EOL> do_migration ( ) <EOL> if dry : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> dry = '<STR_LIT>' in sys . argv <EOL> if not dry : <EOL> script_utils . add_file_logger ( logger , __file__ ) <EOL> main ( dry = dry ) </s>
