From 234d276eb2c220e539c68f20b02876f2a66d7a4d Mon Sep 17 00:00:00 2001 From: "Douglas Cerna (Soy Douglas)" Date: Fri, 11 Aug 2023 01:57:06 +0000 Subject: [PATCH] WIP --- .../clientScripts/archivematica_clamscan.py | 10 ++++++---- .../lib/clientScripts/create_mets_v2.py | 12 ++++++------ .../lib/clientScripts/create_transfer_mets.py | 18 ++++++++++-------- .../clientScripts/update_size_and_checksum.py | 2 +- src/MCPServer/lib/server/packages.py | 2 +- src/MCPServer/tests/test_package.py | 2 +- src/archivematicaCommon/lib/dicts.py | 2 +- src/dashboard/src/components/api/views.py | 2 +- 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/MCPClient/lib/clientScripts/archivematica_clamscan.py b/src/MCPClient/lib/clientScripts/archivematica_clamscan.py index 32ed295160..8869773b09 100755 --- a/src/MCPClient/lib/clientScripts/archivematica_clamscan.py +++ b/src/MCPClient/lib/clientScripts/archivematica_clamscan.py @@ -219,9 +219,12 @@ def version_attrs(self): def file_already_scanned(file_uuid): - return Event.objects.filter( - file_uuid_id=file_uuid, event_type="virus check" - ).exists() + return ( + file_uuid != "None" + and Event.objects.filter( + file_uuid_id=file_uuid, event_type="virus check" + ).exists() + ) def queue_event(file_uuid, date, scanner, passed, queue): @@ -274,7 +277,6 @@ def get_scanner(): """ choice = str(mcpclient_settings.CLAMAV_CLIENT_BACKEND).lower() if choice not in SCANNERS_NAMES: - logger.warning( "Unexpected antivirus scanner (CLAMAV_CLIENT_BACKEND):" ' "%s"; using %s.', choice, diff --git a/src/MCPClient/lib/clientScripts/create_mets_v2.py b/src/MCPClient/lib/clientScripts/create_mets_v2.py index 1b5317fe24..cf65c5fe86 100755 --- a/src/MCPClient/lib/clientScripts/create_mets_v2.py +++ b/src/MCPClient/lib/clientScripts/create_mets_v2.py @@ -1137,7 +1137,7 @@ def createFileSec( GROUPID = "" if f.filegrpuuid: # GROUPID was determined elsewhere - GROUPID = "Group-%s" % (f.filegrpuuid) + GROUPID = f"Group-{f.filegrpuuid}" if use == "TRIM file metadata": use = "metadata" @@ -1148,7 +1148,7 @@ def createFileSec( "maildirFile", ): # These files are in a group defined by themselves - GROUPID = "Group-%s" % (f.uuid) + GROUPID = f"Group-{f.uuid}" if use == "maildirFile": use = "original" # Check for CSV-based Dublincore dmdSec @@ -1194,7 +1194,7 @@ def createFileSec( } original_file = File.objects.filter(**kwargs).first() if original_file is not None: - GROUPID = "Group-" + original_file.uuid + GROUPID = f"Group-{original_file.uuid}" elif use in ("preservation", "text/ocr", "derivative"): # Derived files should be in the original file's group @@ -1206,7 +1206,7 @@ def createFileSec( " where the derived file is {}".format(f.uuid) ) raise - GROUPID = "Group-" + d.source_file_id + GROUPID = f"Group-{d.source_file_id}" elif use == "service": # Service files are in the original file's group @@ -1224,10 +1224,10 @@ def createFileSec( "currentlocation__startswith": fileFileIDPath, } original_file = File.objects.get(**kwargs) - GROUPID = "Group-" + original_file.uuid + GROUPID = f"Group-{original_file.uuid}" elif use == "TRIM container metadata": - GROUPID = "Group-%s" % (f.uuid) + GROUPID = f"Group-{f.uuid}" use = "metadata" # Special DSPACEMETS processing diff --git a/src/MCPClient/lib/clientScripts/create_transfer_mets.py b/src/MCPClient/lib/clientScripts/create_transfer_mets.py index f44abc7cc1..1bb711be81 100755 --- a/src/MCPClient/lib/clientScripts/create_transfer_mets.py +++ b/src/MCPClient/lib/clientScripts/create_transfer_mets.py @@ -338,7 +338,10 @@ def get_premis_relationship_data(derivations, originals): ( "related_object_identification", ("related_object_identifier_type", "UUID"), - ("related_object_identifier_value", derivation.derived_file_id), + ( + "related_object_identifier_value", + str(derivation.derived_file_id), + ), ), ( "related_event_identification", @@ -356,7 +359,7 @@ def get_premis_relationship_data(derivations, originals): ( "related_object_identification", ("related_object_identifier_type", "UUID"), - ("related_object_identifier_value", original.source_file_id), + ("related_object_identifier_value", str(original.source_file_id)), ), ( "related_event_identification", @@ -546,7 +549,6 @@ def get_premis_other_rights_information(rights): def get_premis_rights_granted(rights): rights_granted_info = () for rights_granted in rights.rightsstatementrightsgranted_set.all(): - start_date = clean_date(rights_granted.startdate) if rights_granted.enddateopen: end_date = "OPEN" @@ -584,7 +586,7 @@ def get_premis_object_identifiers(uuid, additional_identifiers): ( "object_identifier", ("object_identifier_type", identifier.type), - ("object_identifier_value", identifier.value), + ("object_identifier_value", str(identifier.value)), ), ) @@ -701,7 +703,7 @@ def event_to_premis(event): ( "linking_agent_identifier", ("linking_agent_identifier_type", agent.identifiertype), - ("linking_agent_identifier_value", agent.identifiervalue), + ("linking_agent_identifier_value", str(agent.identifiervalue)), ), ) @@ -723,7 +725,7 @@ def agent_to_premis(agent): ( "agent_identifier", ("agent_identifier_type", agent.identifiertype), - ("agent_identifier_value", agent.identifiervalue), + ("agent_identifier_value", str(agent.identifiervalue)), ), ("agent_name", agent.name), ("agent_type", agent.agenttype), @@ -761,7 +763,7 @@ def rights_to_premis(rights, file_uuid): ( "rights_statement_identifier", ("rights_statement_identifier_type", id_type), - ("rights_statement_identifier_value", id_value), + ("rights_statement_identifier_value", str(id_value)), ), ("rights_basis", rights_basis), ) @@ -792,7 +794,7 @@ def rights_to_premis(rights, file_uuid): ( "linking_object_identifier", ("linking_object_identifier_type", "UUID"), - ("linking_object_identifier_value", file_uuid), + ("linking_object_identifier_value", str(file_uuid)), ), ) diff --git a/src/MCPClient/lib/clientScripts/update_size_and_checksum.py b/src/MCPClient/lib/clientScripts/update_size_and_checksum.py index 7995bc2f3b..57ec6bf194 100755 --- a/src/MCPClient/lib/clientScripts/update_size_and_checksum.py +++ b/src/MCPClient/lib/clientScripts/update_size_and_checksum.py @@ -50,7 +50,7 @@ def get_file_info_from_mets(job, mets, file_): checksum and checksum_type, as they are described in the original METS document of the transfer. The dict will be empty or missing keys on error. """ - fsentry = mets.get_file(file_uuid=file_.uuid) + fsentry = mets.get_file(file_uuid=str(file_.uuid)) if not fsentry: job.print_error(f"FSEntry with UUID {file_.uuid} not found in METS") return {} diff --git a/src/MCPServer/lib/server/packages.py b/src/MCPServer/lib/server/packages.py index 1167b708be..637fb5b1eb 100644 --- a/src/MCPServer/lib/server/packages.py +++ b/src/MCPServer/lib/server/packages.py @@ -509,7 +509,7 @@ def get_file_replacement_mapping(file_obj, unit_directory): mapping.update( { - r"%fileUUID%": file_obj.pk, + r"%fileUUID%": str(file_obj.pk), r"%originalLocation%": file_obj.originallocation, r"%currentLocation%": file_obj.currentlocation, r"%fileGrpUse%": file_obj.filegrpuse, diff --git a/src/MCPServer/tests/test_package.py b/src/MCPServer/tests/test_package.py index 7a45c7ca2b..9ddb1a936c 100644 --- a/src/MCPServer/tests/test_package.py +++ b/src/MCPServer/tests/test_package.py @@ -294,7 +294,7 @@ def test_package_files_with_non_ascii_names(tmp_path): assert len(result) == 1 # And it is the file we just created - assert result[0]["%fileUUID%"] == kwargs["uuid"] + assert result[0]["%fileUUID%"] == str(kwargs["uuid"]) assert result[0]["%currentLocation%"] == kwargs["currentlocation"] assert result[0]["%fileGrpUse%"] == kwargs["filegrpuse"] diff --git a/src/archivematicaCommon/lib/dicts.py b/src/archivematicaCommon/lib/dicts.py index f9524fe6d1..cece83ddbd 100644 --- a/src/archivematicaCommon/lib/dicts.py +++ b/src/archivematicaCommon/lib/dicts.py @@ -135,7 +135,7 @@ def frommodel(type_="file", sip=None, file_=None, expand_path=True): rd["%relativeLocation%"] = relative_location if file_: - rd["%fileUUID%"] = file_.uuid + rd["%fileUUID%"] = str(file_.uuid) try: base_location = file_.sip.currentpath except: diff --git a/src/dashboard/src/components/api/views.py b/src/dashboard/src/components/api/views.py index 93c1452cb7..c38f6e9f25 100644 --- a/src/dashboard/src/components/api/views.py +++ b/src/dashboard/src/components/api/views.py @@ -520,7 +520,7 @@ def approve_transfer(request): msg = "Unable to start the transfer." LOGGER.error("%s %s (db_transfer_path=%s)", msg, err, db_transfer_path) return _error_response(msg, status_code=500) - return _ok_response("Approval successful.", uuid=unit_uuid) + return _ok_response("Approval successful.", uuid=str(unit_uuid)) def get_modified_standard_transfer_path(transfer_type=None):