Skip to content

Commit

Permalink
Recognise COMMITTED status (#88)
Browse files Browse the repository at this point in the history
This is an interim release

Fix py3.9 deprecated method open_binary()

AB#9188
  • Loading branch information
eccles authored Apr 5, 2024
1 parent 9309353 commit 77f0a27
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 26 deletions.
14 changes: 11 additions & 3 deletions archivist_samples/c2pa/c2pa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# pylint:disable=missing-module-docstring # docstrings
# pylint:disable=missing-class-docstring # docstrings

from importlib import resources
try:
# Python < 3.9
import importlib_resources as res
except ImportError:
import importlib.resources as res

import logging

Expand All @@ -23,7 +27,9 @@


def upload_attachment(arch, attachment_description: AttachmentDescription):
with resources.open_binary(c2pa_files, attachment_description.filename) as fd:
with res.files(c2pa_files).joinpath(attachment_description.filename).open(
"rb"
) as fd:
blob = arch.attachments.upload(fd)
attachment = {
# sample-specific attr to relay attachment name
Expand All @@ -38,7 +44,9 @@ def upload_attachment(arch, attachment_description: AttachmentDescription):


def attachment_create(arch, attachment_description: AttachmentDescription):
with resources.open_binary(c2pa_files, attachment_description.filename) as fd:
with res.files(c2pa_files).joinpath(attachment_description.filename).open(
"rb"
) as fd:
attachment = arch.attachments.upload(fd)
result = {
"arc_attribute_type": "arc_attachment",
Expand Down
14 changes: 11 additions & 3 deletions archivist_samples/document/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# pylint:disable=missing-module-docstring # docstrings
# pylint:disable=missing-class-docstring # docstrings

from importlib import resources
try:
# Python < 3.9
import importlib_resources as res
except ImportError:
import importlib.resources as res

import logging

Expand All @@ -23,7 +27,9 @@


def upload_attachment(arch, attachment_description: AttachmentDescription):
with resources.open_binary(document_files, attachment_description.filename) as fd:
with res.files(document_files).joinpath(attachment_description.filename).open(
"rb"
) as fd:
blob = arch.attachments.upload(fd)
attachment = {
# sample-specific attr to relay attachment name
Expand All @@ -38,7 +44,9 @@ def upload_attachment(arch, attachment_description: AttachmentDescription):


def attachment_create(arch, attachment_description: AttachmentDescription):
with resources.open_binary(document_files, attachment_description.filename) as fd:
with res.files(document_files).joinpath(attachment_description.filename).open(
"rb"
) as fd:
attachment = arch.attachments.upload(fd)
result = {
"arc_attribute_type": "arc_attachment",
Expand Down
12 changes: 9 additions & 3 deletions archivist_samples/door_entry/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
# pylint: disable=missing-docstring


from importlib import resources
try:
# Python < 3.9
import importlib_resources as res
except ImportError:
import importlib.resources as res

from copy import copy
import logging
Expand All @@ -30,7 +34,9 @@


def attachment_create(doors, attachment_description: AttachmentDescription):
with resources.open_binary(images_assets, attachment_description.filename) as fd:
with res.files(images_assets).joinpath(attachment_description.filename).open(
"rb"
) as fd:
attachment = doors.attachments.upload(fd)
result = {
"arc_attribute_type": "arc_attachment",
Expand Down Expand Up @@ -478,7 +484,7 @@ def open_door(doors, doorid, cards, cardid):
# time but if the use case demands it is perfectly possible to
# attach the same attachment ID to multiple assets/events rather
# than duplicating them
with resources.open_binary(images_events, "dooropen.png") as fd:
with res.files(images_events).joinpath("dooropen.png").open("rb") as fd:
image = doors.attachments.upload(fd)

# Issue RecordEvidence logs on each.
Expand Down
7 changes: 4 additions & 3 deletions archivist_samples/sample_scripts/c2pa/c2pa_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import sample

try:
import importlib.resources as pkg_resources
# Python < 3.9
import importlib_resources as res
except ImportError:
import importlib_resources as pkg_resources
import importlib.resources as res


# DataTrails Connection Parameters -- Honest Abe
Expand Down Expand Up @@ -72,7 +73,7 @@ def evil_arch():

# Uploads attachments to DataTrails
def upload_attachment(arch, path, name):
with pkg_resources.open_binary(sample, path) as fd:
with res.files(sample).joinpath(path).open("rb") as fd:
blob = arch.attachments.upload(fd)
attachment = {
"arc_display_name": name,
Expand Down
10 changes: 8 additions & 2 deletions archivist_samples/sbom_document/software_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
# pylint:disable=unused-import # To prevent cyclical import errors forward referencing is used
# pylint:disable=cyclic-import # but pylint doesn't understand this feature

from importlib import resources
try:
# Python < 3.9
import importlib_resources as res
except ImportError:
import importlib.resources as res

import logging
from sys import exit as sys_exit
Expand All @@ -22,7 +26,9 @@

def attachment_create(arch, attachment_description: AttachmentDescription):
LOGGER.info("sbom attachment creator: %s", attachment_description.filename)
with resources.open_binary(sbom_files, attachment_description.filename) as fd:
with res.files(sbom_files).joinpath(attachment_description.filename).open(
"rb"
) as fd:
attachment = arch.attachments.upload(fd)
result = {
"arc_attribute_type": "arc_attachment",
Expand Down
10 changes: 8 additions & 2 deletions archivist_samples/software_bill_of_materials/software_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
# pylint:disable=unused-import # To prevent cyclical import errors forward referencing is used
# pylint:disable=cyclic-import # but pylint doesn't understand this feature

from importlib import resources
try:
# Python < 3.9
import importlib_resources as res
except ImportError:
import importlib.resources as res

import logging
from sys import exit as sys_exit
Expand All @@ -22,7 +26,9 @@

def attachment_create(sboms, attachment_description: AttachmentDescription):
LOGGER.info("sbom attachment creator: %s", attachment_description.filename)
with resources.open_binary(sbom_files, attachment_description.filename) as fd:
with res.files(sbom_files).joinpath(attachment_description.filename).open(
"rb"
) as fd:
attachment = sboms.attachments.upload(fd)
result = {
"arc_attribute_type": "arc_attachment",
Expand Down
14 changes: 9 additions & 5 deletions archivist_samples/synsation/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

# pylint: disable=missing-docstring

from importlib import resources
try:
# Python < 3.9
import importlib_resources as res
except ImportError:
import importlib.resources as res

from yaml import full_load

Expand All @@ -16,14 +20,14 @@


def asset_attachment_upload_from_file(arch, name, mtype):
with resources.open_binary(images_assets, name) as fd:
with res.files(images_assets).joinpath(name).open("rb") as fd:
attachment = arch.attachments.upload(fd, mtype=mtype)

return attachment


def attachment_upload_from_file(arch, name, mtype):
with resources.open_binary(images, name) as fd:
with res.files(images).joinpath(name).open("rb") as fd:
attachment = arch.attachments.upload(fd, mtype=mtype)

return attachment
Expand All @@ -34,7 +38,7 @@ def locations_create_from_yaml_file(arch, name):
assumes there is only one document in the file.
"""
with resources.open_binary(locations, name) as fd:
with res.files(locations).joinpath(name).open("rb") as fd:
data = full_load(fd)
attrs = data["attributes"]
del data["attributes"]
Expand All @@ -46,7 +50,7 @@ def locations_from_yaml_file(name):
assumes there is only one document in the file.
"""
with resources.open_binary(locations, name) as fd:
with res.files(locations).joinpath(name).open("rb") as fd:
data = full_load(fd)
attrs = data["attributes"]
del data["attributes"]
Expand Down
14 changes: 11 additions & 3 deletions archivist_samples/wipp/wipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# pylint:disable=missing-module-docstring # docstrings
# pylint:disable=missing-class-docstring # docstrings

from importlib import resources
try:
# Python < 3.9
import importlib_resources as res
except ImportError:
import importlib.resources as res

import logging

Expand All @@ -22,7 +26,9 @@


def upload_attachment(arch, attachment_description: AttachmentDescription):
with resources.open_binary(wipp_files, attachment_description.filename) as fd:
with res.files(wipp_files).joinpath(attachment_description.filename).open(
"rb"
) as fd:
blob = arch.attachments.upload(fd)
attachment = {
# sample-specific attr to relay attachment name
Expand All @@ -37,7 +43,9 @@ def upload_attachment(arch, attachment_description: AttachmentDescription):


def attachment_create(arch, attachment_description: AttachmentDescription):
with resources.open_binary(wipp_files, attachment_description.filename) as fd:
with res.files(wipp_files).joinpath(attachment_description.filename).open(
"rb"
) as fd:
attachment = arch.attachments.upload(fd)
result = {
"arc_attribute_type": "arc_attachment",
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cryptography~=41.0.2
# TODO change to datatrails when released
datatrails-archivist==0.27.1
importlib-resources==3.0.0; python_version < '3.9'
datatrails-archivist==0.29.0a1
pyyaml~=6.0.1

0 comments on commit 77f0a27

Please sign in to comment.