s3/torture: use stack buffer for rbtree loop
[Samba.git] / python / samba / hostconfig.py
blob970f4892b913470b563d8047494b2c361ff36559
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Local host configuration."""
19 from __future__ import absolute_import
20 from .samdb import SamDB
23 class Hostconfig(object):
24 """Aggregate object that contains all information about the configuration
25 of a Samba host."""
27 def __init__(self, lp):
28 self.lp = lp
30 def get_shares(self):
31 return SharesContainer(self.lp)
33 def get_samdb(self, session_info, credentials):
34 """Access the SamDB host.
36 :param session_info: Session info to use
37 :param credentials: Credentials to access the SamDB with
38 """
39 return SamDB(url=self.lp.samdb_url(),
40 session_info=session_info, credentials=credentials,
41 lp=self.lp)
44 # TODO: Rather than accessing Loadparm directly here, we should really
45 # have bindings to the param/shares.c and use those.
48 class SharesContainer(object):
49 """A shares container."""
51 def __init__(self, lp):
52 self._lp = lp
54 def __getitem__(self, name):
55 if name == "global":
56 # [global] is not a share
57 raise KeyError
58 return Share(self._lp[name])
60 def __len__(self):
61 if "global" in self._lp.services():
62 return len(self._lp) - 1
63 return len(self._lp)
65 def keys(self):
66 return [name for name in self._lp.services() if name != "global"]
68 def __iter__(self):
69 return iter(self.keys())
72 class Share(object):
73 """A file share."""
75 def __init__(self, service):
76 self._service = service
78 def __getitem__(self, name):
79 return self._service[name]
81 def __setitem__(self, name, value):
82 self._service[name] = value