Completed
Pull Request — master (#394)
by Jace
08:10
created

ImageService.__init__()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 5
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1 1
import logging
2
3 1
from ..domain import Image, Font
4
5 1
from ._base import Service
6
7
8 1
log = logging.getLogger(__name__)
9
10
11 1
class ImageService(Service):
12
13 1
    def __init__(self, template_store, font_store, image_store, **kwargs):
14 1
        super().__init__(**kwargs)
15 1
        self.template_store = template_store
16 1
        self.font_store = font_store
17 1
        self.image_store = image_store
18
19 1
    def create(self, template, text, font=None, **options):
20 1
        image = Image(
21
            template, text,
22
            font=font or self.font_store.find(Font.DEFAULT),
23
            watermark_font=self.font_store.find(Font.DEFAULT),
24
            **options,
0 ignored issues
show
introduced by
invalid syntax
Loading history...
25
        )
26
27 1
        try:
28 1
            self.image_store.create(image)
29 1
        except OSError as exception:
30 1
            if "name too long" in str(exception):
31 1
                exception = self.exceptions.FilenameTooLong
32 1
            elif "image file" in str(exception):
33 1
                exception = self.exceptions.InvalidImageLink
34 1
            raise exception from None  # pylint: disable=raising-bad-type
35
        except SystemError as exception:
36
            log.warning(exception)
37
            raise self.exceptions.InvalidImageLink from None
38
39
        return image
40