Пример #1
0
def get_suite_data(prefix, properties=None):
    """Retrieve a dictionary containing the contents of RosieWS

    Adds in any extra requested properties

    """

    if properties is None:
        properties = []

    ws_client = rosie.ws_client.RosieWSClient(
        prefixes=[prefix],
        event_handler=rose.reporter.Reporter()
    )
    suite_data = ws_client.search(prefix, all_revs=1)[0][0]
    for dict_row in sorted(suite_data, key=lambda _: _["revision"]):
        suite_id = rosie.suite_id.SuiteId.from_idx_branch_revision(
            dict_row["idx"],
            dict_row["branch"],
            dict_row["revision"]
        )
        dict_row["suite"] = suite_id.to_string_with_version()
        if "local" in properties:
            dict_row["local"] = suite_id.get_status()
        if "date" in properties:
            dict_row["date"] = time.strftime(
                rosie.ws_client_cli.DATE_TIME_FORMAT,
                time.gmtime(dict_row.get("date"))
            )

    return suite_data
Пример #2
0
def get_suite_data(prefix, properties=None):
    """Retrieve a dictionary containing the contents of RosieWS

    Adds in any extra requested properites

    """

    if properties is None:
        properties = []

    ws_client = rosie.ws_client.RosieWSClient(
        prefixes=[prefix], event_handler=rose.reporter.Reporter())
    suite_data = ws_client.search(prefix, all_revs=1)[0][0]
    for dict_row in sorted(suite_data, key=lambda _: _["revision"]):
        suite_id = rosie.suite_id.SuiteId.from_idx_branch_revision(
            dict_row["idx"], dict_row["branch"], dict_row["revision"])
        dict_row["suite"] = suite_id.to_string_with_version()
        if "local" in properties:
            dict_row["local"] = suite_id.get_status()
        if "date" in properties:
            dict_row["date"] = time.strftime(
                rosie.ws_client_cli.DATE_TIME_FORMAT,
                time.gmtime(dict_row.get("date")))

    return suite_data
Пример #3
0
def calculate_edges(graph,
                    prefix,
                    filter_id=None,
                    properties=None,
                    max_distance=None):
    """Get all connected suites for a prefix, optionally filtered."""
    if properties is None:
        properties = []
    ws_client = rosie.ws_client.RosieWSClient(
        prefixes=[prefix], event_handler=rose.reporter.Reporter())
    node_rosie_properties = {}
    edges = []
    forward_edges = {}
    back_edges = {}
    dict_rows = ws_client.search(prefix, all_revs=1)[0][0]
    for dict_row in sorted(dict_rows, key=lambda _: _["revision"]):
        suite_id = rosie.suite_id.SuiteId.from_idx_branch_revision(
            dict_row["idx"], dict_row["branch"], dict_row["revision"])
        dict_row["suite"] = suite_id.to_string_with_version()
        if "local" in properties:
            dict_row["local"] = suite_id.get_status()
        if "date" in properties:
            dict_row["date"] = time.strftime(
                rosie.ws_client_cli.DATE_TIME_FORMAT,
                time.gmtime(dict_row.get("date")))
        idx = dict_row["idx"]
        node_rosie_properties[idx] = []
        for property in properties:
            node_rosie_properties[idx].append(dict_row.get(property))
        from_idx = dict_row.get("from_idx")
        if from_idx is None:
            continue
        edges.append((from_idx, idx))
        forward_edges.setdefault(from_idx, [])
        forward_edges[from_idx].append(idx)
        back_edges.setdefault(idx, [])
        back_edges[idx].append(from_idx)

    if filter_id is None:
        # Plot all the edges we've found.
        for edge in sorted(edges):
            node0, node1 = edge
            add_node(graph, node0, node_rosie_properties.get(node0))
            add_node(graph, node1, node_rosie_properties.get(node1))
            graph.add_edge(edge[0], edge[1])
    else:
        # Only plot the connections involving filter_id.
        nodes = [n for edge in edges for n in edge]
        node_stack = []
        node_stack = [(filter_id, 0)]
        add_node(graph,
                 filter_id,
                 node_rosie_properties.get(filter_id),
                 fillcolor="lightgrey",
                 style="filled")

        ok_nodes = set([])
        while node_stack:
            node, distance = node_stack.pop()
            if max_distance is not None and distance > max_distance:
                continue
            ok_nodes.add(node)
            for neighbour_node in (forward_edges.get(node, []) +
                                   back_edges.get(node, [])):
                if neighbour_node not in ok_nodes:
                    node_stack.append((neighbour_node, distance + 1))

        if len(ok_nodes) == 1:
            # There are no related suites.
            reporter = rose.reporter.Reporter()
            reporter(NoConnectionsEvent(filter_id))

        for edge in sorted(edges):
            node0, node1 = edge
            if node0 in ok_nodes and node1 in ok_nodes:
                add_node(graph, node0, node_rosie_properties.get(node0))
                add_node(graph, node1, node_rosie_properties.get(node1))
                graph.add_edge(node0, node1)
