s4-tests: register new unit tests
[Samba/ekacnet.git] / source4 / scripting / python / samba / shares.py
blob89a312e855174506bf31561b5eaef5e8451c83d1
1 #!/usr/bin/python
3 # Unix SMB/CIFS implementation.
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """Share management."""
23 # TODO: Rather than accessing Loadparm directly here, we should really
24 # have bindings to the param/shares.c and use those.
27 class SharesContainer(object):
28 """A shares container."""
30 def __init__(self, lp):
31 self._lp = lp
33 def __getitem__(self, name):
34 if name == "global":
35 # [global] is not a share
36 raise KeyError
37 return Share(self._lp[name])
39 def __len__(self):
40 if "global" in self._lp:
41 return len(self._lp)-1
42 return len(self._lp)
44 def keys(self):
45 return [name for name in self._lp.services() if name != "global"]
47 def __iter__(self):
48 return iter(self.keys())
51 class Share(object):
52 """A file share."""
54 def __init__(self, service):
55 self._service = service
57 def __getitem__(self, name):
58 return self._service[name]
60 def __setitem__(self, name, value):
61 self._service[name] = value