Completed
Push — master ( 9d3bc0...b059cb )
by Oleksandr
01:07
created

Logging   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 6
Bugs 0 Features 2
Metric Value
wmc 3
c 6
b 0
f 2
dl 0
loc 39
ccs 8
cts 10
cp 0.8
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A default() 0 5 2
A from_ini() 0 14 1
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, DefaultProvider
10 1
from .helpers import field_from_ini
11
12
13 1
@zope.interface.implementer(INISerializable)
14 1
@zope.interface.implementer(DefaultProvider)
15 1
class Logging(Model):
16 1
    file_name = StringType(
17
        default="eventlog.lst",
18
        min_length=1,
19
        required=True,
20
    )
21 1
    keep = BooleanType(
22
        default=True,
23
        required=True,
24
    )
25 1
    log_buildings = BooleanType(
26
        default=False,
27
        required=True,
28
    )
29
30 1
    @classmethod
31
    def from_ini(cls, ini):
32
        return cls({
33
            'file_name': field_from_ini(
34
                cls.file_name, ini,
35
                'game', 'eventlog',
36
            ),
37
            'keep': field_from_ini(
38
                cls.keep, ini,
39
                'game', 'eventlogkeep',
40
            ),
41
            'log_buildings': field_from_ini(
42
                cls.log_buildings, ini,
43
                'game', 'eventlogHouse',
44
            ),
45
        })
46
47 1
    @classmethod
48
    def default(cls):
49
        return cls({
50
            field_name: field.default
51
            for field_name, field in cls.fields.items()
52
        })
53
54
55 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...
56 1
@zope.interface.implementer(DefaultProvider)
57 1
class Events(Model):
58 1
    chat_level = IntType(
59
        min_value=0,
60
        max_value=3,
61
        default=0,
62
        required=True,
63
    )
64 1
    logging = ModelType(
65
        model_spec=Logging,
66
        required=True,
67
    )
68
69 1
    @classmethod
70
    def from_ini(cls, ini):
71
        return cls({
72
            'chat_level': field_from_ini(
73
                cls.chat_level, ini,
74
                'chat', 'autoLogDetail',
75
            ),
76
            'logging': Logging.from_ini(ini),
77
        })
78
79 1
    @classmethod
80
    def default(cls):
81
        return cls({
82
            'chat_level': cls.chat_level.default,
83
            'logging': Logging.default(),
84
        })
85