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

ImageStore.__init__()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
cc 1
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
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