Skip to content

Commit

Permalink
Implement export to ini
Browse files Browse the repository at this point in the history
  • Loading branch information
o3bvv committed Jun 25, 2017
1 parent 92aa2b2 commit ebdfe9f
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 14 deletions.
4 changes: 4 additions & 0 deletions il2fb/config/ds/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def from_ini(cls, ini):
for field_name, model_type in cls.fields.items()
})

def to_ini(self, ini):
for field_name in self.iter():
self[field_name].to_ini(ini)

@classmethod
def default(cls):
return cls({
Expand Down
6 changes: 5 additions & 1 deletion il2fb/config/ds/schemas/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from schematics.types import StringType

from .interfaces import INISerializable, DefaultProvider
from .helpers import field_from_ini
from .helpers import field_from_ini, field_to_ini


@zope.interface.implementer(INISerializable)
Expand Down Expand Up @@ -34,6 +34,10 @@ def from_ini(cls, ini):
),
})

def to_ini(self, ini):
field_to_ini(self.name, ini, 'NET', 'serverName')
field_to_ini(self.description, ini, 'NET', 'serverDescription')

@classmethod
def default(cls):
return cls({
Expand Down
7 changes: 6 additions & 1 deletion il2fb/config/ds/schemas/anticheat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from schematics.types.compound import ModelType

from ..interfaces import INISerializable, DefaultProvider
from ..helpers import field_from_ini
from ..helpers import field_from_ini, field_to_ini
from .lags import Lags
from .speedhack import Speedhack

Expand Down Expand Up @@ -41,6 +41,11 @@ def from_ini(cls, ini):
'speedhack': Speedhack.from_ini(ini),
})

def to_ini(self, ini):
field_to_ini(self.version_check_level, ini, 'NET', 'checkRuntime')
self.lags.to_ini(ini)
self.speedhack.to_ini(ini)

@classmethod
def default(cls):
return cls({
Expand Down
19 changes: 18 additions & 1 deletion il2fb/config/ds/schemas/anticheat/lags.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from schematics.types.compound import ModelType

from ..constants import NO_CHEATER_WARNINGS_LIMIT_FLAG
from ..helpers import field_from_ini
from ..helpers import field_from_ini, field_to_ini
from ..interfaces import INISerializable, DefaultProvider


Expand Down Expand Up @@ -52,6 +52,10 @@ def from_ini(cls, ini):
),
})

def to_ini(self, ini):
field_to_ini(self.near, ini, 'MaxLag', 'nearMaxLagTime')
field_to_ini(self.far, ini, 'MaxLag', 'farMaxLagTime')

@classmethod
def default(cls):
return cls({
Expand Down Expand Up @@ -95,6 +99,15 @@ def from_ini(cls, ini):
'limit': limit,
})

def to_ini(self, ini):
limit = (
NO_CHEATER_WARNINGS_LIMIT_FLAG
if self.limit is None
else self.limit
)
field_to_ini(limit, ini, 'MaxLag', 'cheaterWarningNum')
field_to_ini(self.delay, ini, 'MaxLag', 'cheaterWarningDelay')

@classmethod
def default(cls):
return cls({
Expand Down Expand Up @@ -122,6 +135,10 @@ def from_ini(cls, ini):
'warnings': Warnings.from_ini(ini),
})

def to_ini(self, ini):
for field_name in self.iter():
self[field_name].to_ini(ini)

@classmethod
def default(cls):
return cls({
Expand Down
8 changes: 7 additions & 1 deletion il2fb/config/ds/schemas/anticheat/speedhack.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from schematics.types import FloatType, BooleanType

from ..interfaces import INISerializable, DefaultProvider
from ..helpers import field_from_ini
from ..helpers import field_from_ini, field_to_ini


@zope.interface.implementer(INISerializable)
Expand Down Expand Up @@ -53,6 +53,12 @@ def from_ini(cls, ini):
),
})

def to_ini(self, ini):
field_to_ini(self.check_server_time_speed, ini, 'NET', 'checkServerTimeSpeed')
field_to_ini(self.check_client_time_speed, ini, 'NET', 'checkClientTimeSpeed')
field_to_ini(self.max_time_difference, ini, 'NET', 'checkTimeSpeedDifferense')
field_to_ini(self.max_time_difference_period, ini, 'NET', 'checkTimeSpeedInterval')

@classmethod
def default(cls):
return cls({
Expand Down
15 changes: 14 additions & 1 deletion il2fb/config/ds/schemas/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from schematics.types.compound import ModelType

from .interfaces import INISerializable, DefaultProvider
from .helpers import field_from_ini
from .helpers import field_from_ini, field_to_ini


@zope.interface.implementer(INISerializable)
Expand Down Expand Up @@ -53,6 +53,12 @@ def from_ini(cls, ini):
),
})

