namechanger
Classes and functions change names of corpus files.
CorpusFileRemover
Remove an original file and all its derived files.
Source code in /home/anders/projects/CorpusTools/corpustools/namechanger.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
__init__(oldpath)
Class to remove corpus files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
oldpath |
unicode
|
the old path |
required |
Source code in /home/anders/projects/CorpusTools/corpustools/namechanger.py
44 45 46 47 48 49 50 51 52 53 54 55 |
|
remove_files()
Remove all the files that are under version control.
Source code in /home/anders/projects/CorpusTools/corpustools/namechanger.py
57 58 59 60 61 62 63 64 |
|
NamechangerError
Bases: Exception
This exception is raised when errors occurs in this module.
Source code in /home/anders/projects/CorpusTools/corpustools/namechanger.py
34 35 |
|
are_duplicates(oldpath, newpath)
Check if oldpath and newpath are duplicates of each other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
oldpath |
unicode
|
old path of the file |
required |
newpath |
unicode
|
the wanted, new path of the file |
required |
Returns:
Type | Description |
---|---|
bool
|
a boolean indicating if the two files are duplicates |
Source code in /home/anders/projects/CorpusTools/corpustools/namechanger.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
compute_hexdigest(afile, blocksize=65536)
Compute the hexdigest of the file in path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
afile |
file
|
a file like object |
required |
Returns:
Type | Description |
---|---|
str
|
a hexdigest of the file |
Source code in /home/anders/projects/CorpusTools/corpustools/namechanger.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
compute_new_basename(orig_path)
Compute the new path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
orig_path |
Path
|
path to file, basename should possibly be normalised |
required |
Returns:
Type | Description |
---|---|
pathlib.Path
|
lower cased, ascii path |
Source code in /home/anders/projects/CorpusTools/corpustools/namechanger.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
normalise_filename(filename)
Normalise filename to ascii only.
Downcase filename, replace non-ascii characters with ascii ones and remove or replace unwanted characters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
name of the file |
required |
Returns:
Type | Description |
---|---|
str
|
a downcased string containing only ascii chars |
Source code in /home/anders/projects/CorpusTools/corpustools/namechanger.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|