Completed
Push — master ( b5954e...236f10 )
by Jace
10s
created

ImageStore.create()   A

Complexity

Conditions 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.432
Metric Value
cc 4
dl 0
loc 12
ccs 7
cts 10
cp 0.7
crap 4.432
rs 9.2
1 1
import os
2
3
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
        except IOError:
31
            pass
32
        os.symlink(image.path, self.latest)
33