#NEWLINE# def migrate( dry_run = True ) : #NEWLINE# #INDENT# migrated_accounts = [ ] #NEWLINE# migrations_failed = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for account in get_targets ( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# account . display_name = NEW_HOST #NEWLINE# account . oauth_key = NEW_HOST #NEWLINE# account . save ( ) #NEWLINE# migrated_accounts . append ( account . _id ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# migrations_failed [ account . _id ] = e #NEWLINE# #UNINDENT# #UNINDENT# if migrated_accounts : #NEWLINE# #INDENT# logging . info ( 'Successfully migrated {0} ExcternalAccounts:\n{1}' . format ( len ( migrated_accounts ) , [ e for e in migrated_accounts ] ) ) #NEWLINE# #UNINDENT# if migrations_failed : #NEWLINE# #INDENT# logging . error ( 'Failed to migrate {0} ExternalAccounts:\n{1}' . format ( len ( migrations_failed ) , [ '{}: {}\n' . format ( i , migrations_failed [ i ] ) for i in migrations_failed . keys ( ) ] ) ) #NEWLINE# #UNINDENT# if i : #NEWLINE# #INDENT# raise RuntimeError ( 'Dry run, transaction rolled back.' )