#NEWLINE# def atomicish_move( source , destination , tmp_suffix = '_TMP' ) : #NEWLINE# #INDENT# '\n    Move source to destination without copying to directly to destination\n    there is never a partial file.\n\n    > from tempfile import mkdtemp\n    > from os.path import join, exists\n    > temp_dir = mkdtemp()\n    > source = join(temp_dir, "the_source")\n    > destination = join(temp_dir, "the_dest")\n    > open(source, "wb").write(b"Hello World!")\n    > assert exists(source)\n    > assert not exists(destination)\n    > atomicish_move(source, destination)\n    > assert not exists(source)\n    > assert exists(destination)\n    ' #NEWLINE# destination_dir = os . path . dirname ( destination ) #NEWLINE# destination_name = os . path . basename ( destination ) #NEWLINE# temp_destination = os . path . join ( destination_dir , ( '%s%s' % ( destination , tmp_suffix ) ) ) #NEWLINE# shutil . move ( source , temp_destination ) #NEWLINE# os . rename ( temp_destination , destination )