|
18 | 18 | """ |
19 | 19 |
|
20 | 20 | import os |
21 | | -import sys |
22 | 21 | from ctypes import c_bool |
23 | 22 | from enum import Enum |
24 | 23 |
|
25 | 24 | try: |
26 | 25 | import ROOT # pylint: disable=import-error |
27 | 26 | from ROOT import o2 |
28 | 27 | except (ModuleNotFoundError, ImportError) as exc: |
29 | | - raise Exception("O2 environment is not loaded.") from exc |
| 28 | + raise OSError("O2 environment is not loaded.") from exc |
30 | 29 |
|
31 | 30 |
|
32 | 31 | # Enum of PDG_t particles |
@@ -200,13 +199,12 @@ def main(): |
200 | 199 | mass_root_head = "/// \\brief Declarations of masses for particles in ROOT PDG_t" |
201 | 200 |
|
202 | 201 | # Get header content before and after the generated block. |
203 | | - print(f"File {path_header} will be updated.") |
| 202 | + print(f'File "{path_header}" will be updated.') |
204 | 203 | try: |
205 | 204 | with open(path_header, encoding="utf-8") as file: |
206 | 205 | content_old = file.readlines() |
207 | | - except OSError: |
208 | | - print(f'Failed to open file "{path_header}".') |
209 | | - sys.exit(1) |
| 206 | + except OSError as exc: |
| 207 | + raise OSError(f'Failed to open file "{path_header}".') from exc |
210 | 208 | lines_header_before: list[str] = [] |
211 | 209 | lines_header_after: list[str] = [] |
212 | 210 | got_block_begin = False |
@@ -264,10 +262,9 @@ def main(): |
264 | 262 | try: |
265 | 263 | with open(path_header, "w", encoding="utf-8") as file: |
266 | 264 | file.write(content_new) |
267 | | - print(f"File {path_header} has been overwritten.") |
268 | | - except OSError: |
269 | | - print(f'Failed to write to file "{path_header}".') |
270 | | - sys.exit(1) |
| 265 | + print(f'File "{path_header}" has been overwritten.') |
| 266 | + except OSError as exc: |
| 267 | + raise OSError(f'Failed to write to file "{path_header}".') from exc |
271 | 268 |
|
272 | 269 |
|
273 | 270 | if __name__ == "__main__": |
|
0 commit comments