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

ImageStore   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 27
ccs 17
cts 18
cp 0.9444
rs 10
c 3
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A exists() 0 4 1
A __init__() 0 3 1
A latest() 0 3 1
A create() 0 10 4
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