diff options
author | Zhizhou Yang <zhizhouy@google.com> | 2017-07-21 16:06:55 -0700 |
---|---|---|
committer | Zhizhou Yang <zhizhouy@google.com> | 2017-07-21 16:10:53 -0700 |
commit | 4307f4735e9a4e3189e8d43f7493bb677a4d06ba (patch) | |
tree | bf139ee25415cecde142e95791edba3803b2452a /file_lock_machine.py | |
parent | 7091edfaa0ec531905b7d914e9307cd74caf02ea (diff) | |
parent | 978b96a8b02935d40e3a2c57cd033dbedd8980e9 (diff) | |
download | toolchain-utils-android-o-iot-preview-5.tar.gz |
Merge branch 'aosp/mirror-chromium-master' into update_utilsandroid-o-iot-preview-5o-iot-preview-5
Update toolchain_utils from ChromeOS side, which includes: initializing
Android toolchain benchmark suite and other changes since last merging.
Bug: None.
Test: None.
Change-Id: I9cd74f4377a8109872414636342be0b9f5df2db5
Diffstat (limited to 'file_lock_machine.py')
-rwxr-xr-x | file_lock_machine.py | 101 |
1 files changed, 52 insertions, 49 deletions
diff --git a/file_lock_machine.py b/file_lock_machine.py index 9b1d3367..8493b082 100755 --- a/file_lock_machine.py +++ b/file_lock_machine.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/env python2 # # Copyright 2010 Google Inc. All Rights Reserved. """Script to lock/unlock machines.""" @@ -79,9 +79,11 @@ class LockDescription(object): return self.counter or self.exclusive def __str__(self): - return ' '.join(['Owner: %s' % self.owner, 'Exclusive: %s' % self.exclusive, - 'Counter: %s' % self.counter, 'Time: %s' % self.time, - 'Reason: %s' % self.reason, 'Auto: %s' % self.auto]) + return ' '.join([ + 'Owner: %s' % self.owner, 'Exclusive: %s' % self.exclusive, + 'Counter: %s' % self.counter, 'Time: %s' % self.time, + 'Reason: %s' % self.reason, 'Auto: %s' % self.auto + ]) class FileLock(object): @@ -120,9 +122,8 @@ class FileLock(object): (os.path.basename(file_lock.getFilePath), file_lock.getDescription().owner, file_lock.getDescription().exclusive, - file_lock.getDescription().counter, - elapsed_time, file_lock.getDescription().reason, - file_lock.getDescription().auto)) + file_lock.getDescription().counter, elapsed_time, + file_lock.getDescription().reason, file_lock.getDescription().auto)) table = '\n'.join(lock_strings) return '\n'.join([header, table]) @@ -199,8 +200,8 @@ class Lock(object): with FileLock(self._lock_file) as lock: if lock.exclusive: self._logger.LogError( - 'Exclusive lock already acquired by %s. Reason: %s' % - (lock.owner, lock.reason)) + 'Exclusive lock already acquired by %s. Reason: %s' % (lock.owner, + lock.reason)) return False if exclusive: @@ -245,9 +246,10 @@ class Lock(object): lock.owner = '' if self._auto: - del_list = [i - for i in FileLock.FILE_OPS - if i.name == FileCheckName(self._lock_file)] + del_list = [ + i for i in FileLock.FILE_OPS + if i.name == FileCheckName(self._lock_file) + ] for i in del_list: FileLock.FILE_OPS.remove(i) for f in del_list: @@ -287,8 +289,7 @@ class Machine(object): if locked or not timeout >= 0: break print('Lock not acquired for {0}, wait {1} seconds ...'.format( - self._name, - sleep)) + self._name, sleep)) time.sleep(sleep) timeout -= sleep return locked @@ -302,41 +303,43 @@ def Main(argv): """The main function.""" parser = argparse.ArgumentParser() - parser.add_argument('-r', - '--reason', - dest='reason', - default='', - help='The lock reason.') - parser.add_argument('-u', - '--unlock', - dest='unlock', - action='store_true', - default=False, - help='Use this to unlock.') - parser.add_argument('-l', - '--list_locks', - dest='list_locks', - action='store_true', - default=False, - help='Use this to list locks.') - parser.add_argument('-f', - '--ignore_ownership', - dest='ignore_ownership', - action='store_true', - default=False, - help="Use this to force unlock on a lock you don't own.") - parser.add_argument('-s', - '--shared', - dest='shared', - action='store_true', - default=False, - help='Use this for a shared (non-exclusive) lock.') - parser.add_argument('-d', - '--dir', - dest='locks_dir', - action='store', - default=Machine.LOCKS_DIR, - help='Use this to set different locks_dir') + parser.add_argument( + '-r', '--reason', dest='reason', default='', help='The lock reason.') + parser.add_argument( + '-u', + '--unlock', + dest='unlock', + action='store_true', + default=False, + help='Use this to unlock.') + parser.add_argument( + '-l', + '--list_locks', + dest='list_locks', + action='store_true', + default=False, + help='Use this to list locks.') + parser.add_argument( + '-f', + '--ignore_ownership', + dest='ignore_ownership', + action='store_true', + default=False, + help="Use this to force unlock on a lock you don't own.") + parser.add_argument( + '-s', + '--shared', + dest='shared', + action='store_true', + default=False, + help='Use this for a shared (non-exclusive) lock.') + parser.add_argument( + '-d', + '--dir', + dest='locks_dir', + action='store', + default=Machine.LOCKS_DIR, + help='Use this to set different locks_dir') parser.add_argument('args', nargs='*', help='Machine arg.') options = parser.parse_args(argv) |