(old_path, new_path)
Migrate one file from an old location to a new one

    avoids collisions if the new file exists
Migrate one file from an old location to a new one
Migrate one file from an old location to a new one
def migrate_file(old_path, new_path):
    """Migrate one file from an old location to a new one

    avoids collisions if the new file exists
    """
    if not os.path.exists(old_path):
        return
    if os.path.exists(new_path):
        # new config file already created! still move the config,
        # but avoid collision
        timestamp = date.today().isoformat()
        dest = dest_base = f"{new_path}.old.{timestamp}"
        i = 0
        while os.path.exists(dest):
            # avoid collisions
            dest = dest_base + f".{i}"
            i += 1
        logger.warning(f"Found file in both old ({old_path}) and new ({new_path}).")
        logger.warning(
            f"Moving {old_path} to {dest} to avoid clobbering.  Its contents will be ignored."
        )
    else:
        dest = new_path
    shutil.move(old_path, dest)
def migrate_file ( old_path , new_path ) : if not os . path . exists ( old_path ) : return if os . path . exists ( new_path ) : # new config file already created! still move the config, # but avoid collision timestamp = date . today ( ) . isoformat ( ) dest = dest_base = f"{new_path}.old.{timestamp}" i = 0 while os . path . exists ( dest ) : # avoid collisions dest = dest_base + f".{i}" i += 1 logger . warning ( f"Found file in both old ({old_path}) and new ({new_path})." ) logger . warning ( f"Moving {old_path} to {dest} to avoid clobbering.  Its contents will be ignored." ) else : dest = new_path shutil . move ( old_path , dest )