コード例 #1
0
    def test_bind_collection(self):
        class TestBoundData(BoundData):
            pass

        class TestChildData(BoundData):
            def template(self):
                return Node('', children=[PropertyNode('value', None)])

        TestBoundData.bind_collection('items',
                                      item_class=TestChildData,
                                      selector=lambda x: x.name != 'test')
        TestChildData.bind_property('value', 'value')
        n = Node('name',
                 children=[
                     Node('1', children=[PropertyNode('value', 1)]),
                     Node('2', children=[PropertyNode('value', 2)]),
                     Node('test', children=[PropertyNode('value', 3)]),
                     Node('3', children=[PropertyNode('value', 3)]),
                 ])

        d = TestBoundData(n)
        self.assertEqual(d.items[0].value, 1)
        self.assertEqual(len(d.items), 3)
        c = TestChildData()
        c.value = 4
        d.items.append(c)
        self.assertEqual(len(d.items), 4)
        self.assertEqual(d.items[-1].value, 4)
コード例 #2
0
 def create_destination():
     return OptionData(
         Node(
             'option',
             Node('argument', PropertyNode('value', 'ACCEPT')),
             PropertyNode('negative', False),
             PropertyNode('name', 'j'),
         ))
コード例 #3
0
ファイル: resolv.py プロジェクト: egberts/python-reconfigure
 def template(self):
     return Node('line',
                 children=[
                     Node('token',
                          children=[PropertyNode('value', 'nameserver')]),
                     Node('token',
                          children=[PropertyNode('value', '8.8.8.8')]),
                 ])
コード例 #4
0
ファイル: ctdb.py プロジェクト: egberts/python-reconfigure
 def template(self):
     return Node('line',
                 children=[
                     Node('token',
                          children=[PropertyNode('value', '127.0.0.1')]),
                     Node('token', children=[PropertyNode('value',
                                                          'eth0')]),
                 ])
コード例 #5
0
 def create(template_id):
     t = OptionData.templates[template_id]
     return OptionData(
         Node(
             'option',
             *([Node('argument', PropertyNode('value', x))
                for x in t[1]] + [PropertyNode('negative', False)] +
               [PropertyNode('name', t[0])])))
コード例 #6
0
ファイル: squid.py プロジェクト: Cloudhedge/staticBuilds
 def template(self, name, *args):
     children = [PropertyNode('1', name)]
     index = 2
     for arg in args:
         children += [PropertyNode(str(index), arg)]
         index += 1
     return Node('line', PropertyNode('name', 'acl'),
                 Node('arguments', *children))
コード例 #7
0
ファイル: iptables.py プロジェクト: Cloudhedge/staticBuilds
 def template(self):
     return Node(
         'append',
         Node(
             'option',
             Node('argument', PropertyNode('value', 'ACCEPT')),
             PropertyNode('negative', False),
             PropertyNode('name', 'j'),
         ))
コード例 #8
0
ファイル: bound_tests.py プロジェクト: Eugeny/reconfigure
    def test_bind_property(self):
        class TestBoundData (BoundData):
            pass
        TestBoundData.bind_property('prop', 'dataprop', getter=lambda x: 'd' + x, setter=lambda x: x[1:])

        n = Node('name', children=[
                PropertyNode('prop', 'value')
            ])

        d = TestBoundData(n)

        self.assertEqual(d.dataprop, 'dvalue')
        d.dataprop = 'dnew'
        self.assertEqual(d.dataprop, 'dnew')
        self.assertEqual(n.get('prop').value, 'new')
コード例 #9
0
ファイル: bind9.py プロジェクト: egberts/python-reconfigure
 def template(self):
     return Node(
         'zone',
         PropertyNode('type', 'master'),
         PropertyNode('file', 'db.example.com'),
         parameter='"example.com"',
     )
コード例 #10
0
 def template(self):
     return Node(
         'unnamed',
         PropertyNode('configs', {}),
         PropertyNode('password', ''),
         PropertyNode('permissions', []),
     )
コード例 #11
0
    def test_bind_property(self):
        class TestBoundData(BoundData):
            pass

        TestBoundData.bind_property('prop',
                                    'dataprop',
                                    getter=lambda x: 'd' + x,
                                    setter=lambda x: x[1:])

        n = Node('name', children=[PropertyNode('prop', 'value')])

        d = TestBoundData(n)

        self.assertEqual(d.dataprop, 'dvalue')
        d.dataprop = 'dnew'
        self.assertEqual(d.dataprop, 'dnew')
        self.assertEqual(n.get('prop').value, 'new')
