89a312e855174506bf31561b5eaef5e8451c83d1
[samba.git] / source4 / scripting / python / samba / shares.py
1 #!/usr/bin/python
2
3 # Unix SMB/CIFS implementation.
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009
5 #
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.
10 #   
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.
15 #   
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/>.
18 #
19
20 """Share management."""
21
22
23 # TODO: Rather than accessing Loadparm directly here, we should really 
24 # have bindings to the param/shares.c and use those.
25
26
27 class SharesContainer(object):
28     """A shares container."""
29
30     def __init__(self, lp):
31         self._lp = lp
32
33     def __getitem__(self, name):
34         if name == "global":
35             # [global] is not a share
36             raise KeyError
37         return Share(self._lp[name])
38
39     def __len__(self):
40         if "global" in self._lp:
41             return len(self._lp)-1
42         return len(self._lp)
43
44     def keys(self):
45         return [name for name in self._lp.services() if name != "global"]
46
47     def __iter__(self):
48         return iter(self.keys())
49
50
51 class Share(object):
52     """A file share."""
53
54     def __init__(self, service):
55         self._service = service
56
57     def __getitem__(self, name):
58         return self._service[name]
59
60     def __setitem__(self, name, value):
61         self._service[name] = value