mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
switch to 4 space indent
Leave the recipes/ code at 2 space to match the rest of the recipes
project in other repos.
Reformatted using:
files=( $(
git ls-tree -r --name-only HEAD | \
grep -Ev -e '^(third_party|recipes)/' | \
grep '\.py$';
git grep -l '#!/usr/bin/env.*python' | grep -v '\.py$'
) )
parallel ./yapf -i -- "${files[@]}"
~/chromiumos/chromite/contrib/reflow_overlong_comments "${files[@]}"
The files that still had strings that were too long were manually
reformatted because they were easy and only a few issues.
autoninja.py
clang_format.py
download_from_google_storage.py
fix_encoding.py
gclient_utils.py
git_cache.py
git_common.py
git_map_branches.py
git_reparent_branch.py
gn.py
my_activity.py
owners_finder.py
presubmit_canned_checks.py
reclient_helper.py
reclientreport.py
roll_dep.py
rustfmt.py
siso.py
split_cl.py
subcommand.py
subprocess2.py
swift_format.py
upload_to_google_storage.py
These files still had lines (strings) that were too long, so the pylint
warnings were suppressed with a TODO.
auth.py
gclient.py
gclient_eval.py
gclient_paths.py
gclient_scm.py
gerrit_util.py
git_cl.py
presubmit_canned_checks.py
presubmit_support.py
scm.py
Change-Id: Ia6535c4f2c48d46b589ec1e791dde6c6b2ea858f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4836379
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
This commit is contained in:
141
lockfile.py
141
lockfile.py
@@ -13,94 +13,95 @@ import time
|
||||
|
||||
|
||||
class LockError(Exception):
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
if sys.platform.startswith('win'):
|
||||
# Windows implementation
|
||||
import win32imports
|
||||
# Windows implementation
|
||||
import win32imports
|
||||
|
||||
BYTES_TO_LOCK = 1
|
||||
BYTES_TO_LOCK = 1
|
||||
|
||||
def _open_file(lockfile):
|
||||
return win32imports.Handle(
|
||||
win32imports.CreateFileW(
|
||||
lockfile, # lpFileName
|
||||
win32imports.GENERIC_WRITE, # dwDesiredAccess
|
||||
0, # dwShareMode=prevent others from opening file
|
||||
None, # lpSecurityAttributes
|
||||
win32imports.CREATE_ALWAYS, # dwCreationDisposition
|
||||
win32imports.FILE_ATTRIBUTE_NORMAL, # dwFlagsAndAttributes
|
||||
None # hTemplateFile
|
||||
))
|
||||
def _open_file(lockfile):
|
||||
return win32imports.Handle(
|
||||
win32imports.CreateFileW(
|
||||
lockfile, # lpFileName
|
||||
win32imports.GENERIC_WRITE, # dwDesiredAccess
|
||||
0, # dwShareMode=prevent others from opening file
|
||||
None, # lpSecurityAttributes
|
||||
win32imports.CREATE_ALWAYS, # dwCreationDisposition
|
||||
win32imports.FILE_ATTRIBUTE_NORMAL, # dwFlagsAndAttributes
|
||||
None # hTemplateFile
|
||||
))
|
||||
|
||||
def _close_file(handle):
|
||||
# CloseHandle releases lock too.
|
||||
win32imports.CloseHandle(handle)
|
||||
def _close_file(handle):
|
||||
# CloseHandle releases lock too.
|
||||
win32imports.CloseHandle(handle)
|
||||
|
||||
def _lock_file(handle):
|
||||
ret = win32imports.LockFileEx(
|
||||
handle, # hFile
|
||||
win32imports.LOCKFILE_FAIL_IMMEDIATELY
|
||||
| win32imports.LOCKFILE_EXCLUSIVE_LOCK, # dwFlags
|
||||
0, #dwReserved
|
||||
BYTES_TO_LOCK, # nNumberOfBytesToLockLow
|
||||
0, # nNumberOfBytesToLockHigh
|
||||
win32imports.Overlapped() # lpOverlapped
|
||||
)
|
||||
# LockFileEx returns result as bool, which is converted into an integer
|
||||
# (1 == successful; 0 == not successful)
|
||||
if ret == 0:
|
||||
error_code = win32imports.GetLastError()
|
||||
raise OSError('Failed to lock handle (error code: %d).' % error_code)
|
||||
def _lock_file(handle):
|
||||
ret = win32imports.LockFileEx(
|
||||
handle, # hFile
|
||||
win32imports.LOCKFILE_FAIL_IMMEDIATELY
|
||||
| win32imports.LOCKFILE_EXCLUSIVE_LOCK, # dwFlags
|
||||
0, #dwReserved
|
||||
BYTES_TO_LOCK, # nNumberOfBytesToLockLow
|
||||
0, # nNumberOfBytesToLockHigh
|
||||
win32imports.Overlapped() # lpOverlapped
|
||||
)
|
||||
# LockFileEx returns result as bool, which is converted into an integer
|
||||
# (1 == successful; 0 == not successful)
|
||||
if ret == 0:
|
||||
error_code = win32imports.GetLastError()
|
||||
raise OSError('Failed to lock handle (error code: %d).' %
|
||||
error_code)
|
||||
else:
|
||||
# Unix implementation
|
||||
import fcntl
|
||||
# Unix implementation
|
||||
import fcntl
|
||||
|
||||
def _open_file(lockfile):
|
||||
open_flags = (os.O_CREAT | os.O_WRONLY)
|
||||
return os.open(lockfile, open_flags, 0o644)
|
||||
def _open_file(lockfile):
|
||||
open_flags = (os.O_CREAT | os.O_WRONLY)
|
||||
return os.open(lockfile, open_flags, 0o644)
|
||||
|
||||
def _close_file(fd):
|
||||
os.close(fd)
|
||||
def _close_file(fd):
|
||||
os.close(fd)
|
||||
|
||||
def _lock_file(fd):
|
||||
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
def _lock_file(fd):
|
||||
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
|
||||
|
||||
def _try_lock(lockfile):
|
||||
f = _open_file(lockfile)
|
||||
try:
|
||||
_lock_file(f)
|
||||
except Exception:
|
||||
_close_file(f)
|
||||
raise
|
||||
return lambda: _close_file(f)
|
||||
f = _open_file(lockfile)
|
||||
try:
|
||||
_lock_file(f)
|
||||
except Exception:
|
||||
_close_file(f)
|
||||
raise
|
||||
return lambda: _close_file(f)
|
||||
|
||||
|
||||
def _lock(path, timeout=0):
|
||||
"""_lock returns function to release the lock if locking was successful.
|
||||
"""_lock returns function to release the lock if locking was successful.
|
||||
|
||||
_lock also implements simple retry logic."""
|
||||
elapsed = 0
|
||||
while True:
|
||||
try:
|
||||
return _try_lock(path + '.locked')
|
||||
except (OSError, IOError) as e:
|
||||
if elapsed < timeout:
|
||||
sleep_time = min(10, timeout - elapsed)
|
||||
logging.info(
|
||||
'Could not create git cache lockfile; '
|
||||
'will retry after sleep(%d).', sleep_time)
|
||||
elapsed += sleep_time
|
||||
time.sleep(sleep_time)
|
||||
continue
|
||||
raise LockError("Error locking %s (err: %s)" % (path, str(e)))
|
||||
elapsed = 0
|
||||
while True:
|
||||
try:
|
||||
return _try_lock(path + '.locked')
|
||||
except (OSError, IOError) as e:
|
||||
if elapsed < timeout:
|
||||
sleep_time = min(10, timeout - elapsed)
|
||||
logging.info(
|
||||
'Could not create git cache lockfile; '
|
||||
'will retry after sleep(%d).', sleep_time)
|
||||
elapsed += sleep_time
|
||||
time.sleep(sleep_time)
|
||||
continue
|
||||
raise LockError("Error locking %s (err: %s)" % (path, str(e)))
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def lock(path, timeout=0):
|
||||
"""Get exclusive lock to path.
|
||||
"""Get exclusive lock to path.
|
||||
|
||||
Usage:
|
||||
import lockfile
|
||||
@@ -109,8 +110,8 @@ def lock(path, timeout=0):
|
||||
pass
|
||||
|
||||
"""
|
||||
release_fn = _lock(path, timeout)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
release_fn()
|
||||
release_fn = _lock(path, timeout)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
release_fn()
|
||||
|
||||
Reference in New Issue
Block a user