summaryrefslogtreecommitdiff
path: root/reconfigure/items/samba.py
blob: 079da5ef77edc68f57131eb7146f6f88ebdc343c (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
58
59
from reconfigure.nodes import Node, PropertyNode
from reconfigure.items.bound import BoundData
from util import yn_getter, yn_setter


class SambaData (BoundData):
    pass


class GlobalData (BoundData):
    pass


class ShareData (BoundData):
    fields = [
        'comment', 'path', 'guest ok', 'browseable', 'create mask', 'directory mask', 'read only',
        'follow symlinks', 'wide links',
    ]
    defaults = [
        '', '', 'no', 'yes', '0744', '0755', 'yes',
        'yes', 'no',
    ]

    def template(self):
        return Node(
            'share',
            *[PropertyNode(x, y) for x, y in zip(ShareData.fields, ShareData.defaults)]
        )


SambaData.bind_child('global', lambda x: x.get('global'), item_class=GlobalData)
SambaData.bind_collection('shares', selector=lambda x: x.name != 'global', item_class=ShareData)


GlobalData.bind_property('workgroup', 'workgroup', default='')
GlobalData.bind_property('server string', 'server_string', default='')
GlobalData.bind_property('interfaces', 'interfaces', default='')
GlobalData.bind_property(
    'bind interfaces only', 'bind_interfaces_only', default=True,
    getter=yn_getter, setter=yn_setter)
GlobalData.bind_property('log file', 'log_file', default='')
GlobalData.bind_property('security', 'security', default='user')

ShareData.bind_name('name')
ShareData.bind_property('path', 'path', default='')
ShareData.bind_property('comment', 'comment', default='')
ShareData.bind_property('create mask', 'create_mask', default='0744')
ShareData.bind_property('directory mask', 'directory_mask', default='0755')

for x, y in [
    ('guest ok', False),
    ('browseable', True),
    ('read only', True),
    ('follow symlinks', True),
    ('wide links', False),
]:
    ShareData.bind_property(
        x, x.replace(' ', '_'), default=y,
        getter=yn_getter, setter=yn_setter)