Example #1
0
    def __init__(self, port, depends=None):
        """Initialise the databases of dependencies."""
        from . import get_port

        DependHandler.__init__(self)
        self._count = 0  #: The count of outstanding dependencies
        self._dependencies = [[], [], [], [], [], [], []]  #: All dependencies
        self._loading = 0  #: Number of dependencies left to load
        self._bad = 0  #: Number of bad dependencies
        self.failed = False  #: If a dependency has failed
        self.port = port  #: The port whom we handle

        if not depends:
            depends = []

        def adder(field, typ):
            """Create an adder to place resolved port on dependency list,"""
            def do_add(port):
                """Add port to dependency list."""
                self._add(port, field, typ)
            return do_add

        for i in range(len(depends)):
            for j in depends[i]:
                self._loading += 1
                get_port(j[1]).connect(adder(j[0], i))
        if not self._loading:
            self._update_priority()
            event.post_event(self.loaded.emit, True)
Example #2
0
    def __call__(self, port):
        """Try resolve a port as a dependency."""
        assert not port.dependent.failed

        if port in self.ports:
            return self.ports[port]
        elif port in self.finished:
            sig = signal.Signal()
            event.post_event(sig.emit, port)
            return sig
        else:
            sig = signal.Signal()
            self.method[port] = env.flags["method"][0]

            for builder, method in zip((install, pkginstall, repoinstall),
                                       ("build", "package", "repo")):
                if port in builder.ports:
                    builder.add(port).connect(self._clean)
                    self.ports[port] = sig
                    self.method[port] = self._next(method)
                    break
            else:
                if not self._find_method(port):
                    self.finished.add(port)
                    event.post_event(sig.emit, port)
                else:
                    self.ports[port] = sig
            return sig
Example #3
0
 def _do_stage(self):
     pkg_query = pkg.query(self.port, "config")
     if pkg_query:
         self.pid = pkg_query.connect(self._post_pkg_query).pid
     else:
         # Unable to query, assume acceptable package
         event.post_event(self._finalise, True)
Example #4
0
    def __call__(self, port):
        """Try resolve a port as a dependency."""
        assert not port.dependent.failed

        if port in self.ports:
            return self.ports[port]
        elif port in self.finished:
            sig = signal.Signal()
            event.post_event(sig.emit, port)
            return sig
        else:
            sig = signal.Signal()
            self.method[port] = env.flags["method"][0]

            for builder, method in zip((install, pkginstall, repoinstall),
                                       ("build", "package", "repo")):
                if port in builder.ports:
                    builder.add(port).connect(self._clean)
                    self.ports[port] = sig
                    self.method[port] = self._next(method)
                    break
            else:
                if not self._find_method(port):
                    self.finished.add(port)
                    event.post_event(sig.emit, port)
                else:
                    self.ports[port] = sig
            return sig
Example #5
0
 def get_port(self, origin):
     """Get a port and callback with it."""
     if origin in self._ports:
         sig = signal.Signal()
         event.post_event(sig.emit, self._ports[origin])
         return sig
     else:
         if origin in self._waiters:
             return self._waiters[origin]
         else:
             sig = signal.Signal()
             self._waiters[origin] = sig
             mk.attr(origin).connect(self._attr)
             return sig
Example #6
0
 def get_port(self, origin):
     """Get a port and callback with it."""
     if origin in self._ports:
         sig = signal.Signal()
         event.post_event(sig.emit, self._ports[origin])
         return sig
     else:
         if origin in self._waiters:
             return self._waiters[origin]
         else:
             sig = signal.Signal()
             self._waiters[origin] = sig
             mk.attr(origin).connect(self._attr)
             return sig
Example #7
0
    def _do_stage(self):  # pylint: disable-msg=E0202
        """Issue a pkg.add() to install the package from a repo."""
        log.debug(
            "PackageInstaller._do_stage()",
            "Port '%s': building stage %s" % (self.port.origin, self.name))

        pkg_add = self._add_pkg()
        # pkg_add may be False if installing `ports-mgmt/pkg` and
        # env.flags["pkg_mgmt"] == "pkgng"
        if pkg_add:
            self.pid = pkg_add.connect(self._post_pkg_add).pid
        else:
            # Cannot call self._finalise from within self.work() ->
            #   self._do_stage()
            event.post_event(self._finalise, False)
Example #8
0
    def _do_stage(self):  # pylint: disable-msg=E0202
        """Issue a pkg.add() to install the package from a repo."""
        log.debug("PackageInstaller._do_stage()",
                  "Port '%s': building stage %s" %
                      (self.port.origin, self.name))


        pkg_add = self._add_pkg()
        # pkg_add may be False if installing `ports-mgmt/pkg` and
        # env.flags["pkg_mgmt"] == "pkgng"
        if pkg_add:
            self.pid = pkg_add.connect(self._post_pkg_add).pid
        else:
            # Cannot call self._finalise from within self.work() ->
            #   self._do_stage()
            event.post_event(self._finalise, False)
Example #9
0
    def add(self, port):
        """Add a port to be build for this stage."""
        assert not port.dependent.failed

        if port in self.ports:
            return self.ports[port]
        else:
            # Create stage job
            stagejob = self.stage(port).connect(self._cleanup)
            self.ports[port] = stagejob
            self.update.emit(self, Builder.ADDED, port)

            # Configure port then process it
            if stacks.Depend not in port.stages:
                depend.add(port).connect(self._add)
            else:
                assert port not in depend.ports
                # self._add() needs to be asynchronous to self.add()
                event.post_event(self._add, port=port)
            return stagejob
Example #10
0
    def add(self, port):
        """Add a port to be build for this stage."""
        assert not port.dependent.failed

        if port in self.ports:
            return self.ports[port]
        else:
            # Create stage job
            stagejob = self.stage(port).connect(self._cleanup)
            self.ports[port] = stagejob
            self.update.emit(self, Builder.ADDED, port)

            # Configure port then process it
            if stacks.Depend not in port.stages:
                depend.add(port).connect(self._add)
            else:
                assert port not in depend.ports
                # self._add() needs to be asynchronous to self.add()
                event.post_event(self._add, port=port)
            return stagejob
Example #11
0
    def work(self):
        assert not self.stack.working
        assert not self.failed

        log.debug("Stage.work()", "Port '%s': starting stage %s" %
                      (self.port.origin, self.name))
        if not self.check(self.port):
            # Cannot call self._finalise(True) directly as self.done() cannot
            # be called from within the scope of self.work()
            event.post_event(self._finalise, False)
            return
        assert self.prev in self.port.stages
        assert (not self.port.dependency or
                not self.port.dependency.check(self.__class__))
        if self.complete():
            # Cannot call self._finalise(True) directly as self.done() cannot
            # be called from within the scope of self.work()
            event.post_event(self._finalise, True)
        else:
            self._do_stage()  # May throw job.JobStalled()
            self.stack.working = time.time()
Example #12
0
    def work(self):
        assert not self.stack.working
        assert not self.failed

        log.debug(
            "Stage.work()",
            "Port '%s': starting stage %s" % (self.port.origin, self.name))
        if not self.check(self.port):
            # Cannot call self._finalise(True) directly as self.done() cannot
            # be called from within the scope of self.work()
            event.post_event(self._finalise, False)
            return
        assert self.prev in self.port.stages
        assert (not self.port.dependency
                or not self.port.dependency.check(self.__class__))
        if self.complete():
            # Cannot call self._finalise(True) directly as self.done() cannot
            # be called from within the scope of self.work()
            event.post_event(self._finalise, True)
        else:
            self._do_stage()  # May throw job.JobStalled()
            self.stack.working = time.time()