|
| 1 | +from ..utils import _write_response_content_to_file |
1 | 2 | from .utils import AnyLoc |
2 | 3 | from .dataset import DSSDataset |
3 | 4 | from .managedfolder import DSSManagedFolder |
|
8 | 9 | from .streaming_endpoint import DSSStreamingEndpoint |
9 | 10 | import logging, json |
10 | 11 |
|
| 12 | + |
11 | 13 | class DSSProjectFlow(object): |
12 | 14 | def __init__(self, client, project): |
13 | 15 | self.client = client |
@@ -111,6 +113,58 @@ def replace_input_computable(self, current_ref, new_ref, type="DATASET"): |
111 | 113 | dap.replace_input(current_ref, new_ref) |
112 | 114 | recipe_obj.set_definition_and_payload(dap) |
113 | 115 |
|
| 116 | + def generate_documentation(self, folder_id=None, path=None): |
| 117 | + """ |
| 118 | + Start the flow document generation from a template docx file in a managed folder, |
| 119 | + or from the default template if no folder id and path are specified. |
| 120 | +
|
| 121 | + :param folder_id: (optional) the id of the managed folder |
| 122 | + :param path: (optional) the path to the file from the root of the folder |
| 123 | + :return: A :class:`~dataikuapi.dss.future.DSSFuture` representing the flow document generation process |
| 124 | + """ |
| 125 | + if bool(folder_id) != bool(path): |
| 126 | + raise ValueError("Both folder id and path arguments are required to use a template from folder. " + |
| 127 | + "Use without argument to generate the flow documentation using the default template") |
| 128 | + |
| 129 | + template_mode_url = "" if folder_id is None and path is None else "-with-template-in-folder" |
| 130 | + |
| 131 | + f = self.client._perform_json("POST", "/projects/%s/flow/documentation/generate%s" % (self.project.project_key, template_mode_url), |
| 132 | + params={"folderId": folder_id, "path": path}) |
| 133 | + return DSSFuture(self.client, f["jobId"]) |
| 134 | + |
| 135 | + def generate_documentation_from_custom_template(self, fp): |
| 136 | + """ |
| 137 | + Start the flow document generation from a docx template (as a file object). |
| 138 | +
|
| 139 | + :param object fp: A file-like object pointing to a template docx file |
| 140 | + :return: A :class:`~dataikuapi.dss.future.DSSFuture` representing the flow document generation process |
| 141 | + """ |
| 142 | + files = {'file': fp} |
| 143 | + f = self.client._perform_json("POST", "/projects/%s/flow/documentation/generate-with-template" % self.project.project_key, files=files) |
| 144 | + return DSSFuture(self.client, f["jobId"]) |
| 145 | + |
| 146 | + def download_documentation_stream(self, export_id): |
| 147 | + """ |
| 148 | + Download a flow documentation, as a binary stream. |
| 149 | +
|
| 150 | + Warning: this stream will monopolize the DSSClient until closed. |
| 151 | +
|
| 152 | + :param export_id: the id of the generated flow documentation returned as the result of the future |
| 153 | + :return: A :class:`~dataikuapi.dss.future.DSSFuture` representing the flow document generation process |
| 154 | + """ |
| 155 | + return self.client._perform_raw("GET", "/projects/%s/flow/documentation/generated/%s" % (self.project.project_key, export_id)) |
| 156 | + |
| 157 | + def download_documentation_to_file(self, export_id, path): |
| 158 | + """ |
| 159 | + Download a flow documentation into the given output file. |
| 160 | +
|
| 161 | + :param export_id: the id of the generated flow documentation returned as the result of the future |
| 162 | + :param path: the path where to download the flow documentation |
| 163 | + :return: None |
| 164 | + """ |
| 165 | + stream = self.download_documentation_stream(export_id) |
| 166 | + _write_response_content_to_file(stream, path) |
| 167 | + |
114 | 168 | ######################################################## |
115 | 169 | # Flow tools |
116 | 170 | ######################################################## |
|
0 commit comments