コード例 #12
0
 def template(self, **kwargs):
     return Node('normal_task',
                 children=[
                     PropertyNode('minute', '0'),
                     PropertyNode('hour', '0'),
                     PropertyNode('day_of_month', '1'),
                     PropertyNode('month', '1'),
                     PropertyNode('day_of_week', '1'),
                     PropertyNode('command', 'false')
                 ])
コード例 #13
0
ファイル: fstab.py プロジェクト: Cloudhedge/staticBuilds
 def template(self):
     return Node('line', children=[
         Node('token', children=[PropertyNode('value', 'none')]),
         Node('token', children=[PropertyNode('value', 'none')]),
         Node('token', children=[PropertyNode('value', 'auto')]),
         Node('token', children=[PropertyNode('value', 'none')]),
         Node('token', children=[PropertyNode('value', '0')]),
         Node('token', children=[PropertyNode('value', '0')]),
     ])
コード例 #14
0
ファイル: crontab_tests.py プロジェクト: tmaone/reconfigure
class CrontabParserTest(BaseParserTest):
    parser = CrontabParser()

    source = '\n'.join([
        '#comment line',
        '* * * * * date',
        '@reboot ls -al',
        '1 * 0 1 2 date -s',
        'NAME = TEST',
    ])
    parsed = RootNode(None,
                      children=[
                          Node('normal_task',
                               comment='comment line',
                               children=[
                                   PropertyNode('minute', '*'),
                                   PropertyNode('hour', '*'),
                                   PropertyNode('day_of_month', '*'),
                                   PropertyNode('month', '*'),
                                   PropertyNode('day_of_week', '*'),
                                   PropertyNode('command', 'date'),
                               ]),
                          Node('special_task',
                               children=[
                                   PropertyNode('special', '@reboot'),
                                   PropertyNode('command', 'ls -al'),
                               ]),
                          Node('normal_task',
                               children=[
                                   PropertyNode('minute', '1'),
                                   PropertyNode('hour', '*'),
                                   PropertyNode('day_of_month', '0'),
                                   PropertyNode('month', '1'),
                                   PropertyNode('day_of_week', '2'),
                                   PropertyNode('command', 'date -s'),
                               ]),
                          Node('env_setting',
                               children=[
                                   PropertyNode('name', 'NAME'),
                                   PropertyNode('value', 'TEST'),
                               ]),
                      ])
コード例 #15
0
ファイル: iptables.py プロジェクト: Cloudhedge/staticBuilds
 def template(self):
     return Node('custom')
コード例 #16
0
 def template(self, **kwargs):
     return Node('special_task',
                 children=[
                     PropertyNode('special', '@reboot'),
                     PropertyNode('command', 'false')
                 ])
コード例 #17
0
ファイル: iptables.py プロジェクト: Cloudhedge/staticBuilds
 def template(self):
     return Node(
         'CUSTOM',
         PropertyNode('default', '-'),
     )
コード例 #18
0
 def template(self):
     return Node('program:new',
         PropertyNode('command', 'false'),
     )
コード例 #19
0
 def template(self, **kwargs):
     return Node('env_setting',
                 children=[
                     PropertyNode('name', 'ENV_NAME'),
                     PropertyNode('value', 'ENV_VALUE')
                 ])
コード例 #20
0
    def parse(self, content):
        root = RootNode()
        lines = [l.strip() for l in content.splitlines() if l]
        comment = None
        for line in lines:
            if line.startswith('#'):
                comment = '\n'.join([comment, line]) if comment else line[1:]
                continue
            elif line.startswith('@'):
                special, command = line.split(' ', 1)
                node = Node('special_task', comment=comment)
                node.append(PropertyNode('special', special))
                node.append(PropertyNode('command', command))

            else:
                split_line = line.split(' ', 5)
                if len(split_line) <= 3 and '=' in line:
                    name, value = [n.strip() for n in line.split('=')]
                    if not name:
                        continue
                    node = Node('env_setting', comment=comment)
                    node.append(PropertyNode('name', name))
                    node.append(PropertyNode('value', value))
                elif len(split_line) == 6:
                    node = Node('normal_task', comment=comment)
                    node.append(PropertyNode('minute', split_line[0]))
                    node.append(PropertyNode('hour', split_line[1]))
                    node.append(PropertyNode('day_of_month', split_line[2]))
                    node.append(PropertyNode('month', split_line[3]))
                    node.append(PropertyNode('day_of_week', split_line[4]))
                    node.append(PropertyNode('command', split_line[5]))
                else:
                    continue
            root.append(node)
            comment = None
        root.comment = comment
        return root
