Use try..finally blocks to ensure calls within context manager
This commit is contained in:
parent
bbeebecd4f
commit
a7d30cf91d
@ -108,9 +108,11 @@ def change_umask():
|
||||
"""Creates a context manager in which the umask is changed. This is to ensure that
|
||||
the script's desired umask is not visible to the user.
|
||||
"""
|
||||
old_umask = os.umask(SCRIPT_UMASK)
|
||||
yield
|
||||
os.umask(old_umask)
|
||||
try:
|
||||
old_umask = os.umask(SCRIPT_UMASK)
|
||||
yield
|
||||
finally:
|
||||
os.umask(old_umask)
|
||||
|
||||
|
||||
# ========== Main Script ==========
|
||||
|
@ -95,9 +95,12 @@ def merge_include_files():
|
||||
|
||||
:return: path-like object
|
||||
"""
|
||||
filelist = merge_files(get_files_by_suffix("-include.conf"))
|
||||
yield filelist
|
||||
filelist.unlink()
|
||||
try:
|
||||
# filelist is guaranteed to exist at this point
|
||||
filelist = merge_files(get_files_by_suffix("-include.conf"))
|
||||
yield filelist
|
||||
finally:
|
||||
filelist.unlink()
|
||||
|
||||
|
||||
@contextmanager
|
||||
@ -106,9 +109,12 @@ def merge_exclude_files():
|
||||
|
||||
:return: path-like object
|
||||
"""
|
||||
filelist = merge_files(get_files_by_suffix("-exclude.conf"))
|
||||
yield filelist
|
||||
filelist.unlink()
|
||||
try:
|
||||
# filelist is guaranteed to exist at this point
|
||||
filelist = merge_files(get_files_by_suffix("-exclude.conf"))
|
||||
yield filelist
|
||||
finally:
|
||||
filelist.unlink()
|
||||
|
||||
|
||||
def parse_configfile():
|
||||
|
Loading…
x
Reference in New Issue
Block a user