summaryrefslogtreecommitdiffstats
path: root/filters/simpleconfig2needlexml.py
blob: f846b310b42eb95f3c91d469cc1bacc2a796e3b0 (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
# -*- coding: UTF-8 -*-
# Copyright 2015 Red Hat, Inc.
# Part of clufter project
# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
"""simpleconfig2needlexml filter"""
__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"

from lxml import etree

from ..filter import Filter
from ..utils import selfaware


@selfaware
def _simpleconfig2needlexml(me, element, options, sections):
    # must not attempt to modify anything from options/sections in-place
    element.attrib.update(options)
    element.extend([me(etree.Element(s[0]), *s[1:]) for s in sections])
    return element


@Filter.deco('simpleconfig-normalized', 'coroxml-needle')
def simpleconfig2needlexml(flt_ctxt, in_obj):
    """Cooks XML representation of corosync.conf"""
    struct = in_obj('struct', protect_safe=True)
    return ('etree', _simpleconfig2needlexml(etree.Element("corosync"),
                                             *struct[1:]))