コード例 #21
0
ファイル: supervisor.py プロジェクト: Cloudhedge/staticBuilds
 def template(self):
     return Node(
         'program:new',
         PropertyNode('command', '127.0.0.1'),
     )
コード例 #22
0
ファイル: squid.py プロジェクト: egberts/python-reconfigure
 def template(self):
     return Node(
         'line',
         PropertyNode('name', 'http_access'),
         Node('arguments', PropertyNode('1', ''))
     )
コード例 #23
0
ファイル: squid.py プロジェクト: egberts/python-reconfigure
 def template(self):
     return Node(
         'line',
         PropertyNode('name', 'https_port'),
         Node('arguments', PropertyNode('1', '3128'))
     )
コード例 #24
0
 def remove_include(self, node):
     return Node('include', children=[PropertyNode('files', node.files)])
コード例 #25
0
ファイル: exports.py プロジェクト: egberts/python-reconfigure
 def template(self):
     return Node('localhost', PropertyNode('options', ''))
コード例 #26
0
ファイル: exports.py プロジェクト: egberts/python-reconfigure
 def template(self):
     return Node('/', Node('clients'))
コード例 #27
0
 def template(self):
     return Node(
         'line',
         Node('token', PropertyNode('value', 'mibs')),
         Node('token', PropertyNode('value', 'IF-MIB')),
     )
コード例 #28
0
ファイル: group.py プロジェクト: egberts/python-reconfigure
 def template(self):
     return Node(
         'line', *[
             Node('token', children=[PropertyNode('value', '')])
             for x in GroupData.fields
         ])
コード例 #29
0
 def template(self):
     return Node(
         'line',
         Node('token', PropertyNode('value', 'rwcommunity')),
         Node('token', PropertyNode('value', 'public 192.168.0.0/24')),
     )
コード例 #30
0
 def template(self):
     return Node(
         'line',
         Node('token', PropertyNode('value', 'informsink')),
         Node('token', PropertyNode('value', 'localhost public')),
     )
コード例 #31
0
ファイル: netatalk.py プロジェクト: Mashpy/ajenti_track
 def template(self):
     return Node(
         'share',
         *[PropertyNode(x, y) for x, y in zip(ShareData.fields, ShareData.defaults)]
     )
コード例 #32
0
ファイル: crontab.py プロジェクト: Eugeny/reconfigure
    def parse(self, content):
        root = RootNode()
        lines = [l.strip() for l in content.splitlines() if l]
        comment = None
        for line in lines:
            if line.startswith('#'):
                comment = '\n'.join([comment, line]) if comment else line[1:]
                continue
            elif line.startswith('@'):
                special, command = line.split(' ', 1)
                node = Node('special_task', comment=comment)
                node.append(PropertyNode('special', special))
                node.append(PropertyNode('command', command))

            else:
                split_line = line.split(' ', 5)
                if len(split_line) <= 3 and '=' in line:
                    name, value = [n.strip() for n in line.split('=')]
                    if not name:
                        continue
                    node = Node('env_setting', comment=comment)
                    node.append(PropertyNode('name', name))
                    node.append(PropertyNode('value', value))
                elif len(split_line) == 6:
                    node = Node('normal_task', comment=comment)
                    node.append(PropertyNode('minute', split_line[0]))
                    node.append(PropertyNode('hour', split_line[1]))
                    node.append(PropertyNode('day_of_month', split_line[2]))
                    node.append(PropertyNode('month', split_line[3]))
                    node.append(PropertyNode('day_of_week', split_line[4]))
                    node.append(PropertyNode('command', split_line[5]))
                else:
                    continue
            root.append(node)
            comment = None
        root.comment = comment
        return root