From: Rob van der Linde Date: Thu, 8 Feb 2024 10:33:09 +0000 (+1300) Subject: netcmd: support hyphens in top-level commands and convert to underscore X-Git-Tag: tdb-1.4.11~1774 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de8b61cbbe38702924d6c59a15eb264f679edf84;p=thirdparty%2Fsamba.git netcmd: support hyphens in top-level commands and convert to underscore Hyphens in python modules are invalid and makes them only importable by importlib, which makes them harder to import in tests. Signed-off-by: Rob van der Linde Reviewed-by: Andrew Bartlett Reviewed-by: Jo Sutton --- diff --git a/python/samba/netcmd/main.py b/python/samba/netcmd/main.py index f1a0afbecf6..c1e89412bd4 100644 --- a/python/samba/netcmd/main.py +++ b/python/samba/netcmd/main.py @@ -31,10 +31,11 @@ class cache_loader(dict): def __getitem__(self, attr): item = dict.__getitem__(self, attr) if item is None: + cmd = 'cmd_%s' % attr.replace('-', '_') package = 'nettime' if attr == 'time' else attr + package = package.replace('-', '_') self[attr] = getattr(__import__('samba.netcmd.%s' % package, - fromlist=['cmd_%s' % attr]), - 'cmd_%s' % attr)() + fromlist=[cmd]), cmd)() return dict.__getitem__(self, attr) def get(self, attr, default=None):