コード例 #1
0
 def _collect(self, TestClass):
     ep("_collect for class " + self.__class__.__name__)
     import yaml  # we need a yaml parser, e.g. PyYAML
     top = yaml.safe_load(self.fspath.open())
     if top and 'items' in top:
         test_items = top['items']
         for name in sorted(test_items.keys()):
             spec = test_items[name]
             yield TestClass(str(name), self, spec)
コード例 #2
0
 def __init__(self, backend=None, file=None):
     if file is None:
         file=CacheBackend.DEFAULT_FILE
     elif file == '':
         # explicitly disabled caching
         ep("Caching disabled for CacheBackend")
     self.file = file
     if backend is None:
         backend = LiveBackend()
     self.backend = backend
     self.data = {}
     # TODO - load yaml file
     if self.file and os.path.exists(self.file):
         self.load()
コード例 #3
0
ファイル: systemd.py プロジェクト: cjsin/systemd-graph
    def search(self, kinds, prune=None):
        for u in self.Units():
            u = self.Unit(u.name)

        all_set = False
        statuses = set()
        name_matchers = []
        for k in kinds:
            if k == 'all':
                all_set = True
            elif k in Unit.STATUS:
                statuses.add(k)
            else:
                ep("Adding name matcher " + str(k))
                name_matchers.append(k)

        startwith = set()
        if all_set:
            verb("All units selected as a starting point")
            for u in self.Units():
                startwith.add(u.name)
        else:
            ep("Searching " + str(len(self.Units())) + " with " +
               str(len(name_matchers)) + " name matchers")
            for u in self.Units():
                for nm in name_matchers:
                    if re.search(nm, u.name):
                        ep("matched " + u.name)
                        startwith.add(u.name)
                        break
                    elif u.name.startswith("test-loop"):
                        ep("matcher " + str(nm) + " did not match " + u.name)
                    #else:
                    #    ep("non test-loop")
        verb2("Starting with a set of units:" + pformat(startwith))
        if statuses:
            filterout = set()
            verb("Excluding units that do not match statuses " +
                 pformat(statuses))
            for u in self.Units():
                if not u.status_match(statuses):
                    filterout.add(u.name)
            startwith = startwith - filterout

        if prune:
            filterout = set()
            verb("Excluding units that do not match names " + pformat(prune))
            for u in self.Units():
                for nm in prune:
                    if re.search(nm, u.name):
                        filterout.add(u.name)
                        break
            startwith = startwith - filterout

        return [self.Unit(x) for x in startwith]
コード例 #4
0
def go(args):
    os.environ['BROWSER']='chromium'
    net = Vis()
    net.add_node(1, label="Node 1")
    net.add_node(2)
    nodes = ["a", "b", "c", "d"]
    net.add_nodes(nodes)  #node ids and labels = ["a", "b", "c", "d"]
    net.add_nodes("hello") # node ids and labels = ["h", "e", "l", "o"]
    #["size", "value", "title", "x", "y", "label", "color"]

    #net.add_nodes([1,2,3], value=[10, 100, 400], title=["I am node 1", "node 2 here", "and im node 3"], x=[21.4, 54.2, 11.2], y=[100.2, 23.54, 32.1], label=["NODE 1", "NODE 2", "NODE 3"], color=["#00ff1e", "#162347", "#dd4b39"])
    #net.add_node(0, label="a")
    #net.add_node(1, label="b")
    #net.add_edge(0, 1)

    #nxg = nx.complete_graph(10)
    #G = Network(height="750px", width="100%", bgcolor="#222222", font_color="white")
    #G.from_nx(nxg)

    #net.enable_physics(True)
    net.path =os.path.dirname(__file__) + "/html/vis_template.html"
    #net.toggle_physics()
    #net.show("blah.html")

    if args.dotfile:
        Vis()
        ep("Load " + args.dotfile)
        net.from_DOT(args.dotfile)
        ep("Number of edges:{}".format(net.num_edges()))
        net.show("test.dot.html")
    else:
        ep("No file.")