def to_ini(self, ini):
field_to_ini(self.host, ini, 'NET', 'socksHost')
field_to_ini(self.port, ini, 'NET', 'socksPort')
field_to_ini(self.user, ini, 'NET', 'socksUser')
field_to_ini(self.password, ini, 'NET', 'socksPwd')

@classmethod
def default(cls):
return cls({
Expand Down Expand Up @@ -113,6 +119,13 @@ def from_ini(cls, ini):
'proxy': Proxy.from_ini(ini),
})

def to_ini(self, ini):
field_to_ini(self.host, ini, 'NET', 'localHost')
field_to_ini(self.port, ini, 'NET', 'localPort')
field_to_ini(self.max_clients, ini, 'NET', 'serverChannels')
field_to_ini(self.bandwidth, ini, 'NET', 'speed')
self.proxy.to_ini(ini)

@classmethod
def default(cls):
return cls({
Expand Down
27 changes: 26 additions & 1 deletion il2fb/config/ds/schemas/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .constants import FORBID_CONSOLE_CONNECTIONS_FLAG
from .interfaces import INISerializable, DefaultProvider
from .helpers import field_from_ini
from .helpers import field_from_ini, field_to_ini


@zope.interface.implementer(INISerializable)
Expand Down Expand Up @@ -50,6 +50,17 @@ def from_ini(cls, ini):
),
})

def to_ini(self, ini):
port = (
FORBID_CONSOLE_CONNECTIONS_FLAG
if self.port is None
else self.port
)
allowed_hosts = ' '.join(self.allowed_hosts)

field_to_ini(port, ini, 'Console', 'IP')
field_to_ini(allowed_hosts, ini, 'Console', 'IPS')

@classmethod
def default(cls):
return cls({
Expand Down Expand Up @@ -100,6 +111,12 @@ def from_ini(cls, ini):
),
})

def to_ini(self, ini):
field_to_ini(self.enabled, ini, 'Console', 'LOG')
field_to_ini(self.file_name, ini, 'Console', 'LOGFILE')
field_to_ini(self.log_time, ini, 'Console', 'LOGTIME')
field_to_ini(self.keep_file, ini, 'Console', 'LOGKEEP')

@classmethod
def default(cls):
return cls({
Expand Down Expand Up @@ -137,6 +154,10 @@ def from_ini(cls, ini):
),
})

def to_ini(self, ini):
field_to_ini(self.max_commands, ini, 'Console', 'HISTORYCMD')
field_to_ini(self.max_records, ini, 'Console', 'HISTORY')

@classmethod
def default(cls):
return cls({
Expand Down Expand Up @@ -169,6 +190,10 @@ def from_ini(cls, ini):
'history': History.from_ini(ini),
})

def to_ini(self, ini):
for field_name in self.iter():
self[field_name].to_ini(ini)

@classmethod
def default(cls):
return cls({
Expand Down
18 changes: 17 additions & 1 deletion il2fb/config/ds/schemas/device_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .constants import FORBID_DEVICE_LINK_CONNECTIONS_FLAG
from .interfaces import INISerializable, DefaultProvider
from .helpers import field_from_ini
from .helpers import field_from_ini, field_to_ini


@zope.interface.implementer(INISerializable)
Expand Down Expand Up @@ -58,6 +58,18 @@ def from_ini(cls, ini):
),
})

def to_ini(self, ini):
port = (
FORBID_DEVICE_LINK_CONNECTIONS_FLAG
if self.port is None
else self.port
)
allowed_hosts = ' '.join(self.allowed_hosts)

field_to_ini(port, ini, 'DeviceLink', 'port')
field_to_ini(self.host, ini, 'DeviceLink', 'host')
field_to_ini(allowed_hosts, ini, 'DeviceLink', 'IPS')

@classmethod
def default(cls):
return cls({
Expand All @@ -81,6 +93,10 @@ def from_ini(cls, ini):
'connection': Connection.from_ini(ini),
})

def to_ini(self, ini):
for field_name in self.iter():
self[field_name].to_ini(ini)

@classmethod
def default(cls):
return cls({
Expand Down
11 changes: 10 additions & 1 deletion il2fb/config/ds/schemas/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from schematics.types.compound import ModelType

from .interfaces import INISerializable, DefaultProvider
from .helpers import field_from_ini
from .helpers import field_from_ini, field_to_ini


@zope.interface.implementer(INISerializable)
Expand Down Expand Up @@ -44,6 +44,11 @@ def from_ini(cls, ini):
),
})

