Skip to content

Commit 76abc07

Browse files
author
d.kovalenko
committed
A support of bool options is added [generic, restart_after_crash]
Tests are added, too.
1 parent b46595c commit 76abc07

12 files changed

+996
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# //////////////////////////////////////////////////////////////////////////////
2+
# Postgres Pro. PostgreSQL Configuration Python Library.
3+
4+
from __future__ import annotations
5+
6+
from ....handlers import OptionHandlerToPrepareGetValue
7+
from ....handlers import OptionHandlerCtxToPrepareGetValue
8+
from ....handlers import ConfigurationDataHandler
9+
10+
# //////////////////////////////////////////////////////////////////////////////
11+
# OptionHandlerToPrepareGetValue__Std__Bool
12+
13+
14+
class OptionHandlerToPrepareGetValue__Std__Bool(OptionHandlerToPrepareGetValue):
15+
def __init__(self):
16+
super().__init__()
17+
18+
# interface ----------------------------------------------------------
19+
def PrepareGetValue(self, ctx: OptionHandlerCtxToPrepareGetValue) -> any:
20+
assert type(ctx) == OptionHandlerCtxToPrepareGetValue
21+
assert isinstance(ctx.DataHandler, ConfigurationDataHandler)
22+
assert type(ctx.OptionName) == str
23+
assert ctx.OptionValue is not None
24+
25+
# [2025-04-13] Research
26+
assert type(ctx.OptionValue) == bool
27+
28+
return bool(ctx.OptionValue)
29+
30+
31+
# //////////////////////////////////////////////////////////////////////////////

src/core/option/handlers/prepare_get_value/option_handler_to_prepare_get_value__std__generic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def PrepareGetValue(self, ctx: OptionHandlerCtxToPrepareGetValue) -> any:
3030
pass # OK
3131
elif typeOfOptionValue == str:
3232
pass # OK
33+
elif typeOfOptionValue == bool:
34+
pass # OK
3335
else:
3436
BugCheckError.UnknownOptionValueType(ctx.OptionName, typeOfOptionValue)
3537

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# //////////////////////////////////////////////////////////////////////////////
2+
# Postgres Pro. PostgreSQL Configuration Python Library.
3+
4+
from __future__ import annotations
5+
6+
from ....raise_error import RaiseError
7+
8+
from ....handlers import OptionHandlerToPrepareSetValue
9+
from ....handlers import OptionHandlerCtxToPrepareSetValue
10+
from ....handlers import ConfigurationDataHandler
11+
12+
# //////////////////////////////////////////////////////////////////////////////
13+
# OptionHandlerToPrepareSetValue__Std__Bool
14+
15+
16+
class OptionHandlerToPrepareSetValue__Std__Bool(OptionHandlerToPrepareSetValue):
17+
def __init__(self):
18+
super().__init__()
19+
20+
# check
21+
assert not any(set(__class__.sm_Str_True).intersection(__class__.sm_Str_False))
22+
23+
# prefixes are checked
24+
assert not any(
25+
[
26+
x1
27+
for x1 in __class__.sm_Str_True
28+
if any([x2 for x2 in __class__.sm_Str_False if x2.startswith(x1)])
29+
]
30+
)
31+
assert not any(
32+
[
33+
x1
34+
for x1 in __class__.sm_Str_False
35+
if any([x2 for x2 in __class__.sm_Str_True if x2.startswith(x1)])
36+
]
37+
)
38+
39+
# interface ----------------------------------------------------------
40+
def PrepareSetValue(self, ctx: OptionHandlerCtxToPrepareSetValue) -> any:
41+
assert type(ctx) == OptionHandlerCtxToPrepareSetValue
42+
assert isinstance(ctx.DataHandler, ConfigurationDataHandler)
43+
assert type(ctx.OptionName) == str
44+
assert ctx.OptionValue is not None
45+
46+
optionValue = ctx.OptionValue
47+
optionValueType = type(optionValue)
48+
49+
if optionValueType == bool:
50+
return optionValue
51+
52+
if optionValueType == int:
53+
assert type(optionValue) == int
54+
55+
if optionValue == 0:
56+
return False
57+
58+
if optionValue == 1:
59+
return True
60+
61+
RaiseError.CantConvertOptionValue(ctx.OptionName, optionValueType, bool)
62+
63+
if optionValueType == str:
64+
assert type(optionValue) == str
65+
66+
if len(optionValue) < __class__.C_MIN_STR_VALUE_LENGTH:
67+
pass
68+
elif len(optionValue) > __class__.C_MAX_STR_VALUE_LENGTH:
69+
pass
70+
else:
71+
optionValue_lower = optionValue.lower()
72+
73+
if optionValue_lower in __class__.sm_Str_False:
74+
return False
75+
76+
if optionValue_lower in __class__.sm_Str_True:
77+
return True
78+
79+
RaiseError.CantConvertOptionValue(ctx.OptionName, optionValueType, bool)
80+
81+
RaiseError.BadOptionValueType(ctx.OptionName, optionValueType, bool)
82+
83+
# Private data -------------------------------------------------------
84+
C_MIN_STR_VALUE_LENGTH = 1
85+
C_MAX_STR_VALUE_LENGTH = 5
86+
87+
sm_Str_False: list[str] = [
88+
"of",
89+
"off",
90+
"f",
91+
"fa",
92+
"fal",
93+
"fals",
94+
"false",
95+
"n",
96+
"no",
97+
"0",
98+
]
99+
100+
sm_Str_True: list[str] = [
101+
"on",
102+
"t",
103+
"tr",
104+
"tru",
105+
"true",
106+
"y",
107+
"ye",
108+
"yes",
109+
"1",
110+
]
111+
112+
113+
# //////////////////////////////////////////////////////////////////////////////

