-
-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shift PlotUploader class to separate file.
- Loading branch information
Karan Desai
committed
Jun 17, 2016
1 parent
c276de0
commit d4576a0
Showing
2 changed files
with
40 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import tempfile | ||
from pytest_html import extras | ||
import tardis | ||
|
||
|
||
class PlotUploader(object): | ||
def __init__(self): | ||
self._plots = list() | ||
self.plot_links = list() | ||
|
||
def add(self, plot, name): | ||
""" | ||
Accept a `matplotlib.pyplot.figure` and add it to self._plots. | ||
""" | ||
self._plots.append((plot, name)) | ||
|
||
def upload(self, request): | ||
""" | ||
Upload the content in self._plots to dokuwiki. | ||
""" | ||
dokuwiki_url = request.config.dokureport.dokuwiki_url | ||
for plot, name in self._plots: | ||
plot_file = tempfile.NamedTemporaryFile(suffix=".png") | ||
plot.savefig(plot_file.name) | ||
|
||
request.config.dokureport.doku_conn.medias.add( | ||
"plots:{0}_{1}.png".format(tardis.__githash__[0:7], name), | ||
plot_file.name | ||
) | ||
self.plot_links.append(extras.url( | ||
"{0}lib/exe/fetch.php?media=plots:{1}_{2}.png".format( | ||
dokuwiki_url, tardis.__githash__[0:7], name | ||
), name) | ||
) | ||
plot_file.close() | ||
|
||
def get_extras(self): | ||
return self.plot_links |