hgext/progress.py
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
Sat, 13 Feb 2010 09:55:28 +0100
changeset 10439 509f4ed56509
parent 10434 ad104a786d35
child 10441 dc0d1ca2d378
permissions -rw-r--r--
progress: correctly handle empty progress topic
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10434
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
     1
# progress.py show progress bars for some actions
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
     2
#
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
     3
# Copyright (C) 2010 Augie Fackler <durin42@gmail.com>
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
     4
#
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
     5
# This program is free software; you can redistribute it and/or modify it
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
     6
# under the terms of the GNU General Public License as published by the
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
     7
# Free Software Foundation; either version 2 of the License, or (at your
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
     8
# option) any later version.
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
     9
#
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    10
# This program is distributed in the hope that it will be useful, but
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    11
# WITHOUT ANY WARRANTY; without even the implied warranty of
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    13
# Public License for more details.
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    14
#
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    15
# You should have received a copy of the GNU General Public License along
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    16
# with this program; if not, write to the Free Software Foundation, Inc.,
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    18
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    19
"""show progress bars for some actions
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    20
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    21
This extension uses the progress information commands can log with hg
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    22
to draw progres bars that are as informative as possible. Some progress
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    23
bars only offer indeterminate information, while others have a definite
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    24
end point.
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    25
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    26
The following settings are available::
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    27
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    28
  [progress]
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    29
  delay = 3 # number of seconds (float) before showing the progress bar
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    30
  refresh = 0.1 # time in seconds between refreshes of the progress bar
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    31
  format = topic bar number # format of the progress bar
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    32
  width = <none> # if set, the maximum width of the progress information
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    33
                 # (that is, min(width, term width) will be used)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    34
  clear-complete = True # clear the progress bar after it's done
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    35
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    36
Valid entries for the format field are topic, bar, number, unit, and item.
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    37
item defaults to the last 20 characters of the item, but this can be
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    38
changed by adding either -<num> which would take the last num characters,
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    39
or +<num> for the first num characters.
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    40
"""
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    41
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    42
import math
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    43
import sys
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    44
import time
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    45
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    46
from mercurial import extensions
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    47
from mercurial import util
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    48
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    49
def spacejoin(*args):
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    50
    ret = ''
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    51
    for s in args:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    52
        if s:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    53
            if ret:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    54
                ret += ' '
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    55
            ret += s
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    56
    return ret
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    57
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    58
class progbar(object):
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    59
    def __init__(self, ui):
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    60
        self.ui = ui
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    61
        self.resetstate()
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    62
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    63
    def resetstate(self):
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    64
        self.topics = []
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    65
        self.printed = False
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    66
        self.lastprint = time.time() + float(self.ui.config(
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    67
            'progress', 'delay', default=3))
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    68
        self.indetcount = 0
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    69
        self.refresh = float(self.ui.config(
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    70
            'progress', 'refresh', default=0.1))
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    71
        self.order = self.ui.configlist(
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    72
            'progress', 'format',
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    73
            default=['topic', 'bar', 'number'])
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    74
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    75
    def show(self, topic, pos, item, unit, total):
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    76
        termwidth = self.width()
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    77
        self.printed = True
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    78
        head = ''
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    79
        needprogress = False
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    80
        tail = ''
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    81
        for indicator in self.order:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    82
            add = ''
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    83
            if indicator == 'topic':
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    84
                add = topic
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    85
            elif indicator == 'number':
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    86
                if total:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    87
                    add = ('% ' + str(len(str(total))) +
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    88
                           's/%s') % (pos, total)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    89
                else:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    90
                    add = str(pos)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    91
            elif indicator.startswith('item') and item:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    92
                slice = 'end'
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    93
                if '-' in indicator:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    94
                    wid = int(indicator.split('-')[1])
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    95
                elif '+' in indicator:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    96
                    slice = 'beginning'
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    97
                    wid = int(indicator.split('+')[1])
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    98
                else:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
    99
                    wid = 20
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   100
                if slice == 'end':
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   101
                    add = item[-wid:]
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   102
                else:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   103
                    add = item[:wid]
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   104
                add += (wid - len(add)) * ' '
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   105
            elif indicator == 'bar':
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   106
                add = ''
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   107
                needprogress = True
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   108
            elif indicator == 'unit' and unit:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   109
                add = unit
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   110
            if not needprogress:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   111
                head = spacejoin(head, add)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   112
            else:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   113
                tail = spacejoin(add, tail)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   114
        if needprogress:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   115
            used = 0
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   116
            if head:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   117
                used += len(head) + 1
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   118
            if tail:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   119
                used += len(tail) + 1
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   120
            progwidth = termwidth - used - 3
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   121
            if total:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   122
                amt = pos * progwidth // total
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   123
                bar = '=' * (amt) + ' ' * (progwidth - amt)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   124
            else:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   125
                progwidth -= 3
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   126
                self.indetcount += 1
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   127
                # mod the count by twice the width so we can make the
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   128
                # cursor bounce between the right and left sides
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   129
                amt = self.indetcount % (2 * progwidth)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   130
                amt -= progwidth
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   131
                bar = (' ' * int(progwidth - abs(amt)) + '<=>' +
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   132
                       ' ' * int(abs(amt)))
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   133
            prog = ''.join(('[', bar , ']'))
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   134
            out = spacejoin(head, prog, tail)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   135
        else:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   136
            out = spacejoin(head, tail)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   137
        sys.stdout.write('\r' + out[:termwidth])
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   138
        sys.stdout.flush()
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   139
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   140
    def clear(self):
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   141
        sys.stdout.write('\r%s\r' % (' ' * self.width()))
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   142
10439
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   143
    def complete(self):
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   144
        if self.ui.configbool('progress', 'clear-complete', default=True):
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   145
            self.clear()
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   146
        else:
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   147
            sys.stdout.write('\n')
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   148
        sys.stdout.flush()
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   149
10434
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   150
    def width(self):
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   151
        tw = util.termwidth()
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   152
        return min(int(self.ui.config('progress', 'width', default=tw)), tw)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   153
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   154
    def progress(self, orig, topic, pos, item='', unit='', total=None):
10439
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   155
        if pos is None:
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   156
            if self.topics and self.topics[-1] == topic and self.printed:
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   157
                self.complete()
10434
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   158
            self.resetstate()
10439
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   159
        else:
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   160
            if topic not in self.topics:
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   161
                self.topics.append(topic)
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   162
            now = time.time()
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   163
            if now - self.lastprint > 0.1 and topic == self.topics[-1]:
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   164
                self.lastprint = now
509f4ed56509 progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10434
diff changeset
   165
                self.show(topic, pos, item, unit, total)
10434
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   166
        return orig(topic, pos, item=item, unit=unit, total=total)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   167
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   168
    def write(self, orig, *args):
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   169
        if self.printed:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   170
            self.clear()
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   171
        return orig(*args)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   172
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   173
sharedprog = None
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   174
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   175
def uisetup(ui):
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   176
    if ui.interactive() and not ui.debugflag:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   177
        # we instantiate one globally shared progress bar to avoid
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   178
        # competing progress bars when multiple UI objects get created
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   179
        global sharedprog
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   180
        if not sharedprog:
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   181
            sharedprog = progbar(ui)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   182
        extensions.wrapfunction(ui, 'progress', sharedprog.progress)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   183
        extensions.wrapfunction(ui, 'write', sharedprog.write)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   184
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   185
def reposetup(ui, repo):
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
   186
    uisetup(repo.ui)