Skip to content

Commit 6e526bc

Browse files
sambacc: add equality comparison to InstanceConfig type
Signed-off-by: John Mulligan <[email protected]>
1 parent 4c794ff commit 6e526bc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

sambacc/config.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ def domain_groups(self) -> typing.Iterable[DomainGroupEntry]:
202202
for n, entry in enumerate(dgroups):
203203
yield DomainGroupEntry(self, entry, n)
204204

205+
def __eq__(self, other: typing.Any) -> bool:
206+
if isinstance(other, InstanceConfig) and self.iconfig == other.iconfig:
207+
self_shares = _shares_data(self.gconfig, self.iconfig)
208+
other_shares = _shares_data(other.gconfig, other.iconfig)
209+
self_globals = _globals_data(self.gconfig, self.iconfig)
210+
other_globals = _globals_data(other.gconfig, other.iconfig)
211+
return (
212+
self_shares == other_shares and self_globals == other_globals
213+
)
214+
return False
215+
205216

206217
class CTDBSambaConfig:
207218
def global_options(self) -> typing.Iterable[typing.Tuple[str, str]]:
@@ -341,3 +352,19 @@ def __init__(self, iconf: InstanceConfig, urec: dict, num: int):
341352

342353
class DomainGroupEntry(GroupEntry):
343354
pass
355+
356+
357+
def _shares_data(gconfig: GlobalConfig, iconfig: dict) -> list:
358+
try:
359+
shares = iconfig["shares"]
360+
except KeyError:
361+
return []
362+
return [gconfig.data["shares"][n] for n in shares]
363+
364+
365+
def _globals_data(gconfig: GlobalConfig, iconfig: dict) -> list:
366+
try:
367+
gnames = iconfig["globals"]
368+
except KeyError:
369+
return []
370+
return [gconfig.data["globals"][n] for n in gnames]

0 commit comments

Comments
 (0)