Don't use a lockfile when the blacklist update is disabled

This commit is contained in:
László Károlyi 2021-12-07 12:19:54 +01:00
parent 91fb131abf
commit 667760f723
Signed by untrusted user: karolyi
GPG Key ID: 2DCAF25E55735BFE
3 changed files with 22 additions and 10 deletions

View File

@ -1,3 +1,6 @@
1.0.5:
- Remove lockfile creation when the updater process is skipped per the environment variable introduced in 1.0.4
1.0.4:
- Skipping the startup update with setting an environment variable called `PY3VE_IGNORE_UPDATER`

View File

@ -57,7 +57,7 @@ class BuildPyCommand(build_py):
setup(
name='py3-validate-email',
version='1.0.4',
version='1.0.5',
packages=find_packages(exclude=['tests']),
install_requires=['dnspython~=2.1', 'idna~=3.0', 'filelock~=3.0'],
author='László Károlyi',

View File

@ -40,17 +40,26 @@ class DomainListValidator(object):
except FileNotFoundError:
return BLACKLIST_FILEPATH_INSTALLED
def _get_blacklist_lines(self) -> list:
'Return the lines of blacklist.txt as a list.'
bl_path = self._blacklist_path
LOGGER.debug(msg=f'(Re)loading blacklist from {bl_path}')
try:
with open(bl_path) as fd:
return fd.readlines()
except FileNotFoundError:
return []
def reload_builtin_blacklist(self):
'(Re)load our built-in blacklist.'
TMP_PATH.mkdir(exist_ok=True)
with FileLock(lock_file=str(LOCK_PATH)):
bl_path = self._blacklist_path
LOGGER.debug(msg=f'(Re)loading blacklist from {bl_path}')
try:
with open(bl_path) as fd:
lines = fd.readlines()
except FileNotFoundError:
return
# Locking is only necessary when we might have an updater
# process running
if ENV_IGNORE_UPDATER:
lines = self._get_blacklist_lines()
else:
TMP_PATH.mkdir(exist_ok=True)
with FileLock(lock_file=str(LOCK_PATH)):
lines = self._get_blacklist_lines()
self.domain_blacklist = set(
x.strip().lower() for x in lines if x.strip())