def _create_parser(cls):
     """
     Need to check the specific symbol "/" in attr_value part as well.
     I checked some multipath configuraion files from the sosreport and got
     although there are some more specific symbols like "-%", it is enclosed
     in double quotes and will be accepted. Furthermore, I also checked the
     source code of "device-mapper-multipath" and got if the attr_value in
     "multipath.conf" include a "whitespace", it must be enclosed in double
     quotation marks. So, we could just add one more specific symbol "/" to
     check.
     ----------------------------------------------------------
     udev_dir                /dev
     getuid_callout          "/sbin/scsi_id -g -u -s /block/%n"
     ----------------------------------------------------------
     """
     section_name = p.Word(p.alphas + "_")
     attr_name = attr_value = p.Word(p.alphanums + "_/")
     LBRACE, RBRACE = map(p.Suppress, "{}")
     attr = p.Group(attr_name +
                    (attr_value
                     | p.quotedString.setParseAction(p.removeQuotes)))
     attr_list = p.Dict(p.ZeroOrMore(attr))
     simple_section = p.Group(section_name + LBRACE + attr_list + RBRACE)
     complex_section = p.Group(section_name + LBRACE +
                               p.OneOrMore(simple_section) + RBRACE)
     simple_or_complex = p.Dict(simple_section | complex_section)
     my_conf = p.Group(p.ZeroOrMore(simple_or_complex))
     my_conf.ignore("#" + p.restOfLine)
     return my_conf
Beispiel #2
0
def perm_parser():
    COLON = p.Suppress(":")
    WHITE = p.Suppress(p.White())

    vhostname = p.Word(p.alphanums + '_-/')
    username = p.Word(p.alphanums + '_-')
    conf = p.Word(p.alphanums + '.*#')

    perm_vhost = p.Suppress("Permissions on") + vhostname + COLON
    ucwr = p.Suppress("user" + WHITE + "configure" + WHITE + "write" + WHITE + "read")
    perm_line = p.Group(username + 3 * (WHITE + conf))

    perm_con = p.Optional(ucwr + p.Dict(p.OneOrMore(perm_line)))
    perm_block = p.Group(perm_vhost + perm_con)
    perm = p.Dict(p.OneOrMore(perm_block))

    return perm
Beispiel #3
0
def create_parser():
    DOTS = p.Suppress("...")
    NSTAT_PREFIX = p.Suppress("Status of node")
    PERM_PREFIX = p.Suppress("Permissions on")
    nodename = p.Word(p.alphanums + '\'_-@')

    block_nstat = p.Group(NSTAT_PREFIX + nodename + DOTS + erlblock_parser())
    nstat = p.Dict(p.OneOrMore(p.Suppress(p.SkipTo(NSTAT_PREFIX)) +
            block_nstat)).setResultsName('nstat')
    perm = p.Suppress(p.SkipTo(PERM_PREFIX)) + perm_parser().setResultsName('perm')

    return nstat + perm
Beispiel #4
0
def erlblock_parser():
    COMMA = p.Suppress(',')
    LBRACE, RBRACE = map(p.Suppress, "{}")
    LBRACKET, RBRACKET = map(p.Suppress, "[]")

    key = p.Word(p.alphas + '_')
    value_tnum = p.Word(p.nums + '.')
    value_tword = p.Word(p.alphanums + '/"-[]:.()')
    value_tstr = p.OneOrMore(value_tword)
    value_tdoustrs = value_tstr + COMMA + value_tstr
    value_tnumstr = value_tnum + value_tstr
    value = value_tdoustrs | value_tnumstr | value_tstr | value_tnum

    attr = LBRACE + p.Group(key + COMMA + value) + RBRACE
    attr_list = p.Dict(p.ZeroOrMore(attr + COMMA) + p.ZeroOrMore(attr))
    block = LBRACKET + attr_list + RBRACKET

    value_plus = block | attr | value
    attr = LBRACE + p.Group(key + COMMA + value_plus) + RBRACE
    attr_list = p.Dict(p.OneOrMore(attr + COMMA) + p.OneOrMore(attr))
    block = LBRACKET + attr_list + RBRACKET

    return block