def to_ini(self, ini):
field_to_ini(self.file_name, ini, 'game', 'eventlog')
field_to_ini(self.keep_file, ini, 'game', 'eventlogkeep')
field_to_ini(self.log_buildings, ini, 'game', 'eventlogHouse')

@classmethod
def default(cls):
return cls({
Expand Down Expand Up @@ -76,6 +81,10 @@ def from_ini(cls, ini):
'logging': Logging.from_ini(ini),
})

def to_ini(self, ini):
field_to_ini(self.chat_level, ini, 'chat', 'autoLogDetail')
self.logging.to_ini(ini)

@classmethod
def default(cls):
return cls({
Expand Down
14 changes: 13 additions & 1 deletion il2fb/config/ds/schemas/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _get_getter(class_type, ini):
try:
method_name = _TYPE_TO_GETTER_MAP.get(class_type)
return getattr(ini, method_name)
except:
except Exception:
return ini.get


Expand All @@ -32,3 +32,15 @@ def field_from_ini(field, ini, section, option, default=_NO_VALUE):
if default is not _NO_VALUE else
field.default
)


def field_to_ini(field_value, ini, section, option):
if not ini.has_section(section):
ini.add_section(section)

if isinstance(field_value, bool):
field_value = 1 if field_value else 0
elif isinstance(field_value, float):
field_value = round(field_value, 2)

ini[section][option] = str(field_value)
7 changes: 6 additions & 1 deletion il2fb/config/ds/schemas/hud.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from schematics.types import BooleanType

from .interfaces import INISerializable, DefaultProvider
from .helpers import field_from_ini
from .helpers import field_from_ini, field_to_ini


@zope.interface.implementer(INISerializable)
Expand Down Expand Up @@ -44,6 +44,11 @@ def from_ini(cls, ini):
),
})

def to_ini(self, ini):
field_to_ini(not self.show_mission_info, ini, 'game', 'NoMissionInfoHud')
field_to_ini(not self.show_kill_info, ini, 'game', 'noKillInfoHud')
field_to_ini(self.show_at_bottom, ini, 'game', 'lowInfoHud')

@classmethod
def default(cls):
return cls({
Expand Down
6 changes: 6 additions & 0 deletions il2fb/config/ds/schemas/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def from_ini(ini):
"""

def to_ini(ini):
"""
Update INI config from current object.
"""


class DefaultProvider(zope.interface.Interface):

Expand Down
11 changes: 10 additions & 1 deletion il2fb/config/ds/schemas/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from schematics.types import BooleanType, IntType

from .interfaces import INISerializable, DefaultProvider
from .helpers import field_from_ini
from .helpers import field_from_ini, field_to_ini


@zope.interface.implementer(INISerializable)
Expand Down Expand Up @@ -75,6 +75,15 @@ def from_ini(cls, ini):
),
})

def to_ini(self, ini):
field_to_ini(self.difficulty, ini, 'NET', 'difficulty')
field_to_ini(self.display_custom_skins, ini, 'NET', 'SkinDownload')
field_to_ini(self.allow_custom_sounds, ini, 'NET', 'allowCustomSounds')
field_to_ini(self.filter_user_names, ini, 'NET', 'filterUserNames')
field_to_ini(self.display_small_way_point_labels, ini, 'game', 'SmallMapWPLabels')
field_to_ini(self.skip_paratrooper_views, ini, 'game', 'SkipParatrooperViews')
field_to_ini(self.use_new_clouds_rendering, ini, 'game', 'TypeClouds')

@classmethod
def default(cls):
return cls({
Expand Down
7 changes: 6 additions & 1 deletion il2fb/config/ds/schemas/morse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from schematics.types import BooleanType

from .interfaces import INISerializable, DefaultProvider
from .helpers import field_from_ini
from .helpers import field_from_ini, field_to_ini


@zope.interface.implementer(INISerializable)
Expand Down Expand Up @@ -42,6 +42,11 @@ def from_ini(cls, ini):
),
})

def to_ini(self, ini):
field_to_ini(self.allow_morse_as_text, ini, 'NET', 'allowMorseAsText')
field_to_ini(self.show_morse_as_text, ini, 'game', 'ShowMorseAsText')
field_to_ini(self.block_morse_chat, ini, 'game', 'BlockMorseChat')

@classmethod
def default(cls):
return cls({
Expand Down
Loading

0 comments on commit ebdfe9f

Please sign in to comment.