1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-10 14:05:07 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -21,20 +21,21 @@ class LockTimeout(Exception):
class FileLock:
'''
"""
Currently FileLock is implemented via fcntl.flock on a lock file, however this
behaviour may change in the future. Avoid mixing lock types fcntl.flock,
fcntl.lockf and module_utils.common.file.FileLock as it will certainly cause
unwanted and/or unexpected behaviour
'''
"""
def __init__(self):
self.lockfd = None
@contextmanager
def lock_file(self, path, tmpdir, lock_timeout=None):
'''
"""
Context for lock acquisition
'''
"""
try:
self.set_lock(path, tmpdir, lock_timeout)
yield
@ -42,7 +43,7 @@ class FileLock:
self.unlock()
def set_lock(self, path, tmpdir, lock_timeout=None):
'''
"""
Create a lock file based on path with flock to prevent other processes
using given path.
Please note that currently file locking only works when it is executed by
@ -55,14 +56,14 @@ class FileLock:
0 = Do not wait, fail if lock cannot be acquired immediately,
Default is None, wait indefinitely until lock is released.
:returns: True
'''
lock_path = os.path.join(tmpdir, f'ansible-{os.path.basename(path)}.lock')
"""
lock_path = os.path.join(tmpdir, f"ansible-{os.path.basename(path)}.lock")
l_wait = 0.1
r_exception = IOError
if sys.version_info[0] == 3:
r_exception = BlockingIOError
self.lockfd = open(lock_path, 'w')
self.lockfd = open(lock_path, "w")
if lock_timeout <= 0:
fcntl.flock(self.lockfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
@ -82,7 +83,7 @@ class FileLock:
continue
self.lockfd.close()
raise LockTimeout(f'{lock_timeout} sec')
raise LockTimeout(f"{lock_timeout} sec")
fcntl.flock(self.lockfd, fcntl.LOCK_EX)
os.chmod(lock_path, stat.S_IWRITE | stat.S_IREAD)
@ -90,12 +91,12 @@ class FileLock:
return True
def unlock(self):
'''
"""
Make sure lock file is available for everyone and Unlock the file descriptor
locked by set_lock
:returns: True
'''
"""
if not self.lockfd:
return True