]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
netcmd: support hyphens in top-level commands and convert to underscore
authorRob van der Linde <rob@catalyst.net.nz>
Thu, 8 Feb 2024 10:33:09 +0000 (23:33 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 16 Feb 2024 02:41:36 +0000 (02:41 +0000)
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 <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
python/samba/netcmd/main.py

index f1a0afbecf6db56806ad83c1798ff19aaa8ec171..c1e89412bd41545a07c129daac9208b7c352afda 100644 (file)
@@ -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):