Ejemplo n.º 1
0
 def grabOutput(self, flag):
     if flag:
         if not self.rpmout:
             # Grab rpm output, but not the python one.
             self.stdout = sys.stdout
             self.stderr = sys.stderr
             writer = codecs.getwriter(ENCODING)
             reader = codecs.getreader(ENCODING)
             sys.stdout = writer(os.fdopen(os.dup(1), "w"))
             sys.stderr = writer(os.fdopen(os.dup(2), "w"))
             pipe = os.pipe()
             os.dup2(pipe[1], 1)
             os.dup2(pipe[1], 2)
             os.close(pipe[1])
             self.rpmout = reader(os.fdopen(pipe[0], "r"))
             setCloseOnExec(self.rpmout.fileno())
             flags = fcntl.fcntl(self.rpmout.fileno(), fcntl.F_GETFL, 0)
             flags |= os.O_NONBLOCK
             fcntl.fcntl(self.rpmout.fileno(), fcntl.F_SETFL, flags)
     else:
         if self.rpmout:
             self._rpmout()
             os.dup2(sys.stdout.fileno(), 1)
             os.dup2(sys.stderr.fileno(), 2)
             sys.stdout = self.stdout
             sys.stderr = self.stderr
             del self.stdout
             del self.stderr
             self.rpmout.close()
             self.rpmout = None
Ejemplo n.º 2
0
 def grabOutput(self, flag):
     if flag:
         if not self.rpmout:
             # Grab rpm output, but not the python one.
             self.stdout = sys.stdout
             self.stderr = sys.stderr
             writer = codecs.getwriter(ENCODING)
             reader = codecs.getreader(ENCODING)
             sys.stdout = writer(os.fdopen(os.dup(1), "w"))
             sys.stderr = writer(os.fdopen(os.dup(2), "w"))
             pipe = os.pipe()
             os.dup2(pipe[1], 1)
             os.dup2(pipe[1], 2)
             os.close(pipe[1])
             self.rpmout = reader(os.fdopen(pipe[0], "r"))
             setCloseOnExec(self.rpmout.fileno())
             flags = fcntl.fcntl(self.rpmout.fileno(), fcntl.F_GETFL, 0)
             flags |= os.O_NONBLOCK
             fcntl.fcntl(self.rpmout.fileno(), fcntl.F_SETFL, flags)
     else:
         if self.rpmout:
             self._rpmout()
             os.dup2(sys.stdout.fileno(), 1)
             os.dup2(sys.stderr.fileno(), 2)
             sys.stdout = self.stdout
             sys.stderr = self.stderr
             del self.stdout
             del self.stderr
             self.rpmout.close()
             self.rpmout = None
Ejemplo n.º 3
0
    def __call__(self, what, amount, total, infopath, data):

        self._rpmout()

        if what == rpm.RPMCALLBACK_INST_OPEN_FILE:
            info, path = infopath
            pkgstr = str(info.getPackage())
            iface.debug(_("Processing %s in %s") % (pkgstr, path))
            self.topic = _("Output from %s:") % pkgstr
            self.fd = os.open(path, os.O_RDONLY)
            setCloseOnExec(self.fd)
            return self.fd

        elif what == rpm.RPMCALLBACK_INST_CLOSE_FILE:
            if self.fd is not None:
                os.close(self.fd)
                self.fd = None

        elif what == rpm.RPMCALLBACK_INST_START:
            info, path = infopath
            pkg = info.getPackage()
            self.data["item-number"] += 1
            self.prog.add(1)
            self.prog.setSubTopic(infopath, _("Installing %s") % pkg.name)
            self.prog.setSub(infopath, 0, 1, subdata=self.data)
            self.prog.show()

        elif (what == rpm.RPMCALLBACK_TRANS_PROGRESS
              or what == rpm.RPMCALLBACK_INST_PROGRESS):
            self.prog.setSub(infopath or "trans",
                             amount,
                             total,
                             subdata=self.data)
            self.prog.show()

        elif what == rpm.RPMCALLBACK_TRANS_START:
            self.prog.setSubTopic("trans", _("Preparing..."))
            self.prog.setSub("trans", 0, 1)
            self.prog.show()

        elif what == rpm.RPMCALLBACK_TRANS_STOP:
            self.prog.setSubDone("trans")
            self.prog.show()

        elif what == rpm.RPMCALLBACK_UNINST_START:
            self.topic = _("Output from %s:") % infopath
            subkey = "R*" + infopath
            self.data["item-number"] += 1
            self.prog.add(1)
            if infopath in self.upgradednames:
                topic = _("Cleaning %s") % infopath
            else:
                topic = _("Removing %s") % infopath
            self.prog.setSubTopic(subkey, topic)
            self.prog.setSub(subkey, 0, 1, subdata=self.data)
            self.prog.show()

        elif what == rpm.RPMCALLBACK_UNINST_STOP:
            self.topic = None
            subkey = "R*" + infopath
            if not self.prog.getSub(subkey):
                self.data["item-number"] += 1
                self.prog.add(1)
                if infopath in self.upgradednames:
                    topic = _("Cleaning %s") % infopath
                else:
                    topic = _("Removing %s") % infopath
                self.prog.setSubTopic(subkey, topic)
                self.prog.setSub(subkey, 1, 1, subdata=self.data)
            else:
                self.prog.setSubDone(subkey)
            self.prog.show()
Ejemplo n.º 4
0
    def __call__(self, what, amount, total, infopath, data):

        self._rpmout()

        if what == rpm.RPMCALLBACK_INST_OPEN_FILE:
            info, path = infopath
            pkgstr = str(info.getPackage())
            iface.debug(_("Processing %s in %s") % (pkgstr, path))
            self.topic = _("Output from %s:") % pkgstr
            self.fd = os.open(path, os.O_RDONLY)
            setCloseOnExec(self.fd)
            return self.fd
        
        elif what == rpm.RPMCALLBACK_INST_CLOSE_FILE:
            if self.fd is not None:
                os.close(self.fd)
                self.fd = None

        elif what == rpm.RPMCALLBACK_INST_START:
            info, path = infopath
            pkg = info.getPackage()
            self.data["item-number"] += 1
            self.prog.add(1)
            self.prog.setSubTopic(infopath, _("Installing %s") % pkg.name)
            self.prog.setSub(infopath, 0, 1, subdata=self.data)
            self.prog.show()

        elif (what == rpm.RPMCALLBACK_TRANS_PROGRESS or
              what == rpm.RPMCALLBACK_INST_PROGRESS):
            self.prog.setSub(infopath or "trans", amount, total,
                             subdata=self.data)
            self.prog.show()

        elif what == rpm.RPMCALLBACK_TRANS_START:
            self.prog.setSubTopic("trans", _("Preparing..."))
            self.prog.setSub("trans", 0, 1)
            self.prog.show()

        elif what == rpm.RPMCALLBACK_TRANS_STOP:
            self.prog.setSubDone("trans")
            self.prog.show()

        elif what == rpm.RPMCALLBACK_UNINST_START:
            self.topic = _("Output from %s:") % infopath
            subkey =  "R*"+infopath
            self.data["item-number"] += 1
            self.prog.add(1)
            if infopath in self.upgradednames:
                topic = _("Cleaning %s") % infopath
            else:
                topic = _("Removing %s") % infopath
            self.prog.setSubTopic(subkey, topic)
            self.prog.setSub(subkey, 0, 1, subdata=self.data)
            self.prog.show()

        elif what == rpm.RPMCALLBACK_UNINST_STOP:
            self.topic = None
            subkey = "R*"+infopath
            if not self.prog.getSub(subkey):
                self.data["item-number"] += 1
                self.prog.add(1)
                if infopath in self.upgradednames:
                    topic = _("Cleaning %s") % infopath
                else:
                    topic = _("Removing %s") % infopath
                self.prog.setSubTopic(subkey, topic)
                self.prog.setSub(subkey, 1, 1, subdata=self.data)
            else:
                self.prog.setSubDone(subkey)
            self.prog.show()