Esempio n. 1
0
def uisetup(ui):
    progressfile = ui.config("progress", "statefile")
    append = ui.configbool("progress", "statefileappend", False)
    filemode = "a+" if append else "w+"
    if progressfile:
        global _pid
        _pid = ui.configint("progress", "fakedpid") or util.getpid()

        def wrapengine(orig):
            origengine = progress._engine
            currentengine = orig()
            if origengine != currentengine or not getattr(
                currentengine, "_filewrapped", False
            ):

                class fileengine(currentengine.__class__):
                    def _show(self, now):
                        super(fileengine, self)._show(now)
                        writeprogress(self, progressfile, filemode, self._bars)

                    def _complete(self):
                        super(fileengine, self)._complete()
                        writeprogress(self, progressfile, filemode, [])

                currentengine.__class__ = fileengine
                currentengine._filewrapped = True
            return currentengine

        wrapfunction(progress, "getengine", wrapengine)
Esempio n. 2
0
def uisetup(ui):
    progressfile = ui.config("progress", "statefile")
    append = ui.configbool("progress", "statefileappend", False)
    filemode = "a+" if append else "w+"
    if progressfile:
        global _pid
        _pid = ui.configint("progress", "fakedpid") or util.getpid()

        class fileengine(progress._engine.__class__):
            def _show(self, now):
                super(fileengine, self)._show(now)
                writeprogress(self, progressfile, filemode, self._bars)

            def _complete(self):
                super(fileengine, self)._complete()
                writeprogress(self, progressfile, filemode, [])

        progress._engine.__class__ = fileengine
Esempio n. 3
0
        def log(self, event, *msg, **opts):
            global lastui
            super(blackboxui, self).log(event, *msg, **opts)

            if not "*" in self.track and not event in self.track:
                return

            if not msg or not msg[0]:
                return

            if self._bbvfs:
                ui = self
            else:
                # certain ui instances exist outside the context of
                # a repo, so just default to the last blackbox that
                # was seen.
                ui = lastui()

            if not ui:
                return
            vfs = ui._bbvfs
            if not vfs:
                return

            repo = getattr(ui, "_bbrepo", lambda: None)()
            if not lastui() or repo:
                lastui = weakref.ref(ui)
            if getattr(ui, "_bbinlog", False):
                # recursion and failure guard
                return
            ui._bbinlog = True
            default = self.configdate("devel", "default-date")
            date = util.datestr(default, "%Y/%m/%d %H:%M:%S")
            user = util.getuser()
            pid = "%d" % util.getpid()
            if len(msg) == 1:
                # Don't even try to format the string if there is only one
                # argument.
                formattedmsg = msg[0]
            else:
                try:
                    formattedmsg = msg[0] % msg[1:]
                except TypeError:
                    # If fails with `TypeError: not enough arguments for format
                    # string`, concatenate the arguments gracefully.
                    formattedmsg = " ".join(msg)
            rev = "(unknown)"
            changed = ""
            # Only log the current commit if the changelog has already been
            # loaded.
            if repo and "changelog" in repo.__dict__:
                try:
                    ctx = repo[None]
                    parents = ctx.parents()
                    rev = "+".join([hex(p.node()) for p in parents])
                except Exception:
                    # This can happen if the dirstate file is sufficiently
                    # corrupt that we can't extract the parents. In that case,
                    # just don't set the rev.
                    pass
                if ui.configbool("blackbox", "dirty") and ctx.dirty(
                        missing=True, merge=False, branch=False):
                    changed = "+"
            if ui.configbool("blackbox", "logsource"):
                src = " [%s]" % event
            else:
                src = ""
            requestid = ui.environ.get("HGREQUESTID") or ""
            if requestid:
                src += "[%s]" % requestid
            try:
                fmt = "%s %s @%s%s (%s)%s> %s"
                args = (date, user, rev, changed, pid, src, formattedmsg)
                with _openlogfile(ui, vfs) as fp:
                    line = fmt % args
                    if not line.endswith("\n"):
                        line += "\n"
                    fp.write(encodeutf8(line))
            except (IOError, OSError) as err:
                self.debug("warning: cannot write to blackbox.log: %s\n" %
                           err.strerror)
                # do not restore _bbinlog intentionally to avoid failed
                # logging again
            else:
                ui._bbinlog = False