mirror of
https://github.com/samba-team/samba.git
synced 2025-12-17 04:23:50 +03:00
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 <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
This commit is contained in:
committed by
Andrew Bartlett
parent
2a95f83c5c
commit
de8b61cbbe
@@ -31,10 +31,11 @@ class cache_loader(dict):
|
|||||||
def __getitem__(self, attr):
|
def __getitem__(self, attr):
|
||||||
item = dict.__getitem__(self, attr)
|
item = dict.__getitem__(self, attr)
|
||||||
if item is None:
|
if item is None:
|
||||||
|
cmd = 'cmd_%s' % attr.replace('-', '_')
|
||||||
package = 'nettime' if attr == 'time' else attr
|
package = 'nettime' if attr == 'time' else attr
|
||||||
|
package = package.replace('-', '_')
|
||||||
self[attr] = getattr(__import__('samba.netcmd.%s' % package,
|
self[attr] = getattr(__import__('samba.netcmd.%s' % package,
|
||||||
fromlist=['cmd_%s' % attr]),
|
fromlist=[cmd]), cmd)()
|
||||||
'cmd_%s' % attr)()
|
|
||||||
return dict.__getitem__(self, attr)
|
return dict.__getitem__(self, attr)
|
||||||
|
|
||||||
def get(self, attr, default=None):
|
def get(self, attr, default=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user