Skip to content

normalise_filenames

Normalise the files in the given directory.

main()

Normalise filenames.

Source code in /home/anders/projects/CorpusTools/corpustools/normalise_filenames.py
75
76
77
78
def main():
    """Normalise filenames."""
    for target_dir in normalise_parse_args().target_dirs:
        normalise(target_dir)

normalise(target_dir)

Normalise the filenames in the corpuses.

Parameters:

Name Type Description Default
target_dir str

directory where filenames should be normalised

required
Source code in /home/anders/projects/CorpusTools/corpustools/normalise_filenames.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def normalise(target_dir):
    """Normalise the filenames in the corpuses.

    Args:
        target_dir (str): directory where filenames should be normalised
    """
    print(f"Normalising names in {target_dir}")
    for root, dirs, files in os.walk(os.path.join(target_dir)):
        for f in files:
            if not f.endswith(".xsl"):
                try:
                    orig_path = os.path.join(root, f)

                    cfmu = namechanger.CorpusFilesetMoverAndUpdater(
                        orig_path, orig_path
                    )
                    filepair = cfmu.move_computer.filepairs[0]
                    print(f"\t\tmove {filepair.oldpath} -> {filepair.newpath}")
                    cfmu.move_files()
                    cfmu.update_own_metadata()
                    cfmu.update_parallel_files_metadata()
                except UserWarning:
                    pass

normalise_parse_args()

Parse the commandline options.

Returns:

Type Description
argparse.Namespace

the parsed commandline arguments

Source code in /home/anders/projects/CorpusTools/corpustools/normalise_filenames.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def normalise_parse_args():
    """Parse the commandline options.

    Returns:
        (argparse.Namespace): the parsed commandline arguments
    """
    parser = argparse.ArgumentParser(
        parents=[argparse_version.parser],
        description="Program to normalise names in given directories. "
        "The filenames are downcased, non ascii characters are replaced "
        "by ascii ones and some unwanted characters are removed.",
    )
    parser.add_argument(
        "target_dirs",
        nargs="+",
        help="The directory/ies where filenames should be normalised.",
    )

    args = parser.parse_args()

    return args