Esempio n. 1
0
 def test_detect_circularity(self):
     g = graph.DirectedGraph()
     g.add_node("a")
     g.add_node("b", ["a"])
     g.add_node("c", ["b"])
     # root <-- a <-- b <-- c
     if not g.depends_on("c", "a"):
         self.fail("Did not detect dependency.")
Esempio n. 2
0
 def test_detect_circularity_when_adding(self):
     g = graph.DirectedGraph()
     g.add_node("a")
     g.add_node("b", ["a"])
     # root <-- a <-- b
     try:
         g.add_dependency("a", "b")
     except graph.GraphError, e:
         pass
Esempio n. 3
0
 def test_get_all_dependees(self):
     g = graph.DirectedGraph()
     g.add_node("a")
     g.add_node("b", ["a"])
     g.add_node("c", ["b"])
     g.add_node("d", ["b"])
     # root <-- a <-- b <-- c,d
     all = g.get_all_dependees("a")
     self.failUnlessEqual(all, ["b", "c", "d"])
Esempio n. 4
0
    def test_traverse(self):
        g = graph.DirectedGraph()
        g.add_node("a")
        g.add_node("b", ["a"])
        g.add_node("c", ["a"])
        g.add_node("d", ["b"])
        g.add_node("e", ["b"])

        li = g.get_supported_by("a")
        self.failUnlessEqual(li, ["b", "c"])
        li = g.get_supported_by("b")
        self.failUnlessEqual(li, ["d", "e"])
Esempio n. 5
0
 def setUp(self):
     self.g = graph.DirectedGraph()
     self.g.add_node("a")
     self.g.add_node("b", ["a"])
     self.g.add_node("c", ["b"])
     self.g.add_node("d", ["b"])
     self.g.add_node("e")
     self.g.add_node("f", ["e"])
     self.g.add_node("g")
     self.g.add_node("h")
     self.g.add_node("j")
     self.g.add_node("i", ['h', 'j'])
Esempio n. 6
0
 def test_clear(self):
     g = graph.DirectedGraph()
     g.add_node("x")
     g.add_node("y")
     g.add_node("z")
     root = g.get_root()
     li = g.get_supported_by(root)
     self.failUnlessEqual(li, ["x", "y", "z"])
     li2 = g.get_all_nodes()
     self.failUnlessEqual(li2, [root, "x", "y", "z"])
     g.clear()
     li3 = g.get_all_nodes()
     self.failUnlessEqual(li3, [root])
Esempio n. 7
0
    def test_remove_dep(self):
        g = graph.DirectedGraph()
        g.add_node("aaa")
        g.add_node("b", "aaa")

        li = g.get_supported_by("aaa")
        self.failUnlessEqual(li, ["b"])

        g.remove_dependency("b", "aaa")

        li = g.get_supported_by("aaa")
        self.failUnlessEqual(li, [])

        li = g.get_dependencies("b")
        self.failUnlessEqual(li, [g.get_root()])
Esempio n. 8
0
    def test_nodes(self):
        g = graph.DirectedGraph()
        root = g.get_root()

        g.add_node("a")
        a = g.get_supported_by(root)
        self.failUnlessEqual(a, ["a"])
        # a should depend on root

        g.add_node("b", ["a"])
        a2 = g.get_dependencies("b")
        self.failUnlessEqual(a, ["a"])
        # b should depend on a

        g.add_node("c", ["a"])
        #print(str(g))
        li = g.get_supported_by("a")
        self.failUnlessEqual(li, ["b", "c"])
Esempio n. 9
0
 def __init__(self, log_dir=None, pid_dir=None, pid_file=None, log_file=None, config_file=None, verbose=False):
     """
     @param log_dir: str Path.
     @param pid_dir: str Path.
     @param pid_file: str Path.
     @param log_file: str Path.
     @param config_file: str Path.
     """
     # attributes:
     self.commands = {} # dict of str identifier: L{lunch.commands.Command}
     self.tree = graph.DirectedGraph()
     # For counting default names if they are none :
     self.i = 0
     # IP to which not use SSH with :
     self.local_addresses = [
         "localhost",
         "127.0.0.1",
         ]
     self._guess_local_ip_and_hostname_for_local_host()
     
     # These are all useless within this class, but might be useful to be read from the GUI:
     self.log_dir = log_dir
     self.pid_dir = pid_dir
     if self.log_dir is None:
         self.log_dir = get_default_log_dir_full_path()
     if self.pid_dir is None:
         self.pid_dir = get_default_pid_dir_full_path()
     self.pid_file = pid_file
     self.log_file = log_file
     self.config_file = config_file
     self.verbose = verbose
     self.main_loop_every = 0.05 # checks process to start/stop 20 times a second.
     self._time_now = time.time()
     self.launch_next_time = time.time() # time in future
     self._looping_call = task.LoopingCall(self.main_loop)
     self._looping_call.start(self.main_loop_every, False) 
     self.wants_to_live = False # The master is either trying to make every child live or die. 
     self.command_added_signal = sig.Signal() # param: Command object
     self.command_removed_signal = sig.Signal() # param: command object -- Called when actually deleted from the graph
     # actions:
     self.start_all()
     self._shutdown_event_id = reactor.addSystemEventTrigger("before", "shutdown", self.before_shutdown)