|
25 | 25 | from openslide.deepzoom import DeepZoomGenerator
|
26 | 26 | from optparse import OptionParser
|
27 | 27 | import os
|
| 28 | +import re |
28 | 29 | import sys
|
| 30 | +from unicodedata import normalize |
29 | 31 |
|
30 | 32 | class TileWorker(Process):
|
31 | 33 | def __init__(self, queue, slidepath, tile_size, overlap):
|
@@ -135,11 +137,23 @@ def _run_image(self, associated=None):
|
135 | 137 | basename = self._basename
|
136 | 138 | else:
|
137 | 139 | image = ImageSlide(self._slide.associated_images[associated])
|
138 |
| - basename = os.path.join(self._basename, associated) |
| 140 | + basename = os.path.join(self._basename, self._slugify(associated)) |
139 | 141 | dz = DeepZoomGenerator(image, self._tile_size, self._overlap)
|
140 | 142 | DeepZoomImageTiler(dz, basename, self._format, associated,
|
141 | 143 | self._queue).run()
|
142 | 144 |
|
| 145 | + _punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+') |
| 146 | + @classmethod |
| 147 | + def _slugify(cls, text): |
| 148 | + """Generates an ASCII-only slug.""" |
| 149 | + # Based on Flask snippet 5 |
| 150 | + result = [] |
| 151 | + for word in cls._punct_re.split(unicode(text, 'UTF-8').lower()): |
| 152 | + word = normalize('NFKD', word).encode('ascii', 'ignore') |
| 153 | + if word: |
| 154 | + result.append(word) |
| 155 | + return unicode(u'_'.join(result)) |
| 156 | + |
143 | 157 | def _shutdown(self):
|
144 | 158 | for _i in range(self._workers):
|
145 | 159 | self._queue.put(None)
|
|
0 commit comments