| Total Complexity | 7 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Coverage | 94.44% |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | # pylint: disable=no-member |
||
| 11 | 1 | class ImageStore: |
|
| 12 | |||
| 13 | 1 | LATEST = "latest.jpg" |
|
| 14 | |||
| 15 | 1 | def __init__(self, root, config): |
|
| 16 | 1 | self.root = root |
|
| 17 | 1 | self.regenerate_images = config.get('REGENERATE_IMAGES', False) |
|
| 18 | |||
| 19 | 1 | @property |
|
| 20 | def latest(self): |
||
| 21 | 1 | return os.path.join(self.root, self.LATEST) |
|
| 22 | |||
| 23 | 1 | def exists(self, image): |
|
| 24 | 1 | image.root = self.root |
|
| 25 | # TODO: add a way to determine if the styled image was already generated |
||
| 26 | 1 | return os.path.isfile(image.path) and not image.style |
|
| 27 | |||
| 28 | 1 | def create(self, image): |
|
| 29 | 1 | if self.exists(image) and not self.regenerate_images: |
|
| 30 | return |
||
| 31 | |||
| 32 | 1 | image.root = self.root |
|
| 33 | 1 | image.generate() |
|
| 34 | |||
| 35 | 1 | with suppress(IOError): |
|
| 36 | 1 | os.remove(self.latest) |
|
| 37 | shutil.copy(image.path, self.latest) |
||
| 38 |