Skip to content

Commit

Permalink
fix: Debugging new refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
monotasker committed Nov 16, 2024
1 parent a96a059 commit 2ff9ad6
Showing 1 changed file with 68 additions and 70 deletions.
138 changes: 68 additions & 70 deletions invenio_record_importer_kcworks/services/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,88 +671,86 @@ def _compare_existing_files(
(existing_draft_files, records_service.draft_files),
(existing_published_files, records_service.files),
]:
if len(existing_files) > 0:
print("files service:", files_service.config)
print("existing files:", existing_files)
print("new entries:", new_entries)
if len(existing_files) == 0 or old_files == {}:
if len(new_entries) > 0:
same_files = False
print("files service:", files_service.config)
print("existing files:", existing_files)
print("new entries:", new_entries)
if len(existing_files) == 0 or old_files == {}:
if len(new_entries) > 0:
same_files = False
app.logger.info(
" new files to be uploaded that are not "
"present in the existing record"
)
else:
record = files_service._get_record(
draft_id, system_identity, "delete_files"
)
if record.files.entries:
app.logger.info(
" neither existing record nor import data "
"has files. Ensuring that the record file "
"manager is empty..."
)
record.files.unlock()
record.files.delete_all(
remove_obj=True,
softdelete_obj=False,
remove_rf=True,
)
app.logger.info(
" new files to be uploaded that are not "
"present in the existing record"
" deleted all files from existing record"
)
else:
record = files_service._get_record(
draft_id, system_identity, "delete_files"
app.logger.info(
" no files attached to existing record "
"and no new files to be uploaded"
)
if record.files.entries:
app.logger.info(
" neither existing record nor import data "
"has files. Ensuring that the record file "
"manager is empty..."
)
record.files.unlock()
record.files.delete_all(
remove_obj=True,
softdelete_obj=False,
remove_rf=True,
)
app.logger.info(
" deleted all files from existing record"
)
else:
app.logger.info(
" no files attached to existing record "
"and no new files to be uploaded"
)
else:
normalized_new_keys = [
unicodedata.normalize("NFC", k)
for k in new_entries.keys()
]
print("normalized new keys:", normalized_new_keys)
old_wrong_files = [
elif len(existing_files) > 0:
normalized_new_keys = [
unicodedata.normalize("NFC", k) for k in new_entries.keys()
]
print("normalized new keys:", normalized_new_keys)
old_wrong_files = [
f
for f in existing_files
if unicodedata.normalize("NFC", f["key"])
not in normalized_new_keys
]
print("old_wrong_files:", old_wrong_files)
for o in old_wrong_files:
print("old wrong file:", o)
self._delete_file(
draft_id,
o["key"],
files_service=files_service,
)

for k, v in new_entries.items():
wrong_file = False
existing_file = [
f
for f in existing_files
if unicodedata.normalize("NFC", f["key"])
not in normalized_new_keys
== unicodedata.normalize("NFC", k)
]
print("old_wrong_files:", old_wrong_files)
for o in old_wrong_files:
print("old wrong file:", o)

if len(existing_file) == 0:
same_files = False
print("no existing file found")

elif (existing_file[0]["status"] == "pending") or (
str(v["size"]) != str(existing_file[0]["size"])
):
same_files = False
wrong_file = True
print("pending or size mismatch")

if wrong_file:
self._delete_file(
draft_id,
o["key"],
existing_file[0]["key"],
files_service=files_service,
)

for k, v in new_entries.items():
wrong_file = False
existing_file = [
f
for f in existing_files
if unicodedata.normalize("NFC", f["key"])
== unicodedata.normalize("NFC", k)
]

if len(existing_file) == 0:
same_files = False
print("no existing file found")

elif (existing_file[0]["status"] == "pending") or (
str(v["size"]) != str(existing_file[0]["size"])
):
same_files = False
wrong_file = True
print("pending or size mismatch")

if wrong_file:
self._delete_file(
draft_id,
existing_file[0]["key"],
files_service=files_service,
)

print("same files:", same_files)
return same_files

0 comments on commit 2ff9ad6

Please sign in to comment.