Completed
Pull Request — master (#154)
by Josh
08:30
created

decode_bytstring_dict()   A

Complexity

Conditions 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2
Metric Value
cc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
rs 9.4285
1 1
import os
2
3
from flask import current_app as app
0 ignored issues
show
Configuration introduced by
The import flask could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
4 1
5
from ..extensions import redis
6 1
from ..domain import Image, Text
7
8 1
9 1
def decode_bytstring_dict(dct):
10
    out = {}
11 1
    for k, v in dct.items():
12
        out[k.decode()] = v.decode()
13 1
    return out
14
15 1
16 1
class ImageStore:
17
18 1
    def __init__(self, root):
19
        self.root = root
20 1
21 1
    @property
22 1
    def latest(self):
23 1
        data = redis.hgetall('latest')
24 1
        if not data:
25 1
            raise FileNotFoundError()
26 1
27 1
        data = decode_bytstring_dict(data)
28
29
        text = Text(data['path'])
30
31
        style = data.get('style', None)
32
        if style == 'None':
33
            style = None
34
35
        template = app.template_service.find(
36
            data['template'],
37
            allow_missing=True
38
        )
39
        image = Image(template, text, style=style, root=self.root)
40
41
        return image
42
43
    def exists(self, image):
44
        image.root = self.root
45
        # TODO: add a way to determine if the styled image was already generated
46
        return os.path.isfile(image.path) and not image.style
47
48
    def create(self, image):
49
        image.root = self.root
50
        image.generate()
51