pub fn rename_package_files(top_path: &Path, old: &str, new: &str) {
    for entry in fs::read_dir(top_path).expect("Problem reading renamed package path") {
        let entry = entry.expect("Problem reading file while renaming");
        let path = entry.path();

        if path.is_dir() {
            rename_package_files(&path, old, new);
            continue;
        }

        if !path.is_file() {
            continue;
        }
        if path.extension().is_none() || path.extension().unwrap() != "py" {
            continue;
        }

        let mut data = fs::read_to_string(&path).expect("Problem reading file while renaming");

        // todo: More flexible with regex?
        data = data.replace(
            &format!("from {} import", old),
            &format!("from {} import", new),
        );
        data = data.replace(&format!("from {}.", old), &format!("from {}.", new));
        data = data.replace(&format!("import {}", old), &format!("import {}", new));
        // Todo: Is this one too general? Supersedes the first. Needed for things like `add_newdoc('numpy.core.multiarray...`
        data = data.replace(&format!("{}.", old), &format!("{}.", new));

        fs::write(path, data).expect("Problem writing file while renaming");
    }
}
/// Rename files in a package. Assume we already renamed the folder, ie during installation.
Rename files in a package. Assume we already renamed the folder, ie during installation.
Rename files in a package . Assume we already renamed the folder ie during installation .
pub fn rename_package_files(top_path: &Path, old: &str, new: &str) {
    for entry in fs::read_dir(top_path).expect("Problem reading renamed package path") {
        let entry = entry.expect("Problem reading file while renaming");
        let path = entry.path();
        if path.is_dir() {
            rename_package_files(&path, old, new);
            continue;
        }
        if !path.is_file() {
            continue;
        }
        if path.extension().is_none() || path.extension().unwrap() != "py" {
            continue;
        }
        let mut data = fs::read_to_string(&path).expect("Problem reading file while renaming");
        // todo: More flexible with regex?
        data = data.replace(
            &format!("from {} import", old),
            &format!("from {} import", new),
        );
        data = data.replace(&format!("from {}.", old), &format!("from {}.", new));
        data = data.replace(&format!("import {}", old), &format!("import {}", new));
        // Todo: Is this one too general? Supersedes the first. Needed for things like `add_newdoc('numpy.core.multiarray...`
        data = data.replace(&format!("{}.", old), &format!("{}.", new));
        fs::write(path, data).expect("Problem writing file while renaming");
    }
}
pub fn rename_package_files ( top_path : & Path , old : & str , new : & str ) { for entry in fs :: read_dir ( top_path ) . expect ( " " ) { let entry = entry . expect ( " " ) ; let path = entry . path ( ) ; if path . is_dir ( ) { rename_package_files ( & path , old , new ) ; continue ; } if ! path . is_file ( ) { continue ; } if path . extension ( ) . is_none ( ) || path . extension ( ) . unwrap ( ) != " " { continue ; } let mut data = fs :: read_to_string ( & path ) . expect ( " " ) ; // todo: More flexible with regex? data = data . replace ( & format ! ( " " old ) , & format ! ( " " new ) , ) ; data = data . replace ( & format ! ( " " old ) , & format ! ( " " new ) ) ; data = data . replace ( & format ! ( " " old ) , & format ! ( " " new ) ) ; // Todo: Is this one too general? Supersedes the first. Needed for things like `add_newdoc('numpy.core.multiarray...` data = data . replace ( & format ! ( " " old ) , & format ! ( " " new ) ) ; fs :: write ( path , data ) . expect ( " " ) ; } }
Rename files in a package.
Rename files in a package .
top_path
&Path
old
&str
new
&str
top_path
&Path
old
&str
new
&str