| Total Complexity | 7 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Coverage | 95% |
| 1 | 1 | import os |
|
| 4 | 1 | class ImageStore: |
|
| 5 | |||
| 6 | 1 | LATEST = "latest.jpg" |
|
| 7 | |||
| 8 | 1 | def __init__(self, root, config): |
|
| 9 | 1 | self.root = root |
|
| 10 | 1 | self.debug = config.get('DEBUG', False) |
|
| 11 | |||
| 12 | 1 | @property |
|
| 13 | def latest(self): |
||
| 14 | 1 | return os.path.join(self.root, self.LATEST) |
|
| 15 | |||
| 16 | 1 | def exists(self, image): |
|
| 17 | 1 | image.root = self.root |
|
| 18 | # TODO: add a way to determine if the styled image was already generated |
||
| 19 | 1 | return os.path.isfile(image.path) and not image.style |
|
| 20 | |||
| 21 | 1 | def create(self, image): |
|
| 22 | 1 | if self.exists(image) and not self.debug: |
|
| 23 | return |
||
| 24 | |||
| 25 | 1 | image.root = self.root |
|
| 26 | 1 | image.generate() |
|
| 27 | |||
| 28 | 1 | try: |
|
| 29 | 1 | os.remove(self.latest) |
|
| 30 | 1 | except IOError: |
|
| 31 | 1 | pass |
|
| 32 | os.symlink(image.path, self.latest) |
||
| 33 |