Patch for TypeError in shares.py
Ricardo Jorge
rvelhote at gmail.com
Sun Feb 7 10:35:17 MST 2010
Hi everyone.
When trying to obtain the length of a SharesContainer object, which
has __len__ defined, the script would exit with the error "Fix for
TypeError: argument of type 'LoadParm' is not iterable"
It can be fixed by calling the services() method (which is partof
LoadParm) which returns a List item.
==================
Test
==================
#!/usr/bin/env python
import param, shares
samba_lp = param.LoadParm()
samba_lp.load_default()
container = shares.SharesContainer(samba_lp)
print len(container)
Result: Fix for TypeError: argument of type 'LoadParm' is not iterable
=================
Workarounds
=================
You can use.
1. len(samba_lp)
Number 1, will also return the global section so you shoud use
len(samba_lp) - 1
2. len(container.keys())
==================
Patch
==================
diff --git a/source4/scripting/python/samba/shares.py
b/source4/scripting/python/samba/shares.py
index 89a312e..b6ddeb3 100644
--- a/source4/scripting/python/samba/shares.py
+++ b/source4/scripting/python/samba/shares.py
@@ -37,7 +37,7 @@ class SharesContainer(object):
return Share(self._lp[name])
def __len__(self):
- if "global" in self._lp:
+ if "global" in self._lp.services():
return len(self._lp)-1
return len(self._lp)
Best Regards.
Ric
More information about the samba-technical
mailing list