Skip to content

Commit

Permalink
Two new dev scripts to copy generated examples images to/from a shared
Browse files Browse the repository at this point in the history
dropbox location so that they can be used with readthedocs
  • Loading branch information
thesamovar committed Feb 26, 2015
1 parent 4af4233 commit edc1519
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
38 changes: 38 additions & 0 deletions dev/tools/docs/copy_examples_images_to_dropbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'''
This script copies the examples_images to a zipfile in a dropbox location
so that it can be read by download_examples_images_from_dropbox.py. This
should be run after a successful run of run_examples.py.
'''

import os, sys, zipfile, glob

__all__ = ['copy_examples_images_to_dropbox']

# add your dropbox location here
possible_dropbox_directories = [
'~/Dropbox/Projects/Shared Brian/Documentation example images',
]

def copy_examples_images_to_dropbox():

zipname = None
for dirname in possible_dropbox_directories:
dirname = os.path.expanduser(dirname)
if os.path.exists(dirname):
zipname = os.path.join(dirname, 'doc_example_images.zip')

if zipname is None:
print 'Cannot find Dropbox directory'
return

imgs = glob.glob('../../../docs_sphinx/examples_images/*.png')

with zipfile.ZipFile(zipname, 'w') as z:
for f in imgs:
base, fname = os.path.split(f)
z.write(f, fname)


if __name__=='__main__':
copy_examples_images_to_dropbox()

26 changes: 26 additions & 0 deletions dev/tools/docs/download_examples_images_from_dropbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'''
Script to download and extract saved examples images from a shared Dropbox
file location. This is used for the documentation system. Images generated
on one developer's computer are copied to a dropbox file (by the script
copy_examples_images_to_dropbox.py) and then readthedocs script can just
download the images (which can take a couple of hours to generate so that
wouldn't work directly on readthedocs).
'''

import os, zipfile, urllib2

zipfile_url = 'https://www.dropbox.com/s/uqb44b9t1gpvy61/doc_example_images.zip?dl=1'

def download_examples_images_from_dropbox():
outputdir = '../../../docs_sphinx/examples_images'
if not os.path.exists(outputdir):
os.mkdir(outputdir)
outfname = os.path.join(outputdir, 'doc_example_images.zip')
f = urllib2.urlopen(zipfile_url)
open(outfname, 'wb').write(f.read())
z = zipfile.ZipFile(outfname, 'r')
z.extractall(outputdir)

if __name__=='__main__':
download_examples_images_from_dropbox()

0 comments on commit edc1519

Please sign in to comment.