コード例 #1
0
def serviceUnitHandler(elem, resolver, context):
    """Custom representation of a service unit"""
    name = elem.attrib.get("listkey", formatTag(elem.tag))
    w = xmlterm.FancyText(resolver.parentWin, ("  " * resolver.depth) + name,
                          fore=SuNameColor,
                          size=SuNameSize)
    resolver.add(w)
    try:
        w = xmlterm.FancyText(
            resolver.parentWin,
            ("  " * resolver.depth) + "  Admin: %s Operational: %s %s " %
            (elem.find("adminState").text, "OK" if elem.find("operState").text
             == "1" else "FAULTED", elem.find("haState").text))
        resolver.add(w)
        w = xmlterm.FancyText(
            resolver.parentWin,
            ("  " * resolver.depth) + "  Active Work: %s Standby Work: %s" %
            (elem.find("numActiveServiceInstances").find("current").text,
             elem.find("numStandbyServiceInstances").find("current").text))
        resolver.add(w)
        w = xmlterm.FancyText(resolver.parentWin, ("  " * resolver.depth) +
                              "  On Node: %s  In Service Group: %s" %
                              (elem.find("node").text.split("/")[-1],
                               elem.find("serviceGroup").text.split("/")[-1]))
        resolver.add(w)
    except AttributeError, e:  # object could have no children because recursion depth exceeded
        pass
コード例 #2
0
def epochTimeHandler(elem, resolver, context):
    """Convert an xml leaf containing seconds since the epoch into a user readable date panel"""
    seconds = int(elem.text)
    s = time.strftime('%Y-%b-%d %H:%M:%S', time.localtime(seconds))
    w = xmlterm.FancyText(resolver.parentWin, ("  " * resolver.depth) +
                          formatTag(elem.tag) + ": " + s)
    resolver.add(w)
コード例 #3
0
def elapsedSecondsHandler(elem, resolver, context):
    """Convert an xml leaf containing seconds to a user readable version of elapsed time"""
    if elem.text is None:
        s = ": unspecified"
    else:
        seconds = int(elem.text)
        days, rest = divmod(seconds, 60 * 60 * 24)
        hours, rest = divmod(rest, 60 * 60)
        minutes, seconds = divmod(rest, 60)
        s = ": %d days %d hours %d minutes and %d seconds" % (days, hours,
                                                              minutes, seconds)
    w = xmlterm.FancyText(resolver.parentWin,
                          ("  " * resolver.depth) + formatTag(elem.tag) + s)
    resolver.add(w)
コード例 #4
0
def epochMsTimeHandler(elem, resolver, context):
    """Convert an xml leaf containing milli-seconds since the epoch into a user readable date panel"""
    try:
        mseconds = int(elem.text)
        s = time.strftime('%Y-%b-%d %H:%M:%S', time.localtime(mseconds / 1000))
    except TypeError:
        if elem.text is None: s = 'unspecified'
        else:  # garbage in the field
            assert (0)
            s = "!error bad numeric field: ", str(elem.text)

    w = xmlterm.FancyText(resolver.parentWin, ("  " * resolver.depth) +
                          formatTag(elem.tag) + ": " + s)
    resolver.add(w)
コード例 #5
0
def serviceUnitListHandler(elem, resolver, context):
    """Create a graphical representation of the XML 'text' tag"""
    if elem.attrib.has_key("listkey"):  # Its an instance of the list
        serviceUnitHandler(elem, resolver, context)
        return
    path = elem.attrib.get("path", None)
    if path == "/SAFplusAmf/ServiceUnit" or len(
            elem
    ) > 0:  # serviceunit tag can be a list, a list entry, or a su ref.  SU ref has no children
        resolver.add(
            xmlterm.FancyText(resolver.parentWin,
                              ("  " * resolver.depth) + "ServiceUnit",
                              fore=SuListColor,
                              size=SuListSize))
        resolver.depth += 1
        for su in elem:
            serviceUnitHandler(su, resolver, context)
        resolver.depth -= 1
    else:  # Could be ServiceUnit has no children because recursion depth exceeded
        w = xmlterm.FancyText(resolver.parentWin, ("  " * resolver.depth) +
                              formatTag(elem.tag))  # so normal display
        resolver.add(w)

    if elem.text:  # There should not be any text in the service unit list but display it if there is
        size = elem.attrib.get("size", None)
        if size: size = int(size)
        fore = elem.attrib.get("fore", None)
        if fore: fore = color.rgb(fore)  # [ int(x) for x in fore.split(",")]
        back = elem.attrib.get("back", None)
        if back: back = color.rgb(back)  # [ int(x) for x in back.split(",")]
        w = xmlterm.FancyText(resolver.parentWin,
                              elem.text,
                              fore=fore,
                              back=back,
                              size=size)
        resolver.add(w)
コード例 #6
0
def topHandler(elem, resolver, context):
    """Make this XML node invisible -- skip down to the children"""
    childReorg(elem, context.path)
    for child in elem:
        fullpath = child.attrib.get("path", None)
        if fullpath:  # print out the full path with a : if it is placed into the child's attribute list.  This only happens for top level nodes so the user can see where they were found
            resolver.add(
                xmlterm.FancyText(resolver.parentWin,
                                  fullpath + ":",
                                  fore=FullPathColor))
            resolver.depth += 1
        resolver.resolve(child, context)
        if fullpath:
            resolver.depth -= 1

        if child.tail and child.tail.strip():
            w = xmlterm.FancyTextChunked(resolver.parentWin,
                                         ("  " * resolver.depth) + child.tail,
                                         chunkSize=2048)
            resolver.add(w)
コード例 #7
0
def historyHandler(elem, resolver, context):
    """Create a plot for the historical statistics XML nodes"""
    if elem.text:
        data = [float(x) for x in elem.text.split(",")]
        title = elem.attrib.get("title", formatTag(elem.tag))
        xlabel = elem.attrib.get("xlabel", "time")
        ylabel = elem.attrib.get(
            "ylabel", "")  # TODO: grab the parent's tag as the ylabel?

        plotAttrib = {"title": title, "xlabel": xlabel, "ylabel": ylabel}
        if len(
                resolver.windows
        ) > 1:  # If there is lots of other data in this command, show a small graph
            plotAttrib["size"] = "(200,100)"
        plot = ET.Element("plot", plotAttrib)
        series = ET.Element("series", {"label": ""}, text=elem.text)
        series.text = elem.text
        plot.append(series)
        resolver.add(xmlterm.FancyText(resolver.parentWin,
                                       formatTag(elem.tag)))
        w = xmlterm.PlotPanel(resolver.parentWin, plot)
        resolver.add(w)
    else:
        resolver.defaultHandler(elem, resolver, context)
コード例 #8
0
def dumpNoTagHandler(elem, resolver, context):
    """"""
    resolver.add(xmlterm.FancyText(resolver.parentWin, elem.text))