Completed
Push — master ( b95acc...a5fbcd )
by Oleksandr
01:06
created

Events.from_ini()   A

Complexity

Conditions 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 1
cts 2
cp 0.5
rs 9.4285
cc 1
crap 1.125
1
# coding: utf-8
2
3 1
import zope.interface
4
5 1
from schematics.models import Model
6 1
from schematics.types import StringType, IntType, BooleanType
7 1
from schematics.types.compound import ModelType
8
9 1
from .interfaces import INISerializable
10
11
12 1 View Code Duplication
@zope.interface.implementer(INISerializable)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
13 1
class Logging(Model):
14 1
    file_name = StringType(
15
        default="eventlog.lst",
16
        min_length=1,
17
        required=True,
18
    )
19 1
    keep = BooleanType(
20
        default=True,
21
        required=True,
22
    )
23 1
    log_buildings = BooleanType(
24
        default=False,
25
        required=True,
26
    )
27
28 1
    @classmethod
29
    def from_ini(cls, ini):
30
        return cls({
31
            'file_name': ini.get(
32
                'game', 'eventlog',
33
                fallback=cls.file_name.default,
34
            ),
35
            'keep': ini.getboolean(
36
                'game', 'eventlogkeep',
37
                fallback=cls.keep.default,
38
            ),
39
            'log_buildings': ini.getboolean(
40
                'game', 'eventlogHouse',
41
                fallback=cls.log_buildings.default,
42
            ),
43
        })
44
45
46 1
@zope.interface.implementer(INISerializable)
47 1
class Events(Model):
48 1
    chat_level = IntType(
49
        min_value=0,
50
        max_value=3,
51
        default=0,
52
        required=True,
53
    )
54 1
    logging = ModelType(
55
        model_spec=Logging,
56
        required=True,
57
    )
58
59 1
    @classmethod
60
    def from_ini(cls, ini):
61
        return cls({
62
            'chat_level': ini.getint(
63
                'chat', 'autoLogDetail',
64
                fallback=cls.chat_level.default,
65
            ),
66
            'logging': Logging.from_ini(ini),
67
        })
68