*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit 6a459527 authored by Moser, Maximilian's avatar Moser, Maximilian
Browse files

Refactor check for file existence in drafts

parent 2b770bc2
No related branches found
No related tags found
1 merge request!16Modernize the package
......@@ -40,6 +40,11 @@ from .utils import (
)
def file_exists(path, filename):
"""Check if the file exists in the given path."""
return isfile(join(path, filename))
def auto_increase_bucket_limits(bucket, filepaths, to_unlimited=False):
"""Dynamically increase the bucket quoat if necessary."""
# see what the file sizes look like
......@@ -156,16 +161,20 @@ def create_draft(metadata_path, publish, user, owners, vanity_pid):
file_paths = []
if isdir(deposit_files_path):
def exists(filename):
return isfile(join(deposit_files_path, filename))
content = os.listdir(deposit_files_path)
file_names = [basename(fn) for fn in content if exists(fn)]
file_names = [
basename(fn) for fn in content if file_exists(deposit_files_path, fn)
]
for fn in file_names:
file_paths.append(join(deposit_files_path, fn))
if len(content) != len(file_names):
ignored = [basename(fn) for fn in content if not exists(fn)]
ignored = [
basename(fn)
for fn in content
if not file_exists(deposit_files_path, fn)
]
msg = f"ignored in '{deposit_files_path}': {ignored}"
click.secho(msg, fg="yellow", err=True)
......@@ -173,6 +182,7 @@ def create_draft(metadata_path, publish, user, owners, vanity_pid):
file_service.init_files(
id_=recid, identity=identity, data=[{"key": fn} for fn in file_names]
)
for fn in file_names:
file_path = join(deposit_files_path, fn)
with open(file_path, "rb") as deposit_file:
......@@ -313,14 +323,13 @@ def add_files(filepaths, pid, pid_type, user):
for file_path in filepaths:
if isdir(file_path):
# add all files (no recursion into sub-dirs) from the directory
def exists(filename):
return isfile(join(file_path, filename))
content = os.listdir(file_path)
file_names = [basename(fn) for fn in content if exists(fn)]
file_names = [basename(fn) for fn in content if file_exists(file_path, fn)]
if len(content) != len(file_names):
ignored = [basename(fn) for fn in content if not exists(fn)]
ignored = [
basename(fn) for fn in content if not file_exists(file_path, fn)
]
msg = f"ignored in '{file_path}': {ignored}"
click.secho(msg, fg="yellow", err=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment