memegen.stores.image.ImageStore.create()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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