src/core/option/handlers/prepare_set_value/option_handler_to_prepare_set_value__std__generic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def PrepareSetValue(self, ctx: OptionHandlerCtxToPrepareSetValue) -> any:
3030
pass # OK
3131
elif typeOfOptionValue == str:
3232
pass # OK
33+
elif typeOfOptionValue == bool:
34+
pass # OK
3335
else:
3436
BugCheckError.UnknownOptionValueType(ctx.OptionName, typeOfOptionValue)
3537

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# //////////////////////////////////////////////////////////////////////////////
2+
# Postgres Pro. PostgreSQL Configuration Python Library.
3+
4+
from __future__ import annotations
5+
6+
from ....handlers import OptionHandlerToWrite
7+
from ....handlers import OptionHandlerCtxToWrite
8+
9+
from ....raise_error import RaiseError
10+
11+
# //////////////////////////////////////////////////////////////////////////////
12+
# OptionHandlerToWrite__Std__Bool
13+
14+
15+
class OptionHandlerToWrite__Std__Bool(OptionHandlerToWrite):
16+
def __init__(self):
17+
super().__init__()
18+
19+
# interface ----------------------------------------------------------
20+
def OptionValueToString(self, ctx: OptionHandlerCtxToWrite) -> str:
21+
assert type(ctx) == OptionHandlerCtxToWrite
22+
assert type(ctx.OptionName) == str
23+
assert ctx.OptionValue is not None
24+
25+
typeOfValue = type(ctx.OptionValue)
26+
27+
if typeOfValue == bool:
28+
typedValue = bool(ctx.OptionValue)
29+
else:
30+
RaiseError.BadOptionValueItemType(ctx.OptionName, typeOfValue, bool)
31+
32+
assert type(typedValue) == bool
33+
34+
if typedValue:
35+
result = "on"
36+
else:
37+
result = "off"
38+
39+
return result
40+
41+
42+
# //////////////////////////////////////////////////////////////////////////////

src/core/option/handlers/write/option_handler_to_write__std__generic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from .option_handler_to_write__std__int import OptionHandlerToWrite__Std__Int
77
from .option_handler_to_write__std__str import OptionHandlerToWrite__Std__Str
8+
from .option_handler_to_write__std__bool import OptionHandlerToWrite__Std__Bool
89

910
from ....handlers import OptionHandlerToWrite
1011
from ....handlers import OptionHandlerCtxToWrite
@@ -20,6 +21,8 @@ class OptionHandlerToWrite__Std__Generic(OptionHandlerToWrite):
2021
sm_Handler_For_Int = OptionHandlerToWrite__Std__Int()
2122

2223
sm_Handler_For_Str = OptionHandlerToWrite__Std__Str()
24+
25+
sm_Handler_For_Bool = OptionHandlerToWrite__Std__Bool()
2326
# fmt on
2427

2528
# --------------------------------------------------------------------
@@ -39,6 +42,9 @@ def OptionValueToString(self, ctx: OptionHandlerCtxToWrite) -> str:
3942
if typeOfOptionValue == str:
4043
return __class__.sm_Handler_For_Str.OptionValueToString(ctx)
4144

45+
if typeOfOptionValue == bool:
46+
return __class__.sm_Handler_For_Bool.OptionValueToString(ctx)
47+
4248
BugCheckError.UnknownOptionValueType(ctx.OptionName, typeOfOptionValue)
4349

4450

src/implementation/v00/configuration_std.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
from ...core.option.handlers.prepare_set_value.option_handler_to_prepare_set_value__std__str \
2525
import OptionHandlerToPrepareSetValue__Std__Str
2626

27+
from ...core.option.handlers.prepare_set_value.option_handler_to_prepare_set_value__std__bool \
28+
import OptionHandlerToPrepareSetValue__Std__Bool
29+
2730
from ...core.option.handlers.prepare_set_value.option_handler_to_prepare_set_value__std__unique_str_list \
2831
import OptionHandlerToPrepareSetValue__Std__UniqueStrList
2932

@@ -41,6 +44,9 @@
4144
from ...core.option.handlers.prepare_get_value.option_handler_to_prepare_get_value__std__str \
4245
import OptionHandlerToPrepareGetValue__Std__Str
4346

47+
from ...core.option.handlers.prepare_get_value.option_handler_to_prepare_get_value__std__bool \
48+
import OptionHandlerToPrepareGetValue__Std__Bool
49+
4450
# -------------
4551
from ...core.option.handlers.prepare_get_value.option_handler_to_prepare_get_value__std__unique_str_list \
4652
import OptionHandlerToPrepareGetValue__Std__UniqueStrList
@@ -74,6 +80,9 @@
7480
from ...core.option.handlers.write.option_handler_to_write__std__str \
7581
import OptionHandlerToWrite__Std__Str
7682

83+
from ...core.option.handlers.write.option_handler_to_write__std__bool \
84+
import OptionHandlerToWrite__Std__Bool
85+
7786
from ...core.option.handlers.write.option_handler_to_write__std__unique_str_list \
7887
import OptionHandlerToWrite__Std__UniqueStrList
7988
# fmt: on
@@ -99,6 +108,9 @@ class PostgresConfiguration_Std(PostgresConfiguration_Base):
99108
sm_SingleInstance__OptionHandlerToPrepareSetValue__Std__Str = \
100109
OptionHandlerToPrepareSetValue__Std__Str()
101110

111+
sm_SingleInstance__OptionHandlerToPrepareSetValue__Std__Bool = \
112+
OptionHandlerToPrepareSetValue__Std__Bool()
113+
102114
sm_SingleInstance__OptionHandlerToPrepareSetValue__Std__UniqueStrList = \
103115
OptionHandlerToPrepareSetValue__Std__UniqueStrList()
104116

@@ -116,6 +128,9 @@ class PostgresConfiguration_Std(PostgresConfiguration_Base):
116128
sm_SingleInstance__OptionHandlerToPrepareGetValue__Std__Str = \
117129
OptionHandlerToPrepareGetValue__Std__Str()
118130

131+
sm_SingleInstance__OptionHandlerToPrepareGetValue__Std__Bool = \
132+
OptionHandlerToPrepareGetValue__Std__Bool()
133+
119134
sm_SingleInstance__OptionHandlerToPrepareGetValue__Std__UniqueStrList = \
120135
OptionHandlerToPrepareGetValue__Std__UniqueStrList()
121136

@@ -148,6 +163,9 @@ class PostgresConfiguration_Std(PostgresConfiguration_Base):
148163
sm_SingleInstance__OptionHandlerToWrite__Std__Str = \
149164
OptionHandlerToWrite__Std__Str()
150165

166+
sm_SingleInstance__OptionHandlerToWrite__Std__Bool = \
167+
OptionHandlerToWrite__Std__Bool()
168+
151169
sm_SingleInstance__OptionHandlerToWrite__Std__UniqueStrList = \
152170
OptionHandlerToWrite__Std__UniqueStrList()
153171
# fmt: on
@@ -245,6 +263,18 @@ def __init__(
245263
sm_SingleInstance__OptionHandlerToWrite__Std__Str,
246264
)
247265

266+
sm_OptionHandlers__Std__Bool = \
267+
tagOptionHandlers(
268+
sm_SingleInstance__OptionHandlerToPrepareSetValue__Std__Bool,
269+
sm_SingleInstance__OptionHandlerToPrepareGetValue__Std__Bool,
270+
None,
271+
sm_SingleInstance__OptionHandlerToSetValue__Std__Simple,
272+
sm_SingleInstance__OptionHandlerToGetValue__Std__Simple,
273+
sm_SingleInstance__OptionHandlerToAddOption__Std,
274+
None,
275+
sm_SingleInstance__OptionHandlerToWrite__Std__Bool,
276+
)
277+
248278
sm_OptionHandlers__Std__UniqueStrList = \
249279
tagOptionHandlers(
250280
sm_SingleInstance__OptionHandlerToPrepareSetValue__Std__UniqueStrList,
@@ -265,6 +295,7 @@ def __init__(
265295
"port": sm_OptionHandlers__Std__Int,
266296
"listen_addresses": sm_OptionHandlers__Std__Str,
267297
"shared_preload_libraries": sm_OptionHandlers__Std__UniqueStrList,
298+
"restart_after_crash": sm_OptionHandlers__Std__Bool,
268299

269300
# PROXIMA --------------------------------------------------------
270301
"proxima.port": sm_OptionHandlers__Std__Int,

0 commit comments

Comments
 (0)