Completed
Pull Request — master (#391)
by Jace
08:05
created

ImageStore.create()   A

Complexity

Conditions 3

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 6
ccs 4
cts 5
cp 0.8
crap 3.072
rs 9.4285
c 0
b 0
f 0
1 1
import os
2 1
import logging
3
4 1
log = logging.getLogger(__name__)
5
6
7 1
class ImageStore:
8
9 1
    def __init__(self, root, config):
10 1
        self.root = root
11 1
        self.regenerate_images = config.get('REGENERATE_IMAGES', False)
12
13 1
    def exists(self, image):
14 1
        image.root = self.root
15
        # TODO: add a way to determine if the styled image was already generated
16 1
        return os.path.isfile(image.path) and not image.style
17
18 1
    def create(self, image):
19 1
        if self.exists(image) and not self.regenerate_images:
20
            return
21
22 1
        image.root = self.root
23
        image.save()
24