Ejemplo n.º 1
0
    def cleanup(self):
        for path in self.rm_list_:
            util.rm_path(path)

        for cmd_entry in self.old_commands_:
            if self.refactoring:
                util.con_err(util.ConsoleRed,
                             'Command removed during refactoring: \n',
                             util.ConsoleBlue, cmd_entry.format(),
                             util.ConsoleNormal)
                raise Exception('Refactoring error: command removed')
            self.db.drop_command(cmd_entry)

        for path in self.old_scripts_:
            self.db.drop_script(path)

        self.db.query_dead_sources(lambda e: self.db.drop_source(e))
        self.db.query_dead_shared_outputs(lambda e: self.db.drop_output(e))
        self.db.drop_unused_environments()

        class Node:
            def __init__(self):
                self.incoming = set()
                self.outgoing = set()

        # Build a tree of dead folders.
        tracker = {}
        for entry in self.old_folders_:
            if entry not in tracker:
                tracker[entry] = Node()

            if entry.folder is None:
                continue

            # If our parent is not a dead folder, don't create an edge. It should be
            # impossible for a/b to be dead, a/b/c to be alive, and a/b/c/d to be
            # dead, since a/b/c will implicitly keep a/b alive.
            if entry.folder not in self.old_folders_:
                continue

            if entry.folder not in tracker:
                tracker[entry.folder] = Node()

            parent = tracker[entry.folder]
            child = tracker[entry]
            parent.incoming.add(entry)
            child.outgoing.add(entry.folder)

        # Find the leaves. Sets start out >= 1 items. Remove them as they they
        # are empty.
        dead_folders = [
            entry for entry in self.old_folders_
            if len(tracker[entry].incoming) == 0
        ]
        while len(dead_folders):
            child_entry = dead_folders.pop()
            child_node = tracker[child_entry]

            if self.refactoring:
                util.con_err(util.ConsoleRed,
                             'Folder removed during refactoring: \n',
                             util.ConsoleBlue, child_entry.format(),
                             util.ConsoleNormal)
                raise Exception('Refactoring error: command removed')

            self.db.drop_folder(child_entry)
            for parent_entry in child_node.outgoing:
                parent_node = tracker[parent_entry]
                parent_node.incoming.remove(child_entry)
                if not len(parent_node.incoming):
                    dead_folders.append(parent_entry)
Ejemplo n.º 2
0
 def drop_output(self, output):
     assert output.type == nodetypes.Output or output.type == nodetypes.SharedOutput
     util.rm_path(output.path)
     self.drop_entry(output)
Ejemplo n.º 3
0
 def drop_output(self, output):
   assert output.type == nodetypes.Output or output.type == nodetypes.SharedOutput
   util.rm_path(output.path)
   self.drop_entry(output)
Ejemplo n.º 4
0
  def cleanup(self):
    for path in self.rm_list_:
      util.rm_path(path)

    for cmd_entry in self.old_commands_:
      if self.refactoring:
        util.con_err(util.ConsoleRed, 'Command removed during refactoring: \n',
                     util.ConsoleBlue, cmd_entry.format(),
                     util.ConsoleNormal)
        raise Exception('Refactoring error: command removed')
      self.db.drop_command(cmd_entry)

    for path in self.old_scripts_:
      self.db.drop_script(path)

    for group in self.old_groups_:
      self.db.drop_group(group)

    self.db.query_dead_sources(lambda e: self.db.drop_source(e))
    self.db.query_dead_shared_outputs(lambda e: self.db.drop_output(e))

    class Node:
      def __init__(self):
        self.incoming = set()
        self.outgoing = set()

    # Build a tree of dead folders.
    tracker = {}
    for entry in self.old_folders_:
      if entry not in tracker:
        tracker[entry] = Node()

      if entry.folder is None:
        continue

      # If our parent is not a dead folder, don't create an edge. It should be
      # impossible for a/b to be dead, a/b/c to be alive, and a/b/c/d to be
      # dead, since a/b/c will implicitly keep a/b alive.
      if entry.folder not in self.old_folders_:
        continue

      if entry.folder not in tracker:
        tracker[entry.folder] = Node()

      parent = tracker[entry.folder]
      child = tracker[entry]
      parent.incoming.add(entry)
      child.outgoing.add(entry.folder)

    # Find the leaves. Sets start out >= 1 items. Remove them as they they
    # are empty.
    dead_folders = [entry for entry in self.old_folders_ if len(tracker[entry].incoming) == 0]
    while len(dead_folders):
      child_entry = dead_folders.pop()
      child_node = tracker[child_entry]

      if self.refactoring:
        util.con_err(util.ConsoleRed, 'Folder removed during refactoring: \n',
                     util.ConsoleBlue, child_entry.format(),
                     util.ConsoleNormal)
        raise Exception('Refactoring error: command removed')

      self.db.drop_folder(child_entry)
      for parent_entry in child_node.outgoing:
        parent_node = tracker[parent_entry]
        parent_node.incoming.remove(child_entry)
        if not len(parent_node.incoming):
          dead_folders.append(parent_entry)