Merge lp:~gz/brz/py3_lockdir into lp:brz

Proposed by Martin Packman on 2017-06-16
Status: Merged
Approved by: Martin Packman on 2017-06-17
Approved revision: 6703
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~gz/brz/py3_lockdir
Merge into: lp:brz
Diff against target: 120 lines (+29/-13)
2 files modified
breezy/lockdir.py (+22/-9)
breezy/tests/test_lockdir.py (+7/-4)
To merge this branch: bzr merge lp:~gz/brz/py3_lockdir
Reviewer Review Type Date Requested Status
Jelmer Vernooij 2017-06-16 Approve on 2017-06-17
Review via email: mp+325879@code.launchpad.net

Commit Message

Make lockdir module Python 3 compatible

Description of the Change

Fixes the lockdir module and tests. Not totally sure about the __eq__ __ne__ implementations but seems to be all that's needed.

To post a comment you must log in.
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/lockdir.py'
2--- breezy/lockdir.py 2017-05-22 00:56:52 +0000
3+++ breezy/lockdir.py 2017-06-16 23:18:17 +0000
4@@ -136,9 +136,13 @@
5 ResourceBusy,
6 TransportError,
7 )
8+from .i18n import gettext
9+from .osutils import format_delta, rand_chars, get_host_name
10+from .sixish import (
11+ PY3,
12+ text_type,
13+ )
14 from .trace import mutter, note
15-from .osutils import format_delta, rand_chars, get_host_name
16-from .i18n import gettext
17
18 from .lazy_import import lazy_import
19 lazy_import(globals(), """
20@@ -301,7 +305,7 @@
21 ui.ui_factory.show_user_warning(
22 'locks_steal_dead',
23 lock_url=urlutils.join(self.transport.base, self.path),
24- other_holder_info=unicode(other_holder))
25+ other_holder_info=text_type(other_holder))
26 self.force_break(other_holder)
27 self._trace("stole lock from dead holder")
28 return
29@@ -408,7 +412,7 @@
30 if ui.ui_factory.confirm_action(
31 u"Break %(lock_info)s",
32 'breezy.lockdir.break',
33- dict(lock_info=unicode(holder_info))):
34+ dict(lock_info=text_type(holder_info))):
35 result = self.force_break(holder_info)
36 ui.ui_factory.show_message(
37 "Broke lock %s" % result.lock_url)
38@@ -739,6 +743,9 @@
39 u'held by %(user)s on %(hostname)s (process #%(pid)s), '
40 u'acquired %(time_ago)s') % d)
41
42+ if PY3:
43+ __str__ = __unicode__
44+
45 def to_readable_dict(self):
46 """Turn the holder info into a dict of human-readable attributes.
47
48@@ -804,11 +811,17 @@
49 else:
50 return cls(stanza.as_dict())
51
52- def __cmp__(self, other):
53- """Value comparison of lock holders."""
54- return (
55- cmp(type(self), type(other))
56- or cmp(self.info_dict, other.info_dict))
57+ def __hash__(self):
58+ return id(self)
59+
60+ def __eq__(self, other):
61+ """Equality check for lock holders."""
62+ if type(self) != type(other):
63+ return False
64+ return self.info_dict == other.info_dict
65+
66+ def __ne__(self, other):
67+ return not self == other
68
69 def is_locked_by_this_process(self):
70 """True if this process seems to be the current lock holder."""
71
72=== modified file 'breezy/tests/test_lockdir.py'
73--- breezy/tests/test_lockdir.py 2017-05-22 00:56:52 +0000
74+++ breezy/tests/test_lockdir.py 2017-06-16 23:18:17 +0000
75@@ -40,6 +40,9 @@
76 LockDir,
77 LockHeldInfo,
78 )
79+from ..sixish import (
80+ text_type,
81+ )
82 from . import (
83 features,
84 TestCase,
85@@ -346,7 +349,7 @@
86 ld2 = self.get_lock()
87 ld.create()
88 ld.lock_write()
89- ld.transport.put_bytes_non_atomic('test_lock/held/info', '\0')
90+ ld.transport.put_bytes_non_atomic('test_lock/held/info', b'\0')
91
92 class LoggingUIFactory(breezy.ui.SilentUIFactory):
93 def __init__(self):
94@@ -508,7 +511,7 @@
95 t = self.get_transport()
96 t.mkdir('test_lock')
97 t.mkdir('test_lock/held')
98- t.put_bytes('test_lock/held/info', '')
99+ t.put_bytes('test_lock/held/info', b'')
100 lf = LockDir(t, 'test_lock')
101 info = lf.peek()
102 formatted_info = info.to_readable_dict()
103@@ -526,7 +529,7 @@
104 t = self.get_transport()
105 t.mkdir('test_lock')
106 t.mkdir('test_lock/held')
107- t.put_bytes('test_lock/held/info', '\0')
108+ t.put_bytes('test_lock/held/info', b'\0')
109 lf = LockDir(t, 'test_lock')
110 self.assertRaises(errors.LockCorrupt, lf.peek)
111 # Currently attempt_lock gives LockContention, but LockCorrupt would be
112@@ -665,7 +668,7 @@
113
114 def test_unicode(self):
115 info = LockHeldInfo.for_this_process(None)
116- self.assertContainsRe(unicode(info),
117+ self.assertContainsRe(text_type(info),
118 r'held by .* on .* \(process #\d+\), acquired .* ago')
119
120 def test_is_locked_by_this_process(self):

Subscribers

People subscribed via source and target branches