|
18 | 18 |
|
19 | 19 | multiimage = re.compile('(.*)_\d\d') |
20 | 20 |
|
| 21 | +def make_thumbnail(args): |
| 22 | + image.thumbnail(args[0], args[1], 0.3) |
| 23 | + |
21 | 24 | def out_of_date(original, derived): |
22 | 25 | return (not os.path.exists(derived) or |
23 | 26 | os.stat(derived).st_mtime < os.stat(original).st_mtime) |
@@ -87,16 +90,23 @@ def gen_gallery(app, doctree): |
87 | 90 | link = 'examples/%s/%s.html'%(subdir, basename) |
88 | 91 | rows.append(link_template%(link, thumbfile, basename)) |
89 | 92 |
|
90 | | - fh = file(os.path.join(app.builder.srcdir, '_templates', 'gallery.html'), |
91 | | - 'w') |
92 | | - fh.write(template%'\n'.join(rows)) |
93 | | - fh.close() |
| 93 | + # Only write out the file if the contents have actually changed. |
| 94 | + # Otherwise, this triggers a full rebuild of the docs |
| 95 | + content = template%'\n'.join(rows) |
| 96 | + gallery_path = os.path.join(app.builder.srcdir, '_templates', 'gallery.html') |
| 97 | + if os.path.exists(gallery_path): |
| 98 | + fh = file(gallery_path, 'r') |
| 99 | + regenerate = fh.read() != content |
| 100 | + fh.close() |
| 101 | + else: |
| 102 | + regenerate = True |
| 103 | + if regenerate: |
| 104 | + fh = file(gallery_path, 'w') |
| 105 | + fh.write(content) |
| 106 | + fh.close() |
94 | 107 |
|
95 | 108 | try: |
96 | 109 | import multiprocessing |
97 | | - def make_thumbnail(args): |
98 | | - image.thumbnail(args[0], args[1], 0.3) |
99 | | - |
100 | 110 | app.builder.info("generating thumbnails... ", nonl=True) |
101 | 111 | pool = multiprocessing.Pool() |
102 | 112 | pool.map(make_thumbnail, thumbnails.iteritems()) |
|
0 commit comments