[SCM] Samba Shared Repository - branch master updated -
release-4-0-0alpha7-2333-g308de54
Jelmer Vernooij
jelmer at samba.org
Tue Jun 16 00:29:01 GMT 2009
The branch, master has been updated
via 308de544f4dd1e23197d3b6d3be85cef1f5f9ded (commit)
via f7ada51c29a517e841843c2a869ac9d16c7057d4 (commit)
from 537aa4cf51def606de6c73c429f97d12c76333b1 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 308de544f4dd1e23197d3b6d3be85cef1f5f9ded
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Tue Jun 16 02:24:43 2009 +0200
python: Provide way to iterate over available shares.
commit f7ada51c29a517e841843c2a869ac9d16c7057d4
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Tue Jun 16 02:05:18 2009 +0200
python: Add API for accessing available shares.
-----------------------------------------------------------------------
Summary of changes:
source4/bin/python/samba/tests/shares.py | 74 ++++++++++++++++++++++++++++++
source4/param/pyparam.c | 16 ++++++
source4/scripting/python/samba/shares.py | 61 ++++++++++++++++++++++++
source4/selftest/tests.sh | 1 +
4 files changed, 152 insertions(+), 0 deletions(-)
create mode 100644 source4/bin/python/samba/tests/shares.py
create mode 100644 source4/scripting/python/samba/shares.py
Changeset truncated at 500 lines:
diff --git a/source4/bin/python/samba/tests/shares.py b/source4/bin/python/samba/tests/shares.py
new file mode 100644
index 0000000..9130c36
--- /dev/null
+++ b/source4/bin/python/samba/tests/shares.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+
+# Unix SMB/CIFS implementation. Tests for shares
+# Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2009
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+from samba.shares import SharesContainer
+from unittest import TestCase
+
+
+class MockService(object):
+
+ def __init__(self, data):
+ self.data = data
+
+ def __getitem__(self, name):
+ return self.data[name]
+
+
+class MockLoadParm(object):
+
+ def __init__(self, data):
+ self.data = data
+
+ def __getitem__(self, name):
+ return MockService(self.data[name])
+
+ def __contains__(self, name):
+ return name in self.data
+
+ def __len__(self):
+ return len(self.data)
+
+ def services(self):
+ return self.data.keys()
+
+
+class ShareTests(TestCase):
+
+ def _get_shares(self, conf):
+ return SharesContainer(MockLoadParm(conf))
+
+ def test_len_no_global(self):
+ shares = self._get_shares({})
+ self.assertEquals(0, len(shares))
+
+ def test_iter(self):
+ self.assertEquals([], list(self._get_shares({})))
+ self.assertEquals([], list(self._get_shares({"global":{}})))
+ self.assertEquals(["bla"], list(self._get_shares({"global":{}, "bla":{}})))
+
+ def test_len(self):
+ shares = self._get_shares({"global": {}})
+ self.assertEquals(0, len(shares))
+
+ def test_getitem_nonexistant(self):
+ shares = self._get_shares({"global": {}})
+ self.assertRaises(KeyError, shares.__getitem__, "bla")
+
+ def test_getitem_global(self):
+ shares = self._get_shares({"global": {}})
+ self.assertRaises(KeyError, shares.__getitem__, "global")
diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c
index d8dabe3..4f6e2ff 100644
--- a/source4/param/pyparam.c
+++ b/source4/param/pyparam.c
@@ -232,6 +232,20 @@ static PyObject *py_lp_ctx_private_path(py_talloc_Object *self, PyObject *args)
return ret;
}
+static PyObject *py_lp_ctx_services(py_talloc_Object *self)
+{
+ struct loadparm_context *lp_ctx = PyLoadparmContext_AsLoadparmContext(self);
+ const char **names;
+ PyObject *ret;
+ int i;
+ names = lp_server_services(lp_ctx);
+ ret = PyList_New(str_list_length(names));
+ for (i = 0; names[i]; i++) {
+ PyList_SetItem(ret, i, PyString_FromString(names[i]));
+ }
+ return ret;
+}
+
static PyMethodDef py_lp_ctx_methods[] = {
{ "load", (PyCFunction)py_lp_ctx_load, METH_VARARGS,
"S.load(filename) -> None\n"
@@ -253,6 +267,8 @@ static PyMethodDef py_lp_ctx_methods[] = {
"Change a parameter." },
{ "private_path", (PyCFunction)py_lp_ctx_private_path, METH_VARARGS,
"S.private_path(name) -> path\n" },
+ { "services", (PyCFunction)py_lp_ctx_services, METH_NOARGS,
+ "S.services() -> list" },
{ NULL }
};
diff --git a/source4/scripting/python/samba/shares.py b/source4/scripting/python/samba/shares.py
new file mode 100644
index 0000000..89a312e
--- /dev/null
+++ b/source4/scripting/python/samba/shares.py
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2009
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+"""Share management."""
+
+
+# TODO: Rather than accessing Loadparm directly here, we should really
+# have bindings to the param/shares.c and use those.
+
+
+class SharesContainer(object):
+ """A shares container."""
+
+ def __init__(self, lp):
+ self._lp = lp
+
+ def __getitem__(self, name):
+ if name == "global":
+ # [global] is not a share
+ raise KeyError
+ return Share(self._lp[name])
+
+ def __len__(self):
+ if "global" in self._lp:
+ return len(self._lp)-1
+ return len(self._lp)
+
+ def keys(self):
+ return [name for name in self._lp.services() if name != "global"]
+
+ def __iter__(self):
+ return iter(self.keys())
+
+
+class Share(object):
+ """A file share."""
+
+ def __init__(self, service):
+ self._service = service
+
+ def __getitem__(self, name):
+ return self._service[name]
+
+ def __setitem__(self, name, value):
+ self._service[name] = value
diff --git a/source4/selftest/tests.sh b/source4/selftest/tests.sh
index 04f8d2b..56462ac 100755
--- a/source4/selftest/tests.sh
+++ b/source4/selftest/tests.sh
@@ -418,6 +418,7 @@ plantest "samr.python" dc:local $SUBUNITRUN samba.tests.dcerpc.sam
plantest "dcerpc.bare.python" dc:local $SUBUNITRUN samba.tests.dcerpc.bare
plantest "unixinfo.python" dc:local $SUBUNITRUN samba.tests.dcerpc.unix
plantest "samdb.python" none $SUBUNITRUN samba.tests.samdb
+plantest "shares.python" none $SUBUNITRUN samba.tests.shares
plantest "messaging.python" none PYTHONPATH="$PYTHONPATH:$samba4srcdir/lib/messaging/tests" $SUBUNITRUN bindings
plantest "samba3sam.python" none PYTHONPATH="$PYTHONPATH:$samba4srcdir/dsdb/samdb/ldb_modules/tests" $SUBUNITRUN samba3sam
plantest "subunit.python" none $SUBUNITRUN subunit
--
Samba Shared Repository
More information about the samba-cvs
mailing list