Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions dataikuapi/dss/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -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), 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to use with ... as stream: instead of the get/do/close construction? (if the stream can handle it)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it, it's indeed neater. Also I used underscores instead of camelCase for parameter names


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
Expand Down Expand Up @@ -247,6 +271,32 @@ 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):
"""
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
}
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):
"""
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()


def delete(self):
"""
Delete the article
Expand Down