Completed
Push — master ( 263efb...8c1082 )
by Oleksandr
03:25
created

Refly.from_ini()   B

Complexity

Conditions 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3.1852

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 26
ccs 1
cts 3
cp 0.3333
rs 8.8571
cc 2
crap 3.1852
1
# coding: utf-8
2
3 1
import zope.interface
4
5 1
from schematics.models import Model
6 1
from schematics.types import BooleanType, IntType, FloatType
7
8 1
from .constants import NO_DEATH_LIMIT_FLAG
9 1
from .helpers import field_from_ini
10
from .interfaces import INISerializable, DefaultProvider
11
12 1
13 1
@zope.interface.implementer(INISerializable)
14 1
@zope.interface.implementer(DefaultProvider)
15 1
class Refly(Model):
16
    enabled = BooleanType(
17
        default=True,
18
        required=True,
19 1
    )
20
    death_penalty = IntType(
21
        min_value=0,
22
        default=0,
23
        required=True,
24 1
    )
25
    death_penalty_multiplier = FloatType(
26
        min_value=0.0,
27
        default=0.0,
28
        required=True,
29 1
    )
30
    death_limit = IntType(
31
        min_value=1,
32
        default=None,
33
        required=False,
34
    )
35 1
36
    @classmethod
37
    def from_ini(cls, ini):
38
        death_limit = field_from_ini(
39
            cls.death_limit, ini,
40
            'NET', 'maxAllowedKIA',
41
        )
42
        death_limit = (
43
            None
44
            if death_limit == NO_DEATH_LIMIT_FLAG
45
            else death_limit
46
        )
47
48
        return cls({
49
            'enabled': not field_from_ini(
50
                cls.enabled, ini,
51
                'NET', 'reflyDisabled',
52
            ),
53
            'death_penalty': field_from_ini(
54
                cls.death_penalty, ini,
55
                'NET', 'reflyKIADelay',
56 1
            ),
57
            'death_penalty_multiplier': field_from_ini(
58
                cls.death_penalty_multiplier, ini,
59
                'NET', 'reflyKIADelayMultiplier',
60
            ),
61
            'death_limit': death_limit,
62
        })
63
64
    @classmethod
65
    def default(cls):
66
        return cls({
67
            field_name: field.default
68
            for field_name, field in cls.fields.items()
69
        })
70