Merge ~cjwatson/launchpad:contrib-glock-print-function into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 97495f9e60cf09d4da4c25f2cf9aa2714596129d
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:contrib-glock-print-function
Merge into: launchpad:master
Diff against target: 102 lines (+19/-16)
1 file modified
lib/contrib/glock.py (+19/-16)
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+380128@code.launchpad.net

Commit message

Port contrib.glock to Python 3 print functions

Description of the change

This is old imported code that doesn't really comply with Launchpad's standards, but for now it's easier to do a basic port than to look for and validate a replacement.

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/contrib/glock.py b/lib/contrib/glock.py
2index 36a3061..e1a7364 100644
3--- a/lib/contrib/glock.py
4+++ b/lib/contrib/glock.py
5@@ -20,6 +20,9 @@ Unix.
6
7 @see: class L{GlobalLock} for more details.
8 '''
9+
10+from __future__ import absolute_import, print_function
11+
12 __version__ = '0.2.' + '$Revision: #5 $'[12:-2]
13 __author__ = 'Richard Gruet', 'rjgruet@yahoo.com'
14 __date__ = '$Date: 2005/06/19 $'[7:-2], '$Author: rgruet $'[9:-2]
15@@ -132,7 +135,7 @@ class GlobalLock:
16 self.acquire()
17
18 def __del__(self):
19- #print '__del__ called' ##
20+ #print('__del__ called') ##
21 try: self.release()
22 except: pass
23 if _windows:
24@@ -185,7 +188,7 @@ class GlobalLock:
25 else:
26 raise GlobalLockError('Cannot acquire lock on "file" '
27 '%s: %s\n' % (self.name, message))
28- #print 'got file lock.' ##
29+ #print('got file lock.') ##
30
31 # Then acquire the local (inter-thread) lock:
32 if not self.threadLock.acquire(blocking):
33@@ -194,7 +197,7 @@ class GlobalLock:
34 'someone else' % self.name)
35 if self.previous_lockfile_present and self.logger:
36 self.logger.warn("Stale lockfile detected and claimed.")
37- #print 'got thread lock.' ##
38+ #print('got thread lock.') ##
39
40 self.is_locked = True
41
42@@ -229,7 +232,7 @@ class GlobalLock:
43 else:
44 try:
45 win32event.ReleaseMutex(self.mutex)
46- #print "released mutex"
47+ #print("released mutex")
48 except pywintypes.error as e:
49 errCode, fctName, errMsg = e.args
50 if errCode == 288:
51@@ -264,7 +267,7 @@ def test():
52 #----------------------------------------------------------------------------
53 ##TODO: a more serious test with distinct processes !
54
55- print 'Testing glock.py...'
56+ print('Testing glock.py...')
57
58 # unfortunately can't test inter-process lock here!
59 lockName = 'myFirstLock'
60@@ -283,31 +286,31 @@ def test():
61 # Check that <> threads of same process do block:
62 import threading, time
63 thread = threading.Thread(target=threadMain, args=(l,))
64- print 'main: locking...',
65+ print('main: locking...', end='')
66 l.acquire()
67- print ' done.'
68+ print(' done.')
69 thread.start()
70 time.sleep(3)
71- print '\nmain: unlocking...',
72+ print('\nmain: unlocking...', end='')
73 l.release()
74- print ' done.'
75+ print(' done.')
76 time.sleep(0.1)
77
78- print '=> Test of glock.py passed.'
79+ print('=> Test of glock.py passed.')
80 return l
81
82 def threadMain(lock):
83- print 'thread started(%s).' % lock
84+ print('thread started(%s).' % lock)
85 try: lock.acquire(blocking=False)
86 except LockAlreadyAcquired: pass
87 else: raise Exception('should have raised LockAlreadyAcquired')
88- print 'thread: locking (should stay blocked for ~ 3 sec)...',
89+ print('thread: locking (should stay blocked for ~ 3 sec)...', end='')
90 lock.acquire()
91- print 'thread: locking done.'
92- print 'thread: unlocking...',
93+ print('thread: locking done.')
94+ print('thread: unlocking...', end='')
95 lock.release()
96- print ' done.'
97- print 'thread ended.'
98+ print(' done.')
99+ print('thread ended.')
100
101 #----------------------------------------------------------------------------
102 # M A I N

Subscribers

People subscribed via source and target branches

to status/vote changes: