/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Martin Pool
  • Date: 2010-09-14 06:46:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5426.
  • Revision ID: mbp@sourcefrog.net-20100914064618-1b05bktzv3513mx0
Add ConfirmationUserInterfacePolicy that lets specific confirmations be configured off.

Show diffs side-by-side

added added

removed removed

Lines of Context:
151
151
# files/dirs created.
152
152
 
153
153
 
154
 
_DEFAULT_TIMEOUT_SECONDS = 300
 
154
_DEFAULT_TIMEOUT_SECONDS = 30
155
155
_DEFAULT_POLL_SECONDS = 1.0
156
156
 
157
157
 
243
243
        # have a similar bug allowing someone to think they got the lock
244
244
        # when it's already held.
245
245
        #
246
 
        # See <https://bugs.edge.launchpad.net/bzr/+bug/498378> for one case.
 
246
        # See <https://bugs.launchpad.net/bzr/+bug/498378> for one case.
247
247
        #
248
248
        # Strictly the check is unnecessary and a waste of time for most
249
249
        # people, but probably worth trapping if something is wrong.
351
351
        holder_info = self.peek()
352
352
        if holder_info is not None:
353
353
            lock_info = '\n'.join(self._format_lock_info(holder_info))
354
 
            if bzrlib.ui.ui_factory.get_boolean("Break %s" % lock_info):
 
354
            if bzrlib.ui.ui_factory.confirm_action(
 
355
                "Break %(lock_info)s", 'bzrlib.lockdir.break', 
 
356
                dict(lock_info=lock_info)):
355
357
                self.force_break(holder_info)
356
358
 
357
359
    def force_break(self, dead_holder_info):
447
449
        # XXX: is creating this here inefficient?
448
450
        config = bzrlib.config.GlobalConfig()
449
451
        try:
450
 
            user = config.user_email()
451
 
        except errors.NoEmailInUsername:
452
452
            user = config.username()
 
453
        except errors.NoWhoami:
 
454
            user = osutils.getuser_unicode()
453
455
        s = rio.Stanza(hostname=get_host_name(),
454
456
                   pid=str(os.getpid()),
455
457
                   start_time=str(int(time.time())),
539
541
                if deadline_str is None:
540
542
                    deadline_str = time.strftime('%H:%M:%S',
541
543
                                                 time.localtime(deadline))
 
544
                # As local lock urls are correct we display them.
 
545
                # We avoid displaying remote lock urls.
542
546
                lock_url = self.transport.abspath(self.path)
543
 
                # See <https://bugs.edge.launchpad.net/bzr/+bug/250451>
544
 
                # the URL here is sometimes not one that is useful to the
545
 
                # user, perhaps being wrapped in a lp-%d or chroot decorator,
546
 
                # especially if this error is issued from the server.
547
 
                self._report_function('%s %s\n'
548
 
                    '%s\n' # held by
549
 
                    '%s\n' # locked ... ago
550
 
                    'Will continue to try until %s, unless '
551
 
                    'you press Ctrl-C.\n'
552
 
                    'See "bzr help break-lock" for more.',
553
 
                    start,
554
 
                    formatted_info[0],
555
 
                    formatted_info[1],
556
 
                    formatted_info[2],
557
 
                    deadline_str,
558
 
                    )
559
 
 
 
547
                if lock_url.startswith('file://'):
 
548
                    lock_url = lock_url.split('.bzr/')[0]
 
549
                else:
 
550
                    lock_url = ''
 
551
                user, hostname, pid, time_ago = formatted_info
 
552
                msg = ('%s lock %s '        # lock_url
 
553
                    'held by '              # start
 
554
                    '%s\n'                  # user
 
555
                    'at %s '                # hostname
 
556
                    '[process #%s], '       # pid
 
557
                    'acquired %s.')         # time ago
 
558
                msg_args = [start, lock_url, user, hostname, pid, time_ago]
 
559
                if timeout > 0:
 
560
                    msg += ('\nWill continue to try until %s, unless '
 
561
                        'you press Ctrl-C.')
 
562
                    msg_args.append(deadline_str)
 
563
                msg += '\nSee "bzr help break-lock" for more.'
 
564
                self._report_function(msg, *msg_args)
560
565
            if (max_attempts is not None) and (attempt_count >= max_attempts):
561
566
                self._trace("exceeded %d attempts")
562
567
                raise LockContention(self)
564
569
                self._trace("waiting %ss", poll)
565
570
                time.sleep(poll)
566
571
            else:
 
572
                # As timeout is always 0 for remote locks
 
573
                # this block is applicable only for local
 
574
                # lock contention
567
575
                self._trace("timeout after waiting %ss", timeout)
568
 
                raise LockContention(self)
 
576
                raise LockContention('(local)', lock_url)
569
577
 
570
578
    def leave_in_place(self):
571
579
        self._locked_via_token = True
616
624
 
617
625
    def _format_lock_info(self, info):
618
626
        """Turn the contents of peek() into something for the user"""
619
 
        lock_url = self.transport.abspath(self.path)
620
627
        start_time = info.get('start_time')
621
628
        if start_time is None:
622
629
            time_ago = '(unknown)'
623
630
        else:
624
631
            time_ago = format_delta(time.time() - int(info['start_time']))
 
632
        user = info.get('user', '<unknown>')
 
633
        hostname = info.get('hostname', '<unknown>')
 
634
        pid = info.get('pid', '<unknown>')
625
635
        return [
626
 
            'lock %s' % (lock_url,),
627
 
            'held by %s on host %s [process #%s]' %
628
 
                tuple([info.get(x, '<unknown>') for x in ['user', 'hostname', 'pid']]),
629
 
            'locked %s' % (time_ago,),
 
636
            user,
 
637
            hostname,
 
638
            pid,
 
639
            time_ago,
630
640
            ]
631
641
 
632
642
    def validate_token(self, token):