Action function for the document command.
(
deepl_client: deepl.DeepLClient,
file: List[str],
dest: str,
output_format: Optional[str],
**kwargs,
)
| 52 | |
| 53 | |
| 54 | def action_document( |
| 55 | deepl_client: deepl.DeepLClient, |
| 56 | file: List[str], |
| 57 | dest: str, |
| 58 | output_format: Optional[str], |
| 59 | **kwargs, |
| 60 | ): |
| 61 | """Action function for the document command.""" |
| 62 | if not os.path.exists(dest): |
| 63 | os.makedirs(dest, exist_ok=True) |
| 64 | elif not os.path.isdir(dest): |
| 65 | raise Exception("Destination already exists, and is not a directory") |
| 66 | |
| 67 | for this_file in file: |
| 68 | outfile_name = ( |
| 69 | this_file |
| 70 | if not output_format |
| 71 | else (os.path.splitext(this_file)[0] + "." + output_format) |
| 72 | ) |
| 73 | output_path = os.path.join(dest, os.path.basename(outfile_name)) |
| 74 | deepl_client.translate_document_from_filepath( |
| 75 | this_file, output_path, **kwargs |
| 76 | ) |
| 77 | |
| 78 | |
| 79 | def action_text( |
nothing calls this directly
no test coverage detected