From e67cecfe16a89e623fb9ecd63417c136d13fef67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lian=20Haydont?= Date: Tue, 6 Oct 2020 15:42:58 +0200 Subject: [PATCH 1/6] Add functions to export a wiki article as a PDF --- dataikuapi/dss/wiki.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/dataikuapi/dss/wiki.py b/dataikuapi/dss/wiki.py index 4d7423ca..66777168 100644 --- a/dataikuapi/dss/wiki.py +++ b/dataikuapi/dss/wiki.py @@ -247,6 +247,31 @@ def get_uploaded_file(self, upload_id): """ return self.client._perform_raw("GET", "/projects/%s/wiki/%s/uploads/%s" % (self.project_key, self.article_id, upload_id)) + def get_export_stream(self, paperSize="A4", exportChildren=False): + """ + Download an article in PDF format as a binary stream. + Warning: this stream will monopolize the DSSClient until closed. + """ + body = { + "paperSize": paperSize, + "exportChildren": exportChildren + } + return self.client._perform_raw("POST", "/projects/%s/wiki/%s/actions/export" % (self.project_key, self.article_id), body=body) + + def export_to_file(self, path, paperSize="A4", exportChildren=False): + """ + Download an article in PDF format into the given output file. + """ + stream = self.export(paperSize=paperSize, exportChildren=exportChildren) + + with open(path, 'wb') as f: + for chunk in stream.iter_content(chunk_size=10000): + if chunk: + f.write(chunk) + f.flush() + stream.close() + + def delete(self): """ Delete the article From 878a6943cea43ec1e143562f87654bb664ca3b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lian=20Haydont?= Date: Fri, 9 Oct 2020 14:43:20 +0200 Subject: [PATCH 2/6] fix function name --- dataikuapi/dss/wiki.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataikuapi/dss/wiki.py b/dataikuapi/dss/wiki.py index 66777168..100bc6f7 100644 --- a/dataikuapi/dss/wiki.py +++ b/dataikuapi/dss/wiki.py @@ -262,7 +262,7 @@ def export_to_file(self, path, paperSize="A4", exportChildren=False): """ Download an article in PDF format into the given output file. """ - stream = self.export(paperSize=paperSize, exportChildren=exportChildren) + stream = self.get_export_stream(paperSize=paperSize, exportChildren=exportChildren) with open(path, 'wb') as f: for chunk in stream.iter_content(chunk_size=10000): From ae71a0c043f58e5278bdcdc941e29e76d0e5c8e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lian=20Haydont?= Date: Wed, 18 Nov 2020 17:05:24 +0100 Subject: [PATCH 3/6] Adding function to export the full wiki and option to export attachments --- dataikuapi/dss/wiki.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/dataikuapi/dss/wiki.py b/dataikuapi/dss/wiki.py index 100bc6f7..1d2a8f50 100644 --- a/dataikuapi/dss/wiki.py +++ b/dataikuapi/dss/wiki.py @@ -89,6 +89,30 @@ def create_article(self, article_name, parent_id=None, content=None): return article + def get_export_stream(self, paperSize="A4", exportAttachment=False): + """ + Download the whole wiki of the project in PDF format as a binary stream. + Warning: this stream will monopolize the DSSClient until closed. + """ + body = { + "paperSize": paperSize, + "exportAttachment": exportAttachment + } + return self.client._perform_raw("POST", "/projects/%s/wiki/actions/export" % (self.project_key, self.article_id), body=body) + + def export_to_file(self, path, paperSize="A4", exportAttachment=False): + """ + Download the whole wiki of the project in PDF format into the given output file. + """ + stream = self.get_export_stream(paperSize=paperSize, exportAttachment=exportAttachment) + + with open(path, 'wb') as f: + for chunk in stream.iter_content(chunk_size=10000): + if chunk: + f.write(chunk) + f.flush() + stream.close() + class DSSWikiSettings(object): """ Global settings for the wiki, including taxonomy. Call save() to save @@ -247,22 +271,23 @@ def get_uploaded_file(self, upload_id): """ return self.client._perform_raw("GET", "/projects/%s/wiki/%s/uploads/%s" % (self.project_key, self.article_id, upload_id)) - def get_export_stream(self, paperSize="A4", exportChildren=False): + def get_export_stream(self, paperSize="A4", exportChildren=False, exportAttachment=False): """ Download an article in PDF format as a binary stream. Warning: this stream will monopolize the DSSClient until closed. """ body = { "paperSize": paperSize, - "exportChildren": exportChildren + "exportChildren": exportChildren, + "exportAttachment": exportAttachment } return self.client._perform_raw("POST", "/projects/%s/wiki/%s/actions/export" % (self.project_key, self.article_id), body=body) - def export_to_file(self, path, paperSize="A4", exportChildren=False): + def export_to_file(self, path, paperSize="A4", exportChildren=False, exportAttachment=False): """ Download an article in PDF format into the given output file. """ - stream = self.get_export_stream(paperSize=paperSize, exportChildren=exportChildren) + stream = self.get_export_stream(paperSize=paperSize, exportChildren=exportChildren, exportAttachment=exportAttachment) with open(path, 'wb') as f: for chunk in stream.iter_content(chunk_size=10000): From 3294c0b10c220e47332880c51e22eafb8d54559d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lian=20Haydont?= Date: Thu, 19 Nov 2020 11:37:06 +0100 Subject: [PATCH 4/6] remove unused articleId from the full wiki export --- dataikuapi/dss/wiki.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataikuapi/dss/wiki.py b/dataikuapi/dss/wiki.py index 1d2a8f50..b4cefb4a 100644 --- a/dataikuapi/dss/wiki.py +++ b/dataikuapi/dss/wiki.py @@ -98,7 +98,7 @@ def get_export_stream(self, paperSize="A4", exportAttachment=False): "paperSize": paperSize, "exportAttachment": exportAttachment } - return self.client._perform_raw("POST", "/projects/%s/wiki/actions/export" % (self.project_key, self.article_id), body=body) + return self.client._perform_raw("POST", "/projects/%s/wiki/actions/export" % (self.project_key), body=body) def export_to_file(self, path, paperSize="A4", exportAttachment=False): """ From 38d70a22676fb6d396d1b6e0b54a9524754f8087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lian=20Haydont?= Date: Thu, 26 Nov 2020 14:57:46 +0100 Subject: [PATCH 5/6] [PR review] use "with/as" syntax --- dataikuapi/dss/wiki.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/dataikuapi/dss/wiki.py b/dataikuapi/dss/wiki.py index b4cefb4a..aad51105 100644 --- a/dataikuapi/dss/wiki.py +++ b/dataikuapi/dss/wiki.py @@ -104,14 +104,12 @@ def export_to_file(self, path, paperSize="A4", exportAttachment=False): """ Download the whole wiki of the project in PDF format into the given output file. """ - stream = self.get_export_stream(paperSize=paperSize, exportAttachment=exportAttachment) - - with open(path, 'wb') as f: - for chunk in stream.iter_content(chunk_size=10000): - if chunk: - f.write(chunk) - f.flush() - stream.close() + with self.get_export_stream(paperSize=paperSize, exportAttachment=exportAttachment) as stream: + with open(path, 'wb') as f: + for chunk in stream.iter_content(chunk_size=10000): + if chunk: + f.write(chunk) + f.flush() class DSSWikiSettings(object): """ @@ -287,14 +285,12 @@ def export_to_file(self, path, paperSize="A4", exportChildren=False, exportAttac """ Download an article in PDF format into the given output file. """ - stream = self.get_export_stream(paperSize=paperSize, exportChildren=exportChildren, exportAttachment=exportAttachment) - - with open(path, 'wb') as f: - for chunk in stream.iter_content(chunk_size=10000): - if chunk: - f.write(chunk) - f.flush() - stream.close() + with self.get_export_stream(paperSize=paperSize, exportChildren=exportChildren, exportAttachment=exportAttachment) as stream: + with open(path, 'wb') as f: + for chunk in stream.iter_content(chunk_size=10000): + if chunk: + f.write(chunk) + f.flush() def delete(self): From 7f2c3e70e04acaa58146402b657c23d83186a4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lian=20Haydont?= Date: Thu, 26 Nov 2020 15:00:58 +0100 Subject: [PATCH 6/6] not use camelCase for named param --- dataikuapi/dss/wiki.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dataikuapi/dss/wiki.py b/dataikuapi/dss/wiki.py index aad51105..335d1a3b 100644 --- a/dataikuapi/dss/wiki.py +++ b/dataikuapi/dss/wiki.py @@ -89,22 +89,22 @@ def create_article(self, article_name, parent_id=None, content=None): return article - def get_export_stream(self, paperSize="A4", exportAttachment=False): + def get_export_stream(self, paper_size="A4", export_attachment=False): """ Download the whole wiki of the project in PDF format as a binary stream. Warning: this stream will monopolize the DSSClient until closed. """ body = { - "paperSize": paperSize, - "exportAttachment": exportAttachment + "paperSize": paper_size, + "exportAttachment": export_attachment } return self.client._perform_raw("POST", "/projects/%s/wiki/actions/export" % (self.project_key), body=body) - def export_to_file(self, path, paperSize="A4", exportAttachment=False): + def export_to_file(self, path, paper_size="A4", export_attachment=False): """ Download the whole wiki of the project in PDF format into the given output file. """ - with self.get_export_stream(paperSize=paperSize, exportAttachment=exportAttachment) as stream: + with self.get_export_stream(paper_size=paper_size, export_attachment=export_attachment) as stream: with open(path, 'wb') as f: for chunk in stream.iter_content(chunk_size=10000): if chunk: @@ -269,23 +269,23 @@ def get_uploaded_file(self, upload_id): """ return self.client._perform_raw("GET", "/projects/%s/wiki/%s/uploads/%s" % (self.project_key, self.article_id, upload_id)) - def get_export_stream(self, paperSize="A4", exportChildren=False, exportAttachment=False): + def get_export_stream(self, paper_size="A4", export_children=False, export_attachment=False): """ Download an article in PDF format as a binary stream. Warning: this stream will monopolize the DSSClient until closed. """ body = { - "paperSize": paperSize, - "exportChildren": exportChildren, - "exportAttachment": exportAttachment + "paperSize": paper_size, + "exportChildren": export_children, + "exportAttachment": export_attachment } return self.client._perform_raw("POST", "/projects/%s/wiki/%s/actions/export" % (self.project_key, self.article_id), body=body) - def export_to_file(self, path, paperSize="A4", exportChildren=False, exportAttachment=False): + def export_to_file(self, path, paper_size="A4", export_children=False, export_attachment=False): """ Download an article in PDF format into the given output file. """ - with self.get_export_stream(paperSize=paperSize, exportChildren=exportChildren, exportAttachment=exportAttachment) as stream: + with self.get_export_stream(paper_size=paper_size, export_children=export_children, export_attachment=export_attachment) as stream: with open(path, 'wb') as f: for chunk in stream.iter_content(chunk_size=10000): if chunk: