Skip to content

Commit 2ddecc4

Browse files
author
Dmitry Kovalenko
committed
Merge branch 'D20250817_001--cfg_os_ops' into 'master'
Usage of "os" is replaced with ConfigurationOsOps See merge request d.kovalenko/testgres.postgres_configuration!1
2 parents 1a11fd0 + 17a8446 commit 2ddecc4

File tree

11 files changed

+422
-96
lines changed

11 files changed

+422
-96
lines changed

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
"testgres.postgres_configuration.core.option.handlers.set_value",
3636
"testgres.postgres_configuration.core.option.handlers.set_value_item",
3737
"testgres.postgres_configuration.core.option.handlers.write",
38+
"testgres.postgres_configuration.os",
39+
"testgres.postgres_configuration.os.abstract",
40+
"testgres.postgres_configuration.os.local",
3841
],
3942
package_dir={"testgres.postgres_configuration": "src"},
4043
description="PostgreSQL Configuration Python Library",

src/core/controller_utils.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
from .model import FileData as PgCfgModel__FileData
1515
# fmt: on
1616

17+
from ..os.abstract.configuration_os_ops import ConfigurationOsOps
18+
1719
from .raise_error import RaiseError
1820
from .bugcheck_error import BugCheckError
1921
from .helpers import Helpers
2022

21-
import os
2223
import typing
2324

2425
# //////////////////////////////////////////////////////////////////////////////
@@ -350,12 +351,13 @@ def Cfg__CreateAndAddTopLevelFile__AUTO(
350351
assert type(cfgData) == PgCfgModel__ConfigurationData
351352
assert type(cfgData.m_Files) == list
352353
assert type(cfgData.m_AllFilesByName) == dict
354+
assert isinstance(cfgData.OsOps, ConfigurationOsOps)
353355
assert type(file_name) == str
354356
assert file_name != ""
355-
assert os.path.basename(file_name) == file_name
357+
assert cfgData.OsOps.Path_BaseName(file_name) == file_name
356358

357-
newFilePath = os.path.join(cfgData.m_DataDir, file_name)
358-
newFilePath = os.path.normpath(newFilePath)
359+
newFilePath = cfgData.OsOps.Path_Join(cfgData.m_DataDir, file_name)
360+
newFilePath = cfgData.OsOps.Path_NormPath(newFilePath)
359361

360362
assert type(newFilePath) == str
361363
assert newFilePath != ""
@@ -370,9 +372,10 @@ def Cfg__CreateAndAddTopLevelFile__USER(
370372
assert type(cfgData.m_Files) == list
371373
assert type(cfgData.m_AllFilesByName) == dict
372374
assert type(path) == str
375+
assert isinstance(cfgData.OsOps, ConfigurationOsOps)
373376
assert path != ""
374377

375-
newFilePath = Helpers.NormalizeFilePath(cfgData.m_DataDir, path)
378+
newFilePath = Helpers.NormalizeFilePath(cfgData.OsOps, cfgData.m_DataDir, path)
376379

377380
assert type(newFilePath) == str
378381
assert newFilePath != ""
@@ -395,11 +398,12 @@ def Cfg__GetOrCreateFile__USER(
395398
assert type(cfgData) == PgCfgModel__ConfigurationData
396399
assert type(cfgData.m_Files) == list
397400
assert type(cfgData.m_AllFilesByName) == dict
401+
assert isinstance(cfgData.OsOps, ConfigurationOsOps)
398402
assert type(baseFolder) == str
399403
assert type(path) == str
400404
assert path != ""
401405

402-
newFilePath = Helpers.NormalizeFilePath(baseFolder, path)
406+
newFilePath = Helpers.NormalizeFilePath(cfgData.OsOps, baseFolder, path)
403407

404408
assert type(newFilePath) == str
405409
assert newFilePath != ""
@@ -492,13 +496,14 @@ def Helper__RegFileInCfgData(
492496
assert cfgData is not None
493497
assert fileData is not None
494498
assert type(cfgData) == PgCfgModel__ConfigurationData
499+
assert isinstance(cfgData.OsOps, ConfigurationOsOps)
495500
assert type(fileData) == PgCfgModel__FileData
496501
assert type(fileData.m_Path) == str
497502
assert fileData.m_Path != ""
498503

499504
assert fileData.IsAlive()
500505

501-
fileName = os.path.basename(fileData.m_Path)
506+
fileName = cfgData.OsOps.Path_BaseName(fileData.m_Path)
502507
assert type(fileName) == str
503508
assert fileName != ""
504509

@@ -513,12 +518,13 @@ def Helper__UnRegFileFromCfgData(
513518
assert cfgData is not None
514519
assert fileData is not None
515520
assert type(cfgData) == PgCfgModel__ConfigurationData
521+
assert isinstance(cfgData.OsOps, ConfigurationOsOps)
516522
assert type(fileData) == PgCfgModel__FileData
517523
assert fileData.m_Path != ""
518524

519525
assert fileData.IsAlive()
520526

521-
fileName = os.path.basename(fileData.m_Path)
527+
fileName = cfgData.OsOps.Path_BaseName(fileData.m_Path)
522528
assert type(fileName) == str
523529
assert fileName != ""
524530

src/core/helpers.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from .model import OptionData
55
from .bugcheck_error import BugCheckError
66

7+
from ..os.abstract.configuration_os_ops import ConfigurationOsOps
8+
79
import typing
8-
import os
910

1011
# //////////////////////////////////////////////////////////////////////////////
1112

@@ -63,24 +64,30 @@ def DoesContainerContainsValue__NotNullAndExact(
6364
return False
6465

6566
# --------------------------------------------------------------------
66-
def NormalizeFilePath(baseFolder: str, filePath: str) -> str:
67+
def NormalizeFilePath(
68+
cfgOsOps: ConfigurationOsOps,
69+
baseFolder: str,
70+
filePath: str
71+
) -> str:
72+
assert cfgOsOps is not None
73+
assert isinstance(cfgOsOps, ConfigurationOsOps)
6774
assert type(baseFolder) == str
6875
assert type(filePath) == str
6976
assert filePath != ""
7077

7178
newFilePath = None
7279

73-
if os.path.isabs(filePath):
74-
newFilePath = os.path.normpath(filePath)
80+
if cfgOsOps.Path_IsAbs(filePath):
81+
newFilePath = cfgOsOps.Path_NormPath(filePath)
7582
else:
76-
newFilePath = os.path.join(baseFolder, filePath)
77-
newFilePath = os.path.normpath(newFilePath)
83+
newFilePath = cfgOsOps.Path_Join(baseFolder, filePath)
84+
newFilePath = cfgOsOps.Path_NormPath(newFilePath)
7885

7986
assert type(newFilePath) == str
8087
assert newFilePath != ""
8188

82-
newFilePath = os.path.abspath(newFilePath)
83-
newFilePath = os.path.normcase(newFilePath)
89+
newFilePath = cfgOsOps.Path_AbsPath(newFilePath)
90+
newFilePath = cfgOsOps.Path_NormCase(newFilePath)
8491

8592
return newFilePath
8693

src/core/model.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
from .raise_error import RaiseError
77

8+
from ..os.abstract.configuration_os_ops import ConfigurationOsOps
9+
810
import typing
9-
import os
1011
import enum
1112
import datetime
1213

@@ -213,9 +214,9 @@ class FileData(ObjectData):
213214
def __init__(self, parent: ConfigurationData, path: str):
214215
assert type(parent) == ConfigurationData
215216
assert type(path) == str
216-
assert os.path.isabs(path)
217-
assert os.path.normpath(path) == path
218-
assert os.path.normcase(path) == path
217+
assert parent.OsOps.Path_IsAbs(path)
218+
assert parent.OsOps.Path_NormPath(path) == path
219+
assert parent.OsOps.Path_NormCase(path) == path
219220

220221
super().__init__()
221222

@@ -251,24 +252,35 @@ def IsAlive(self) -> bool:
251252

252253
class ConfigurationData(ObjectData):
253254
m_DataDir: str
255+
m_OsOps: ConfigurationOsOps
256+
254257
m_Files: list[FileData]
255258

256259
m_AllOptionsByName: dict[str, typing.Union[OptionData, list[OptionData]]]
257260
m_AllFilesByName: dict[str, typing.Union[FileData, list[FileData]]]
258261

259262
# --------------------------------------------------------------------
260-
def __init__(self, data_dir: str):
263+
def __init__(self, data_dir: str, osOps: ConfigurationOsOps):
261264
assert type(data_dir) == str
265+
assert isinstance(osOps, ConfigurationOsOps)
262266

263267
super().__init__()
264268

265269
self.m_DataDir = data_dir
270+
self.m_OsOps = osOps
271+
266272
self.m_Files = list[FileData]()
267273
self.m_AllOptionsByName = dict[
268274
str, typing.Union[OptionData, list[OptionData]]
269275
]()
270276
self.m_AllFilesByName = dict[str, typing.Union[FileData, list[FileData]]]()
271277

278+
# Own interface ------------------------------------------------------
279+
@property
280+
def OsOps(self) -> ConfigurationOsOps:
281+
assert isinstance(self.m_OsOps, ConfigurationOsOps)
282+
return self.m_OsOps
283+
272284
# Object interface ---------------------------------------------------
273285
def get_Parent(self) -> FileData:
274286
return None

0 commit comments

Comments
 (0)