#NEWLINE# def write_file_and_backup( path , contents , bk_ext = 'org' ) : #NEWLINE# #INDENT# perms = None #NEWLINE# backup_path = None #NEWLINE# if isfile ( path ) : #NEWLINE# #INDENT# perms = fileperms ( path ) #NEWLINE# backup_path = ( '%s.%s' % ( path , bk_ext ) ) #NEWLINE# if ( not isfile ( backup_path ) ) : #NEWLINE# #INDENT# LOG . debug ( 'Backing up %s => %s' , path , backup_path ) #NEWLINE# move ( path , backup_path ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# LOG . debug ( 'Leaving original backup of %s at %s' , path , backup_path ) #NEWLINE# #UNINDENT# #UNINDENT# write_file ( path , contents ) #NEWLINE# if ( perms is not None ) : #NEWLINE# #INDENT# chmod ( path , perms ) #NEWLINE# #UNINDENT# return backup_path