Completed
Push — master ( a73a95...7cbbbf )
by Jace
17s
created

ImageStore.__init__()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
# pylint: disable=no-member
2
3 1
import os
4 1
import shutil
5 1
from contextlib import suppress
6 1
import logging
7
8 1
log = logging.getLogger(__name__)
9
10
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