コード例 #5
0
 def save(self):
     """ Save, if this backend has the capability """
     if not self.file:
         return False
     if not self.modified:
         #ep(f"Skip saving - no changes.")
         return True
     #ep(f"Save cache {self.file}")
     # TODO - save yaml file
     import yaml
     try:
         ydata = dict()
         #ep(f"Save cache self data has {len(self.data.keys())} keys")
         ydata.update(self.data)
         strdata = yaml.safe_dump(ydata)
         with open(self.file,"w") as f:
             f.write(strdata)
             #ep(f"Save cache {len(ydata.keys())}")
             self.modified=False
             return True
     except:
         traceback.print_exc()
         ep("Saving failed.")
         return False
コード例 #6
0
def save_dotfile(dotfile, htmlfile, show=False):

    #net.toggle_physics()
    #net.show("blah.html")

    if dotfile:
        net = Vis()
        #net.show_buttons(filter_=['physics'])

        ep("Load " + dotfile)
        net.from_DOT(dotfile)
        ep("Number of edges:{}".format(net.num_edges()))
        if show:
            net.show(htmlfile)
        else:
            net.save_graph(htmlfile)

    else:
        ep("No file.")
コード例 #7
0
ファイル: systemd.py プロジェクト: cjsin/systemd-graph
    def dump(self):
        units = self.Units()
        nunits = len(units)

        #ep(f"{nunits} units to process.")
        if verbose() > 1:
            for n in range(0, len(units)):
                #ep(f"{n}={units[n].name}")
                pass

        for n in range(0, len(units)):
            if n % 10 == 0:
                #ep(f"\r{n}/{nunits} processed...\x1b[K")
                pass
            self.Unit(units[n].name)

        ep("\rAll units processed.")

        for u in units:
            ep(u)
            for e in u.Edges():
                ep(e)
コード例 #8
0
 def __init__(self, name, parent, spec):
     ep("Yaml Item")
     super(YamlItem, self).__init__(name, parent)
     self.spec = spec
コード例 #9
0
ファイル: systemd.py プロジェクト: cjsin/systemd-graph
 def FinishLoading(self):
     ep("")
     for u in self.Units():
         self.Unit(u.name)
     ep("")
コード例 #10
0
ファイル: systemd.py プロジェクト: cjsin/systemd-graph
    def Graph(self, name, backwards=True, units=None):
        if name is None:
            name = "systemd"

        g = Graph(name)
        ep("Generating graph for " + str(len(units)) + " selected units")
        # First preprocess the units to pre-load and generate extras if required

        if units is None:
            units = self.Units()

        todo = set()
        done = set()
        for u in units:
            u = self.Unit(u.name)
            todo.add(u.name)

        # It is simple to go forwards, just follow the edges
        if not backwards:
            while len(todo):
                #ep("TODO: "+str(len(todo)))
                uname = todo.pop()
                if uname in done:
                    #ep("Aldready done")
                    continue

                u = self.Unit(uname)
                #ep("Add node " + u.name + " with " + str(len(u.Edges())) + " edges")
                g.add_node(u)
                done.add(uname)

                for e in u.Edges():
                    #ep("Check edge " + str(e))
                    a = e.a
                    b = e.b
                    if e.a.name not in done:
                        todo.add(e.a.name)

                    if e.b.name not in done:
                        todo.add(e.b.name)
                    #ep("Add edge " + str(e))
                    g.add_edge(e)

        else:
            #ep("Search network for forward links to these nodes")
            # we are going backwards, need to search the entire set of nodes
            # for forward edges that point to these nodes.
            while len(todo):
                verb("TODO: " + str(len(todo)))
                uname = todo.pop()
                if uname in done:
                    continue
                u = self.Unit(uname)
                g.add_node(u)
                done.add(uname)
                for u2 in self.Units():
                    verb("Search for units with edges going to " + uname)
                    if u2.name == uname:
                        continue
                    elif u2.name in done:
                        continue
                    elif u2.name in todo:
                        # do it later
                        continue
                    else:
                        for e in u2.Edges():
                            b = e.b
                            if b.name == uname:
                                aname = e.a.name
                                if aname not in todo and aname not in done:
                                    g.add_node(self.Unit(aname))
                                    g.add_edge(e)
                                    #ep("Add edge " + str(e))
                                    todo.add(aname)

            # Now we will have all interesting nodes in 'done'
        return g
コード例 #11
0
ファイル: test_graph.py プロジェクト: cjsin/systemd-graph
def dump(g):
    #ep(f"Graph {g} :")
    dump_graph(g)
    ep(repr(g))