~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Vincent Ladeuil
  • Date: 2012-03-13 17:25:29 UTC
  • mfrom: (6499 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6501.
  • Revision ID: v.ladeuil+lp@free.fr-20120313172529-i0suyjnepsor25i7
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
but helps protect against colliding host names.
99
99
"""
100
100
 
 
101
from __future__ import absolute_import
 
102
 
101
103
 
102
104
# TODO: We sometimes have the problem that our attempt to rename '1234' to
103
105
# 'held' fails because the transport server moves into an existing directory,
107
109
# the existing locking code and needs a new format of the containing object.
108
110
# -- robertc, mbp 20070628
109
111
 
110
 
import errno
111
112
import os
112
113
import time
113
114
 
137
138
        )
138
139
from bzrlib.trace import mutter, note
139
140
from bzrlib.osutils import format_delta, rand_chars, get_host_name
 
141
from bzrlib.i18n import gettext
140
142
 
141
143
from bzrlib.lazy_import import lazy_import
142
144
lazy_import(globals(), """
295
297
        """
296
298
        if (other_holder is not None):
297
299
            if other_holder.is_lock_holder_known_dead():
298
 
                if self.get_config().get_user_option_as_bool(
299
 
                    'locks.steal_dead',
300
 
                    default=False):
 
300
                if self.get_config().get('locks.steal_dead'):
301
301
                    ui.ui_factory.show_user_warning(
302
302
                        'locks_steal_dead',
303
303
                        lock_url=urlutils.join(self.transport.base, self.path),
318
318
            self.transport.delete(tmpname + self.__INFO_NAME)
319
319
            self.transport.rmdir(tmpname)
320
320
        except PathError, e:
321
 
            note("error removing pending lock: %s", e)
 
321
            note(gettext("error removing pending lock: %s"), e)
322
322
 
323
323
    def _create_pending_dir(self):
324
324
        tmpname = '%s/%s.tmp' % (self.path, rand_chars(10))
613
613
            new_info = self.peek()
614
614
            if new_info is not None and new_info != last_info:
615
615
                if last_info is None:
616
 
                    start = 'Unable to obtain'
 
616
                    start = gettext('Unable to obtain')
617
617
                else:
618
 
                    start = 'Lock owner changed for'
 
618
                    start = gettext('Lock owner changed for')
619
619
                last_info = new_info
620
 
                msg = u'%s lock %s %s.' % (start, lock_url, new_info)
 
620
                msg = gettext('{0} lock {1} {2}.').format(start, lock_url,
 
621
                                                                    new_info)
621
622
                if deadline_str is None:
622
623
                    deadline_str = time.strftime('%H:%M:%S',
623
624
                                                    time.localtime(deadline))
624
625
                if timeout > 0:
625
 
                    msg += ('\nWill continue to try until %s, unless '
626
 
                        'you press Ctrl-C.'
627
 
                        % deadline_str)
628
 
                msg += '\nSee "bzr help break-lock" for more.'
 
626
                    msg += '\n' + gettext(
 
627
                             'Will continue to try until %s, unless '
 
628
                             'you press Ctrl-C.') % deadline_str
 
629
                msg += '\n' + gettext('See "bzr help break-lock" for more.')
629
630
                self._report_function(msg)
630
631
            if (max_attempts is not None) and (attempt_count >= max_attempts):
631
632
                self._trace("exceeded %d attempts")
709
710
        """Get the configuration that governs this lockdir."""
710
711
        # XXX: This really should also use the locationconfig at least, but
711
712
        # that seems a bit hard to hook up at the moment. -- mbp 20110329
712
 
        return config.GlobalConfig()
 
713
        # FIXME: The above is still true ;) -- vila 20110811
 
714
        return config.GlobalStack()
713
715
 
714
716
 
715
717
class LockHeldInfo(object):
733
735
    def __unicode__(self):
734
736
        """Return a user-oriented description of this object."""
735
737
        d = self.to_readable_dict()
736
 
        return (
 
738
        return ( gettext(
737
739
            u'held by %(user)s on %(hostname)s (process #%(pid)s), '
738
 
            u'acquired %(time_ago)s' % d)
 
740
            u'acquired %(time_ago)s') % d)
739
741
 
740
742
    def to_readable_dict(self):
741
743
        """Turn the holder info into a dict of human-readable attributes.