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 ListType, ModelType |
8
|
|
|
|
9
|
1 |
|
from .interfaces import INISerializable |
10
|
|
|
|
11
|
|
|
|
12
|
1 |
View Code Duplication |
@zope.interface.implementer(INISerializable) |
|
|
|
|
13
|
1 |
|
class Connection(Model): |
14
|
1 |
|
port = IntType( |
15
|
|
|
min_value=0, |
16
|
|
|
max_value=65000, |
17
|
|
|
default=0, |
18
|
|
|
required=True, |
19
|
|
|
) |
20
|
1 |
|
allowed_hosts = ListType( |
21
|
|
|
field=StringType, |
22
|
|
|
min_size=0, |
23
|
|
|
required=True, |
24
|
|
|
min_length=1, |
25
|
|
|
) |
26
|
|
|
|
27
|
1 |
|
@classmethod |
28
|
|
|
def from_ini(cls, ini): |
29
|
|
|
return cls({ |
30
|
|
|
'port': ini.getint( |
31
|
|
|
'Console', 'IP', |
32
|
|
|
fallback=cls.port.default, |
33
|
|
|
), |
34
|
|
|
'allowed_hosts': [ |
35
|
|
|
x.strip() |
36
|
|
|
for x in |
37
|
|
|
( |
38
|
|
|
ini |
39
|
|
|
.get('Console', 'IPS', fallback="") |
40
|
|
|
.split() |
41
|
|
|
) |
42
|
|
|
], |
43
|
|
|
}) |
44
|
|
|
|
45
|
|
|
|
46
|
1 |
View Code Duplication |
@zope.interface.implementer(INISerializable) |
|
|
|
|
47
|
1 |
|
class Logging(Model): |
48
|
1 |
|
is_enabled = BooleanType( |
49
|
|
|
default=False, |
50
|
|
|
required=True, |
51
|
|
|
) |
52
|
1 |
|
file_name = StringType( |
53
|
|
|
default="log.lst", |
54
|
|
|
min_length=1, |
55
|
|
|
required=True, |
56
|
|
|
) |
57
|
1 |
|
keep = BooleanType( |
58
|
|
|
default=True, |
59
|
|
|
required=True, |
60
|
|
|
) |
61
|
1 |
|
log_time = BooleanType( |
62
|
|
|
default=False, |
63
|
|
|
required=True, |
64
|
|
|
) |
65
|
|
|
|
66
|
1 |
|
@classmethod |
67
|
|
|
def from_ini(cls, ini): |
68
|
|
|
return cls({ |
69
|
|
|
'is_enabled': ini.getboolean( |
70
|
|
|
'Console', 'LOG', |
71
|
|
|
fallback=cls.is_enabled.default, |
72
|
|
|
), |
73
|
|
|
'file_name': ini.get( |
74
|
|
|
'Console', 'LOGFILE', |
75
|
|
|
fallback=cls.file_name.default, |
76
|
|
|
), |
77
|
|
|
'log_time': ini.getboolean( |
78
|
|
|
'Console', 'LOGTIME', |
79
|
|
|
fallback=cls.log_time.default, |
80
|
|
|
), |
81
|
|
|
'keep': ini.getboolean( |
82
|
|
|
'Console', 'LOGKEEP', |
83
|
|
|
fallback=cls.keep.default, |
84
|
|
|
), |
85
|
|
|
}) |
86
|
|
|
|
87
|
|
|
|
88
|
1 |
View Code Duplication |
@zope.interface.implementer(INISerializable) |
|
|
|
|
89
|
1 |
|
class HistorySize(Model): |
90
|
1 |
|
commands = IntType( |
91
|
|
|
min_value=0, |
92
|
|
|
max_value=10000, |
93
|
|
|
default=128, |
94
|
|
|
required=True, |
95
|
|
|
) |
96
|
1 |
|
records = IntType( |
97
|
|
|
min_value=0, |
98
|
|
|
max_value=10000, |
99
|
|
|
default=128, |
100
|
|
|
required=True, |
101
|
|
|
) |
102
|
|
|
|
103
|
1 |
|
@classmethod |
104
|
|
|
def from_ini(cls, ini): |
105
|
|
|
return cls({ |
106
|
|
|
'commands': ini.getint( |
107
|
|
|
'Console', 'HISTORYCMD', |
108
|
|
|
fallback=cls.commands.default, |
109
|
|
|
), |
110
|
|
|
'records': ini.getint( |
111
|
|
|
'Console', 'HISTORY', |
112
|
|
|
fallback=cls.records.default, |
113
|
|
|
), |
114
|
|
|
}) |
115
|
|
|
|
116
|
|
|
|
117
|
1 |
|
@zope.interface.implementer(INISerializable) |
118
|
1 |
|
class Console(Model): |
119
|
1 |
|
connection = ModelType( |
120
|
|
|
model_spec=Connection, |
121
|
|
|
required=True, |
122
|
|
|
) |
123
|
1 |
|
logging = ModelType( |
124
|
|
|
model_spec=Logging, |
125
|
|
|
required=True, |
126
|
|
|
) |
127
|
1 |
|
history_size = ModelType( |
128
|
|
|
model_spec=HistorySize, |
129
|
|
|
required=True, |
130
|
|
|
) |
131
|
|
|
|
132
|
1 |
|
@classmethod |
133
|
|
|
def from_ini(cls, ini): |
134
|
|
|
return cls({ |
135
|
|
|
'connection': Connection.from_ini(ini), |
136
|
|
|
'logging': Logging.from_ini(ini), |
137
|
|
|
'history_size': HistorySize.from_ini(ini), |
138
|
|
|
}) |
139
|
|
|
|