MCPcopy Create free account
hub / github.com/DeepL/deepl-python / action_document

Function action_document

deepl/__main__.py:54–76  ·  view source on GitHub ↗

Action function for the document command.

(
    deepl_client: deepl.DeepLClient,
    file: List[str],
    dest: str,
    output_format: Optional[str],
    **kwargs,
)

Source from the content-addressed store, hash-verified

52
53
54def 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
79def action_text(

Callers

nothing calls this directly

Tested by

no test coverage detected