#NEWLINE# def commit( self , previews ) : #NEWLINE# #INDENT# actions = sorted ( ( ( '' . join ( i [ 0 ] ) , ( i [ 0 ] [ 0 ] + i [ 1 ] ) ) for i in previews ) , key = ( lambda i : i [ 0 ] . count ( '/' ) ) , reverse = True ) #NEWLINE# for i in actions : #NEWLINE# #INDENT# log . debug ( '{} -> {}.' . format ( i [ 0 ] , i [ 1 ] ) ) #NEWLINE# if ( i [ 0 ] == i [ 1 ] ) : #NEWLINE# #INDENT# log . warn ( 'File already exists. Skipping.' ) #NEWLINE# continue #NEWLINE# #UNINDENT# if self . simulate : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if self . stopcommit : #NEWLINE# #INDENT# idx = actions . index ( i ) #NEWLINE# log . warn ( 'Stopping commit after {} renames.' . format ( ( idx + 1 ) ) ) #NEWLINE# if idx : #NEWLINE# #INDENT# log . warn ( 'Use undo to revert the rename actions.' ) #NEWLINE# #UNINDENT# self . history . append ( actions [ : ( idx + 1 ) ] ) #NEWLINE# return #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# os . rename ( i [ 0 ] , i [ 1 ] ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# log . debug ( 'Rename Error: {} -> {} ({}).' . format ( i [ 0 ] , i [ 1 ] , e ) ) #NEWLINE# if self . autostop : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . history . append ( actions ) #NEWLINE# log . info ( 'Renaming complete.' )