Lines Matching defs:Lock
4 """Script to lock/unlock machines."""
60 """The description of the lock."""
88 """File lock operation class."""
139 with file_lock as lock:
140 if lock.IsLocked():
189 class Lock(object):
190 """Lock class"""
199 with FileLock(self._lock_file) as lock:
200 if lock.exclusive:
202 'Exclusive lock already acquired by %s. Reason: %s' %
203 (lock.owner, lock.reason))
207 if lock.counter:
208 self._logger.LogError('Shared lock already acquired')
214 lock.exclusive = True
215 lock.reason = reason
216 lock.owner = getpass.getuser()
217 lock.time = time.time()
218 lock.auto = self._auto
220 lock.counter += 1
225 with FileLock(self._lock_file) as lock:
226 if not lock.IsLocked():
230 if lock.exclusive != exclusive:
234 if lock.exclusive:
235 if lock.owner != getpass.getuser() and not force:
236 self._logger.LogError("%s can't unlock lock owned by: %s" %
237 (getpass.getuser(), lock.owner))
239 if lock.auto != self._auto:
240 self._logger.LogError("Can't unlock lock with different -a"
243 lock.exclusive = False
244 lock.reason = ''
245 lock.owner = ''
260 lock.counter -= 1
278 def Lock(self, exclusive=False, reason=''):
279 lock = Lock(self._full_name, self._auto)
280 return lock.NonBlockingLock(exclusive, reason)
286 locked = self.Lock(exclusive, reason)
289 print('Lock not acquired for {0}, wait {1} seconds ...'.format(
297 lock = Lock(self._full_name, self._auto)
298 return lock.Unlock(exclusive, ignore_ownership)
309 help='The lock reason.')
327 help="Use this to force unlock on a lock you don't own.")
333 help='Use this for a shared (non-exclusive) lock.')
363 retval = machine.Lock(exclusive, options.reason)