Completed
Push — master ( 156c71...ff0da6 )
by Jace
10:32
created

ImageStore.create()   A

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2
Metric Value
cc 2
dl 0
loc 8
ccs 8
cts 8
cp 1
crap 2
rs 9.4285
1 1
import os
2
3
4 1
class ImageStore:
5
6 1
    LATEST = "latest.jpg"
7
8 1
    def __init__(self, root):
9 1
        self.root = root
10
11 1
    @property
12
    def latest(self):
13 1
        return os.path.join(self.root, self.LATEST)
14
15 1
    def exists(self, image):
16 1
        image.root = self.root
17
        # TODO: add a way to determine if the styled image was already generated
18 1
        return os.path.isfile(image.path) and not image.style
19
20 1
    def create(self, image):
21 1
        image.root = self.root
22 1
        image.generate()
23 1
        try:
24 1
            os.remove(self.latest)
25 1
        except IOError:
26 1
            pass
27
        os.symlink(image.path, self.latest)
28