Пример #4
0
def calculate_edges(graph, prefix, filter_id=None, properties=None, max_distance=None):
    """Get all connected suites for a prefix, optionally filtered."""
    if properties is None:
        properties = []
    ws_client = rosie.ws_client.RosieWSClient(prefixes=[prefix], event_handler=rose.reporter.Reporter())
    node_rosie_properties = {}
    edges = []
    forward_edges = {}
    back_edges = {}
    dict_rows = ws_client.search(prefix, all_revs=1)[0][0]
    for dict_row in sorted(dict_rows, key=lambda _: _["revision"]):
        suite_id = rosie.suite_id.SuiteId.from_idx_branch_revision(
            dict_row["idx"], dict_row["branch"], dict_row["revision"]
        )
        dict_row["suite"] = suite_id.to_string_with_version()
        if "local" in properties:
            dict_row["local"] = suite_id.get_status()
        if "date" in properties:
            dict_row["date"] = time.strftime(rosie.ws_client_cli.DATE_TIME_FORMAT, time.gmtime(dict_row.get("date")))
        idx = dict_row["idx"]
        node_rosie_properties[idx] = []
        for property in properties:
            node_rosie_properties[idx].append(dict_row.get(property))
        from_idx = dict_row.get("from_idx")
        if from_idx is None:
            continue
        edges.append((from_idx, idx))
        forward_edges.setdefault(from_idx, [])
        forward_edges[from_idx].append(idx)
        back_edges.setdefault(idx, [])
        back_edges[idx].append(from_idx)

    if filter_id is None:
        # Plot all the edges we've found.
        for edge in sorted(edges):
            node0, node1 = edge
            add_node(graph, node0, node_rosie_properties.get(node0))
            add_node(graph, node1, node_rosie_properties.get(node1))
            graph.add_edge(edge[0], edge[1])
    else:
        # Only plot the connections involving filter_id.
        nodes = [n for edge in edges for n in edge]
        node_stack = []
        node_stack = [(filter_id, 0)]
        add_node(graph, filter_id, node_rosie_properties.get(filter_id), fillcolor="lightgrey", style="filled")

        ok_nodes = set([])
        while node_stack:
            node, distance = node_stack.pop()
            if max_distance is not None and distance > max_distance:
                continue
            ok_nodes.add(node)
            for neighbour_node in forward_edges.get(node, []) + back_edges.get(node, []):
                if neighbour_node not in ok_nodes:
                    node_stack.append((neighbour_node, distance + 1))

        if len(ok_nodes) == 1:
            # There are no related suites.
            reporter = rose.reporter.Reporter()
            reporter(NoConnectionsEvent(filter_id))

        for edge in sorted(edges):
            node0, node1 = edge
            if node0 in ok_nodes and node1 in ok_nodes:
                add_node(graph, node0, node_rosie_properties.get(node0))
                add_node(graph, node1, node_rosie_properties.get(node1))
                graph.add_edge(node0, node1)