|
16 | 16 | from docopt import docopt |
17 | 17 |
|
18 | 18 | from . import _io |
| 19 | +from . import hooks |
19 | 20 | from . import _errors |
20 | 21 | from .. import files |
21 | | -from .hooks import default |
22 | 22 |
|
23 | 23 |
|
24 | 24 | EXECUTABLE = """ |
@@ -57,15 +57,17 @@ class Run: |
57 | 57 | path_subdirectories: List of paths to run directories. |
58 | 58 | """ |
59 | 59 |
|
60 | | - PREHOOK_PASS = default |
61 | | - POSTHOOK_PASS = default |
| 60 | + PREHOOK_EMPTY = hooks.empty |
| 61 | + POSTHOOK_EMPTY = hooks.empty |
| 62 | + PREHOOK_NPS = hooks.nps |
| 63 | + POSTHOOK_CLEAN = hooks.clean |
62 | 64 |
|
63 | 65 | def __init__( |
64 | 66 | self, |
65 | 67 | inps: list[files.inp.Inp], |
66 | 68 | path: pathlib.Path, |
67 | | - prehook: ModuleType = PREHOOK_PASS, |
68 | | - posthook: ModuleType = POSTHOOK_PASS, |
| 69 | + prehook: ModuleType = PREHOOK_EMPTY, |
| 70 | + posthook: ModuleType = POSTHOOK_EMPTY, |
69 | 71 | command: str = 'mcnp6', |
70 | 72 | ): |
71 | 73 | """ |
@@ -127,7 +129,7 @@ def __init__( |
127 | 129 |
|
128 | 130 | def run(self, hosts: list[str] = []): |
129 | 131 | """ |
130 | | - Runs MCNP INP files. |
| 132 | + Runs MCNP INP pymcnp. |
131 | 133 |
|
132 | 134 | Parameters: |
133 | 135 | hosts: List of hostnames on which to execute. |
@@ -168,25 +170,35 @@ def main() -> None: |
168 | 170 | """ |
169 | 171 | Executes the ``pymcnp run`` command. |
170 | 172 |
|
171 | | - ``pymcnp run`` runs INP files. |
| 173 | + ``pymcnp run`` runs INP pymcnp. |
172 | 174 | """ |
173 | 175 |
|
174 | | - args = docopt(__doc__) |
| 176 | + _io.warning() |
175 | 177 |
|
| 178 | + # Processing CLI arguments. |
| 179 | + args = docopt(__doc__) |
176 | 180 | inps = args['<file>'] |
177 | 181 | hosts = args['--hosts'] if args['--hosts'] else [] |
178 | 182 | command = args['--command'] if args['--command'] else 'mcnp6' |
179 | 183 |
|
| 184 | + # Reading INP files. |
180 | 185 | try: |
181 | 186 | inps = [files.inp.Inp.from_mcnp_file(inp) for inp in inps] |
182 | 187 | except files.utils.errors.McnpError as err: |
183 | 188 | _io.error(err.__str__()) |
| 189 | + except FileNotFoundError: |
| 190 | + _io.error(f'[red][bold]IoError:[/][/] {inps} File not found.') |
184 | 191 |
|
185 | | - path = pathlib.Path(os.getcwd()) |
186 | | - |
| 192 | + # Running! |
187 | 193 | try: |
188 | | - run = Run(inps, path, command=command) |
| 194 | + Run( |
| 195 | + inps, |
| 196 | + pathlib.Path(os.getcwd()), |
| 197 | + prehook=Run.PREHOOK_EMPTY, |
| 198 | + posthook=Run.POSTHOOK_CLEAN, |
| 199 | + command=command, |
| 200 | + ).run(hosts) |
189 | 201 | except _errors.CliError as err: |
190 | 202 | _io.error(err.__str__()) |
191 | 203 |
|
192 | | - run.run(hosts) |
| 204 | + _io.done() |
0 commit comments