Format Python code with black

This commit is contained in:
kpj
2022-02-27 15:26:41 +01:00
parent 13885968e3
commit fc695896dd
136 changed files with 6142 additions and 3811 deletions

View File

@@ -18,24 +18,26 @@ def path_check(var, directory):
messages = []
if directory:
if not os.path.isdir(directory):
messages.append(Error(
exists_message.format(var),
exists_hint.format(directory)
))
messages.append(
Error(exists_message.format(var), exists_hint.format(directory))
)
else:
test_file = os.path.join(
directory, f'__paperless_write_test_{os.getpid()}__'
directory, f"__paperless_write_test_{os.getpid()}__"
)
try:
with open(test_file, 'w'):
with open(test_file, "w"):
pass
except PermissionError:
messages.append(Error(
writeable_message.format(var),
writeable_hint.format(
f'\n{stat.filemode(os.stat(directory).st_mode)} '
f'{directory}\n')
))
messages.append(
Error(
writeable_message.format(var),
writeable_hint.format(
f"\n{stat.filemode(os.stat(directory).st_mode)} "
f"{directory}\n"
),
)
)
finally:
if os.path.isfile(test_file):
os.remove(test_file)
@@ -49,10 +51,12 @@ def paths_check(app_configs, **kwargs):
Check the various paths for existence, readability and writeability
"""
return path_check("PAPERLESS_DATA_DIR", settings.DATA_DIR) + \
path_check("PAPERLESS_TRASH_DIR", settings.TRASH_DIR) + \
path_check("PAPERLESS_MEDIA_ROOT", settings.MEDIA_ROOT) + \
path_check("PAPERLESS_CONSUMPTION_DIR", settings.CONSUMPTION_DIR)
return (
path_check("PAPERLESS_DATA_DIR", settings.DATA_DIR)
+ path_check("PAPERLESS_TRASH_DIR", settings.TRASH_DIR)
+ path_check("PAPERLESS_MEDIA_ROOT", settings.MEDIA_ROOT)
+ path_check("PAPERLESS_CONSUMPTION_DIR", settings.CONSUMPTION_DIR)
)
@register()
@@ -65,11 +69,7 @@ def binaries_check(app_configs, **kwargs):
error = "Paperless can't find {}. Without it, consumption is impossible."
hint = "Either it's not in your ${PATH} or it's not installed."
binaries = (
settings.CONVERT_BINARY,
settings.OPTIPNG_BINARY,
"tesseract"
)
binaries = (settings.CONVERT_BINARY, settings.OPTIPNG_BINARY, "tesseract")
check_messages = []
for binary in binaries:
@@ -82,11 +82,14 @@ def binaries_check(app_configs, **kwargs):
@register()
def debug_mode_check(app_configs, **kwargs):
if settings.DEBUG:
return [Warning(
"DEBUG mode is enabled. Disable Debug mode. This is a serious "
"security issue, since it puts security overides in place which "
"are meant to be only used during development. This "
"also means that paperless will tell anyone various "
"debugging information when something goes wrong.")]
return [
Warning(
"DEBUG mode is enabled. Disable Debug mode. This is a serious "
"security issue, since it puts security overides in place which "
"are meant to be only used during development. This "
"also means that paperless will tell anyone various "
"debugging information when something goes wrong."
)
]
else:
return []