Completed
Push — master ( a73a95...7cbbbf )
by Jace
17s
created

WordModel   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 6
cts 7
cp 0.8571
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A ImageStore.latest() 0 3 1
1
# pylint: disable=no-member
2
3 1
import os
4 1
import shutil
5 1
from contextlib import suppress
6 1
import logging
7
8 1
log = logging.getLogger(__name__)
9
10
11 1
class ImageStore:
12
13 1
    LATEST = "latest.jpg"
14
15 1
    def __init__(self, root, config):
16 1
        self.root = root
17 1
        self.regenerate_images = config.get('REGENERATE_IMAGES', False)
18
19 1
    @property
20
    def latest(self):
21 1
        return os.path.join(self.root, self.LATEST)
22
23 1
    def exists(self, image):
24 1
        image.root = self.root
25
        # TODO: add a way to determine if the styled image was already generated
26 1
        return os.path.isfile(image.path) and not image.style
27
28 1
    def create(self, image):
29 1
        if self.exists(image) and not self.regenerate_images:
30
            return
31
32 1
        image.root = self.root
33 1
        image.generate()
34
35 1
        with suppress(IOError):
36 1
            os.remove(self.latest)
37
        shutil.copy(image.path, self.latest)
38