summaryrefslogtreecommitdiffstats
path: root/base/all/root/scripts/cluster_configure/plugins/share.py
blob: ae328f8d88ee79740cbb250dd9947b8f180025f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Configure clustered Samba nodes

# Module for handling shares.

# Copyright (C) Martin Schwenke 2010

# 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/>.

import util

_share_prefix = "share"

def names(config):
    """Given a config, return the names of all shares."""

    return util.names(config, _share_prefix)

def retrieve(config):
    """Given a config, retrieve all the information about shares.  The
    result is a dictionary with share names (minus "share:") as keys
    where each value is a dictionary for the section."""

    return util.retrieve(config, _share_prefix)

def format(config, package, format, items):
    """Given a config object, return the formatted shares.  Use format
    string and apply it to the share fields in the order specified in
    items.  Argument package is ignored but is present for consistency."""

    shares = retrieve(config)

    out = []

    for e in shares.keys():
        # Add name.
        shares[e]["name"] = e

        def get_val(k):
            ret = shares[e].get(k)
            if ret is None:
                raise ValueError("No option '%s'" % k)
            return ret

        out.append(format % tuple(map(get_val, items)))

    return "".join(out)