utils.util
Utility functions that can be used in various parts of the code.
path_validation(file_path, check_for_file=False, check_for_file_type=None)
Utility function for validating the path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
Path to be validated |
required |
check_for_file |
bool
|
Checks for existence of file |
False
|
check_for_file_type |
Union[str, None]
|
Check if file is of this type |
None
|
Raises:
Type | Description |
---|---|
PathDoesNotExist
|
Raises if path does not exist |
NotAFileError
|
Raises if file is not present |
InvalidFileTypePassed
|
Raises if invalid file type is passed |
Source code in erad\utils\util.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
read_file(file_path)
Utility function to read file into a python dict.
Supports json, yaml and geojson.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
Path to a file to be read. |
required |
Raises:
Type | Description |
---|---|
FeatureNotImplementedError
|
Raises if invalid file is passed. |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Python dict containing content of file. |
Source code in erad\utils\util.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
setup_logging(filename=None)
Creates log directory and sets up logging via logging.yaml.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Path to logging.yaml file |
None
|
If not providex expects log file in the root of repo.
Source code in erad\utils\util.py
44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
timeit(func)
Decorator for timing execution of a function.
Source code in erad\utils\util.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
write_file(content, file_path, **kwargs)
Utility function to write to a file..
Supports json, yaml and geojson.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content |
dict
|
Python dict content |
required |
file_path |
str
|
Path to a file to be read |
required |
kwargs |
dict
|
Keyword arguments passed to relevant writer. |
{}
|
Raises:
Type | Description |
---|---|
FeatureNotImplementedError
|
Raises if invalid file type is passed. |
Source code in erad\utils\util.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|