/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: Parth Malwankar
  • Date: 2010-06-11 07:56:46 UTC
  • mto: This revision was merged to the branch mainline in revision 5303.
  • Revision ID: parth.malwankar@gmail.com-20100611075646-9yyeih46ken6yagd
fixed tests. closed review comments by mgz.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
447
447
        # XXX: is creating this here inefficient?
448
448
        config = bzrlib.config.GlobalConfig()
449
449
        try:
450
 
            user = config.user_email()
451
 
        except errors.NoEmailInUsername:
452
450
            user = config.username()
 
451
        except errors.NoWhoami:
 
452
            user = osutils.getuser_unicode()
453
453
        s = rio.Stanza(hostname=get_host_name(),
454
454
                   pid=str(os.getpid()),
455
455
                   start_time=str(int(time.time())),
539
539
                if deadline_str is None:
540
540
                    deadline_str = time.strftime('%H:%M:%S',
541
541
                                                 time.localtime(deadline))
542
 
                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
 
 
 
542
                user, hostname, pid, time_ago = formatted_info
 
543
                msg = ('%s lock held by '   # start
 
544
                    '%s\n'                  # user
 
545
                    'at %s '                # hostname
 
546
                    '[process #%s], '       # pid
 
547
                    'acquired %s.')         # time ago
 
548
                msg_args = [start, user, hostname, pid, time_ago]
 
549
                if timeout > 0:
 
550
                    msg += ('\nWill continue to try until %s, unless '
 
551
                        'you press Ctrl-C.')
 
552
                    msg_args.append(deadline_str)
 
553
                msg += '\nSee "bzr help break-lock" for more.'
 
554
                self._report_function(msg, *msg_args)
560
555
            if (max_attempts is not None) and (attempt_count >= max_attempts):
561
556
                self._trace("exceeded %d attempts")
562
557
                raise LockContention(self)
616
611
 
617
612
    def _format_lock_info(self, info):
618
613
        """Turn the contents of peek() into something for the user"""
619
 
        lock_url = self.transport.abspath(self.path)
620
614
        start_time = info.get('start_time')
621
615
        if start_time is None:
622
616
            time_ago = '(unknown)'
623
617
        else:
624
618
            time_ago = format_delta(time.time() - int(info['start_time']))
 
619
        user = info.get('user', '<unknown>')
 
620
        hostname = info.get('hostname', '<unknown>')
 
621
        pid = info.get('pid', '<unknown>')
625
622
        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,),
 
623
            user,
 
624
            hostname,
 
625
            pid,
 
626
            time_ago,
630
627
            ]
631
628
 
632
629
    def validate_token(self, token):