@@ 13-81 (lines=69) @@ | ||
10 | from .interfaces import INISerializable, DefaultProvider |
|
11 | ||
12 | ||
13 | @zope.interface.implementer(INISerializable) |
|
14 | @zope.interface.implementer(DefaultProvider) |
|
15 | class Refly(Model): |
|
16 | enabled = BooleanType( |
|
17 | default=True, |
|
18 | required=True, |
|
19 | ) |
|
20 | death_penalty = IntType( |
|
21 | min_value=0, |
|
22 | default=0, |
|
23 | required=True, |
|
24 | ) |
|
25 | death_penalty_multiplier = FloatType( |
|
26 | min_value=0.0, |
|
27 | default=0.0, |
|
28 | required=True, |
|
29 | ) |
|
30 | death_limit = IntType( |
|
31 | min_value=1, |
|
32 | default=None, |
|
33 | required=False, |
|
34 | ) |
|
35 | ||
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 | False, |
|
53 | ), |
|
54 | 'death_penalty': field_from_ini( |
|
55 | cls.death_penalty, ini, |
|
56 | 'NET', 'reflyKIADelay', |
|
57 | ), |
|
58 | 'death_penalty_multiplier': field_from_ini( |
|
59 | cls.death_penalty_multiplier, ini, |
|
60 | 'NET', 'reflyKIADelayMultiplier', |
|
61 | ), |
|
62 | 'death_limit': death_limit, |
|
63 | }) |
|
64 | ||
65 | def to_ini(self, ini): |
|
66 | death_limit = ( |
|
67 | NO_DEATH_LIMIT_FLAG |
|
68 | if self.death_limit is None |
|
69 | else self.death_limit |
|
70 | ) |
|
71 | ||
72 | field_to_ini(not self.enabled, ini, 'NET', 'reflyDisabled') |
|
73 | field_to_ini(self.death_penalty, ini, 'NET', 'reflyKIADelay') |
|
74 | field_to_ini(self.death_penalty_multiplier, ini, 'NET', 'reflyKIADelayMultiplier') |
|
75 | field_to_ini(death_limit, ini, 'NET', 'maxAllowedKIA') |
|
76 | ||
77 | @classmethod |
|
78 | def default(cls): |
|
79 | return cls({ |
|
80 | field_name: field.default |
|
81 | for field_name, field in cls.fields.items() |
|
82 | }) |
|
83 |
@@ 14-78 (lines=65) @@ | ||
11 | from .helpers import field_from_ini, field_to_ini |
|
12 | ||
13 | ||
14 | @zope.interface.implementer(INISerializable) |
|
15 | @zope.interface.implementer(DefaultProvider) |
|
16 | class Connection(Model): |
|
17 | host = StringType( |
|
18 | default="", |
|
19 | required=True, |
|
20 | ) |
|
21 | port = IntType( |
|
22 | min_value=1000, |
|
23 | max_value=65000, |
|
24 | default=None, |
|
25 | required=False, |
|
26 | ) |
|
27 | allowed_hosts = ListType( |
|
28 | field=StringType, |
|
29 | min_size=0, |
|
30 | required=True, |
|
31 | min_length=1, |
|
32 | ) |
|
33 | ||
34 | @classmethod |
|
35 | def from_ini(cls, ini): |
|
36 | port = field_from_ini( |
|
37 | cls.port, ini, |
|
38 | 'DeviceLink', 'port', |
|
39 | ) |
|
40 | port = ( |
|
41 | None |
|
42 | if port == FORBID_DEVICE_LINK_CONNECTIONS_FLAG |
|
43 | else port |
|
44 | ) |
|
45 | ||
46 | return cls({ |
|
47 | 'host': field_from_ini( |
|
48 | cls.host, ini, |
|
49 | 'DeviceLink', 'host', |
|
50 | ), |
|
51 | 'port': port, |
|
52 | 'allowed_hosts': ( |
|
53 | field_from_ini( |
|
54 | cls.allowed_hosts, ini, |
|
55 | 'DeviceLink', 'IPS', default="", |
|
56 | ) |
|
57 | .split() |
|
58 | ), |
|
59 | }) |
|
60 | ||
61 | def to_ini(self, ini): |
|
62 | port = ( |
|
63 | FORBID_DEVICE_LINK_CONNECTIONS_FLAG |
|
64 | if self.port is None |
|
65 | else self.port |
|
66 | ) |
|
67 | allowed_hosts = ' '.join(self.allowed_hosts) |
|
68 | ||
69 | field_to_ini(port, ini, 'DeviceLink', 'port') |
|
70 | field_to_ini(self.host, ini, 'DeviceLink', 'host') |
|
71 | field_to_ini(allowed_hosts, ini, 'DeviceLink', 'IPS') |
|
72 | ||
73 | @classmethod |
|
74 | def default(cls): |
|
75 | return cls({ |
|
76 | 'host': cls.host.default, |
|
77 | 'port': cls.port.default, |
|
78 | 'allowed_hosts': [], |
|
79 | }) |
|
80 | ||
81 |