Commit 4124459e authored by anarcat's avatar anarcat
Browse files

Merge branch 'blacken' into 'main'

blacken

See merge request !11
parents f4e87443 c1d0247a
Pipeline #20620 passed with stage
in 25 seconds
variables:
LC_ALL: "C.UTF-8"
LANG: "C.UTF-8"
# We use a job template to avoid mindless repetition. All of our jobs
# run 'tox', and we vary which tox environment they run or which
# Python version they use by overriding the 'TOXENV' environment
# variable or the 'image' job parameter.
#
# The name of the template starts with a dot to prevent GitLab from
# running it as an actual job.
.tox:
image: python:latest
before_script:
- pip install tox
script:
- tox
variables:
TOXENV: py
# The environment 'py' uses the version of Python used to invoke tox,
# which allows us to test various Python versions by changing the
# Docker image version in use.
flake8:
extends: .tox
variables:
TOXENV: flake8
black:
extends: .tox
variables:
TOXENV: black
......@@ -106,13 +106,15 @@ class BatchArgParser(argparse.ArgumentParser):
args = super().parse_args(*args, **kwargs)
if args.password is None:
args.password = getpass("Password:")
for attr in ('location', 'username', 'password'):
for attr in ("location", "username", "password"):
if not getattr(args, attr):
self.error("no %s provided, provide one with --%s or WEBDAV_%s environment" % (attr, attr, attr.upper()))
self.error(
"no %s provided, provide one with --%s or WEBDAV_%s environment"
% (attr, attr, attr.upper())
)
return args
class Sanitizer:
"""actually sanitize files with Docker
......@@ -308,14 +310,14 @@ SPECIAL_FOLDERS = (
"dangerzone-rejected",
# those are actually in use
"dangerzone",
"safe"
"safe",
)
def is_special_folder(folder: str) -> bool:
"""Normalize `folder` and check if it's in `SPECIAL_FOLDERS`"""
return folder.strip('/') in SPECIAL_FOLDERS
return folder.strip("/") in SPECIAL_FOLDERS
def main():
......@@ -391,12 +393,17 @@ class ProcessingClient(wc.Client):
# non-empty folder or regular file
if len(listing) > 1 or not path.endswith("/"):
remote_processing_path = join(folder, "dangerzone/processing", path)
logging.info("moving %s to %s before processing", path, remote_processing_path)
logging.info(
"moving %s to %s before processing", path, remote_processing_path
)
if not self.dryrun:
self.mkdir(join(folder, "dangerzone"))
self.mkdir(join(folder, "dangerzone/processing"))
try:
self.move(remote_path_from=join(folder, path), remote_path_to=remote_processing_path)
self.move(
remote_path_from=join(folder, path),
remote_path_to=remote_processing_path,
)
except ResponseErrorCode as e:
# https://datatracker.ietf.org/doc/html/rfc7232#section-4.2
# actually used in WebDAV to show the file already exists
......@@ -457,12 +464,12 @@ class ProcessingClient(wc.Client):
remote_safe_directory = join(folder, "safe")
remote_safe_path = join(remote_safe_directory, path)
local_safe_path = join(self.sanitizer.safe_dir, path)
logging.info(f"recursively creating remote safe directory {remote_safe_directory}")
if not self.dryrun:
self.mkdir_recursive(remote_safe_directory)
logging.info(
"uploading %s to %s", local_safe_path, remote_safe_path
f"recursively creating remote safe directory {remote_safe_directory}"
)
if not self.dryrun:
self.mkdir_recursive(remote_safe_directory)
logging.info("uploading %s to %s", local_safe_path, remote_safe_path)
if not self.dryrun:
self.upload_sync(
# does that work when safe/ already has stuff?
......@@ -471,7 +478,9 @@ class ProcessingClient(wc.Client):
)
remote_processed_path = join(folder, "dangerzone/processed", path)
logging.info(
"renaming %s to %s", remote_processing_path, remote_processed_path,
"renaming %s to %s",
remote_processing_path,
remote_processed_path,
)
if not self.dryrun:
# TODO: turn "dangerzone/processed" into a constant
......
# just delegate install to setup.py for now
#
# this exists mostly so we don't have to duplicate test dependencies
# between tox and setup.py
-e .
[tox]
envlist = flake8,black
[testenv:flake8]
skip_install = true
deps = flake8
commands = flake8 dangerzone-webdav-processor
[testenv:black]
skip_install = true
deps = black
commands = black --diff --check dangerzone-webdav-processor
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment