pyPreservica 2.7.2__py3-none-any.whl → 2.7.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyPreservica/__init__.py +1 -1
- pyPreservica/uploadAPI.py +51 -50
- pyPreservica/workflowAPI.py +4 -4
- {pyPreservica-2.7.2.dist-info → pyPreservica-2.7.3.dist-info}/METADATA +1 -1
- {pyPreservica-2.7.2.dist-info → pyPreservica-2.7.3.dist-info}/RECORD +8 -9
- {pyPreservica-2.7.2.dist-info → pyPreservica-2.7.3.dist-info}/WHEEL +1 -1
- pyPreservica/vocabularyAPI.py +0 -141
- {pyPreservica-2.7.2.dist-info → pyPreservica-2.7.3.dist-info}/LICENSE.txt +0 -0
- {pyPreservica-2.7.2.dist-info → pyPreservica-2.7.3.dist-info}/top_level.txt +0 -0
pyPreservica/__init__.py
CHANGED
pyPreservica/uploadAPI.py
CHANGED
|
@@ -99,8 +99,8 @@ def prettify(elem):
|
|
|
99
99
|
def __create_io__(xip=None, file_name=None, parent_folder=None, **kwargs):
|
|
100
100
|
if xip is None:
|
|
101
101
|
xip = Element('xip:XIP')
|
|
102
|
+
xip.set('xmlns:xip', 'http://preservica.com/XIP/v6.0')
|
|
102
103
|
assert xip is not None
|
|
103
|
-
xip.set('xmlns:xip', 'http://preservica.com/XIP/v6.0')
|
|
104
104
|
io = SubElement(xip, 'xip:InformationObject')
|
|
105
105
|
ref = SubElement(io, 'xip:Ref')
|
|
106
106
|
|
|
@@ -598,12 +598,12 @@ def generic_asset_package(preservation_files_dict=None, access_files_dict=None,
|
|
|
598
598
|
for identifier_key, identifier_value in identifier_map.items():
|
|
599
599
|
if identifier_key:
|
|
600
600
|
if identifier_value:
|
|
601
|
-
identifier = SubElement(xip, 'Identifier')
|
|
602
|
-
id_type = SubElement(identifier, "Type")
|
|
601
|
+
identifier = SubElement(xip, 'xip:Identifier')
|
|
602
|
+
id_type = SubElement(identifier, "xip:Type")
|
|
603
603
|
id_type.text = identifier_key
|
|
604
|
-
id_value = SubElement(identifier, "Value")
|
|
604
|
+
id_value = SubElement(identifier, "xip:Value")
|
|
605
605
|
id_value.text = identifier_value
|
|
606
|
-
id_io = SubElement(identifier, "Entity")
|
|
606
|
+
id_io = SubElement(identifier, "xip:Entity")
|
|
607
607
|
id_io.text = io_ref
|
|
608
608
|
|
|
609
609
|
if 'Asset_Metadata' in kwargs:
|
|
@@ -613,22 +613,22 @@ def generic_asset_package(preservation_files_dict=None, access_files_dict=None,
|
|
|
613
613
|
if metadata_path:
|
|
614
614
|
if os.path.exists(metadata_path) and os.path.isfile(metadata_path):
|
|
615
615
|
descriptive_metadata = xml.etree.ElementTree.parse(source=metadata_path)
|
|
616
|
-
metadata = SubElement(xip, 'Metadata', {'schemaUri': metadata_ns})
|
|
617
|
-
metadata_ref = SubElement(metadata, 'Ref')
|
|
616
|
+
metadata = SubElement(xip, 'xip:Metadata', {'schemaUri': metadata_ns})
|
|
617
|
+
metadata_ref = SubElement(metadata, 'xip:Ref')
|
|
618
618
|
metadata_ref.text = str(uuid.uuid4())
|
|
619
|
-
entity = SubElement(metadata, 'Entity')
|
|
619
|
+
entity = SubElement(metadata, 'xip:Entity')
|
|
620
620
|
entity.text = io_ref
|
|
621
|
-
content = SubElement(metadata, 'Content')
|
|
621
|
+
content = SubElement(metadata, 'xip:Content')
|
|
622
622
|
content.append(descriptive_metadata.getroot())
|
|
623
623
|
elif isinstance(metadata_path, str):
|
|
624
624
|
try:
|
|
625
625
|
descriptive_metadata = xml.etree.ElementTree.fromstring(metadata_path)
|
|
626
|
-
metadata = SubElement(xip, 'Metadata', {'schemaUri': metadata_ns})
|
|
627
|
-
metadata_ref = SubElement(metadata, 'Ref')
|
|
626
|
+
metadata = SubElement(xip, 'xip:Metadata', {'schemaUri': metadata_ns})
|
|
627
|
+
metadata_ref = SubElement(metadata, 'xip:Ref')
|
|
628
628
|
metadata_ref.text = str(uuid.uuid4())
|
|
629
|
-
entity = SubElement(metadata, 'Entity')
|
|
629
|
+
entity = SubElement(metadata, 'xip:Entity')
|
|
630
630
|
entity.text = io_ref
|
|
631
|
-
content = SubElement(metadata, 'Content')
|
|
631
|
+
content = SubElement(metadata, 'xip:Content')
|
|
632
632
|
content.append(descriptive_metadata)
|
|
633
633
|
except RuntimeError:
|
|
634
634
|
logging.info(f"Could not parse asset metadata in namespace {metadata_ns}")
|
|
@@ -712,71 +712,72 @@ def multi_asset_package(asset_file_list=None, export_folder=None, parent_folder=
|
|
|
712
712
|
os.mkdir(os.path.join(inner_folder, CONTENT_FOLDER))
|
|
713
713
|
|
|
714
714
|
asset_map = dict()
|
|
715
|
-
xip = Element('XIP')
|
|
715
|
+
xip = Element('xip:XIP')
|
|
716
|
+
xip.set('xmlns:xip', 'http://preservica.com/XIP/v6.0')
|
|
716
717
|
for file in asset_file_list:
|
|
717
718
|
default_asset_title = os.path.splitext(os.path.basename(file))[0]
|
|
718
719
|
xip, io_ref = __create_io__(xip, file_name=default_asset_title, parent_folder=parent_folder, **kwargs)
|
|
719
720
|
asset_map[file] = io_ref
|
|
720
|
-
representation = SubElement(xip, 'Representation')
|
|
721
|
-
io_link = SubElement(representation, 'InformationObject')
|
|
721
|
+
representation = SubElement(xip, 'xip:Representation')
|
|
722
|
+
io_link = SubElement(representation, 'xip:InformationObject')
|
|
722
723
|
io_link.text = io_ref
|
|
723
|
-
access_name = SubElement(representation, 'Name')
|
|
724
|
+
access_name = SubElement(representation, 'xip:Name')
|
|
724
725
|
access_name.text = "Preservation"
|
|
725
|
-
access_type = SubElement(representation, 'Type')
|
|
726
|
+
access_type = SubElement(representation, 'xip:Type')
|
|
726
727
|
access_type.text = "Preservation"
|
|
727
|
-
content_objects = SubElement(representation, 'ContentObjects')
|
|
728
|
-
content_object = SubElement(content_objects, 'ContentObject')
|
|
728
|
+
content_objects = SubElement(representation, 'xip:ContentObjects')
|
|
729
|
+
content_object = SubElement(content_objects, 'xip:ContentObject')
|
|
729
730
|
content_object_ref = str(uuid.uuid4())
|
|
730
731
|
content_object.text = content_object_ref
|
|
731
732
|
|
|
732
733
|
default_content_objects_title = os.path.splitext(os.path.basename(file))[0]
|
|
733
|
-
content_object = SubElement(xip, 'ContentObject')
|
|
734
|
-
ref_element = SubElement(content_object, "Ref")
|
|
734
|
+
content_object = SubElement(xip, 'xip:ContentObject')
|
|
735
|
+
ref_element = SubElement(content_object, "xip:Ref")
|
|
735
736
|
ref_element.text = content_object_ref
|
|
736
|
-
title = SubElement(content_object, "Title")
|
|
737
|
+
title = SubElement(content_object, "xip:Title")
|
|
737
738
|
title.text = default_content_objects_title
|
|
738
|
-
description = SubElement(content_object, "Description")
|
|
739
|
+
description = SubElement(content_object, "xip:Description")
|
|
739
740
|
description.text = default_content_objects_title
|
|
740
|
-
security_tag_element = SubElement(content_object, "SecurityTag")
|
|
741
|
+
security_tag_element = SubElement(content_object, "xip:SecurityTag")
|
|
741
742
|
security_tag_element.text = security_tag
|
|
742
|
-
custom_type = SubElement(content_object, "CustomType")
|
|
743
|
+
custom_type = SubElement(content_object, "xip:CustomType")
|
|
743
744
|
custom_type.text = content_type
|
|
744
|
-
parent = SubElement(content_object, "Parent")
|
|
745
|
+
parent = SubElement(content_object, "xip:Parent")
|
|
745
746
|
parent.text = io_ref
|
|
746
747
|
|
|
747
|
-
generation = SubElement(xip, 'Generation', {"original": "true", "active": "true"})
|
|
748
|
-
content_object = SubElement(generation, "ContentObject")
|
|
748
|
+
generation = SubElement(xip, 'xip:Generation', {"original": "true", "active": "true"})
|
|
749
|
+
content_object = SubElement(generation, "xip:ContentObject")
|
|
749
750
|
content_object.text = content_object_ref
|
|
750
|
-
label = SubElement(generation, "Label")
|
|
751
|
+
label = SubElement(generation, "xip:Label")
|
|
751
752
|
label.text = os.path.splitext(os.path.basename(file))[0]
|
|
752
|
-
effective_date = SubElement(generation, "EffectiveDate")
|
|
753
|
+
effective_date = SubElement(generation, "xip:EffectiveDate")
|
|
753
754
|
effective_date.text = datetime.now().isoformat()
|
|
754
|
-
bitstreams = SubElement(generation, "Bitstreams")
|
|
755
|
-
bitstream = SubElement(bitstreams, "Bitstream")
|
|
755
|
+
bitstreams = SubElement(generation, "xip:Bitstreams")
|
|
756
|
+
bitstream = SubElement(bitstreams, "xip:Bitstream")
|
|
756
757
|
bitstream.text = os.path.basename(file)
|
|
757
|
-
SubElement(generation, "Formats")
|
|
758
|
-
SubElement(generation, "Properties")
|
|
758
|
+
SubElement(generation, "xip:Formats")
|
|
759
|
+
SubElement(generation, "xip:Properties")
|
|
759
760
|
|
|
760
|
-
bitstream = SubElement(xip, 'Bitstream')
|
|
761
|
-
filename_element = SubElement(bitstream, "Filename")
|
|
761
|
+
bitstream = SubElement(xip, 'xip:Bitstream')
|
|
762
|
+
filename_element = SubElement(bitstream, "xip:Filename")
|
|
762
763
|
filename_element.text = os.path.basename(file)
|
|
763
|
-
filesize = SubElement(bitstream, "FileSize")
|
|
764
|
+
filesize = SubElement(bitstream, "xip:FileSize")
|
|
764
765
|
file_stats = os.stat(file)
|
|
765
766
|
filesize.text = str(file_stats.st_size)
|
|
766
|
-
physical_location = SubElement(bitstream, "PhysicalLocation")
|
|
767
|
-
fixities = SubElement(bitstream, "Fixities")
|
|
767
|
+
physical_location = SubElement(bitstream, "xip:PhysicalLocation")
|
|
768
|
+
fixities = SubElement(bitstream, "xip:Fixities")
|
|
768
769
|
fixity_result = fixity_callback(filename_element.text, file)
|
|
769
770
|
if type(fixity_result) == tuple:
|
|
770
|
-
fixity = SubElement(fixities, "Fixity")
|
|
771
|
-
fixity_algorithm_ref = SubElement(fixity, "FixityAlgorithmRef")
|
|
772
|
-
fixity_value = SubElement(fixity, "FixityValue")
|
|
771
|
+
fixity = SubElement(fixities, "xip:Fixity")
|
|
772
|
+
fixity_algorithm_ref = SubElement(fixity, "xip:FixityAlgorithmRef")
|
|
773
|
+
fixity_value = SubElement(fixity, "xip:FixityValue")
|
|
773
774
|
fixity_algorithm_ref.text = fixity_result[0]
|
|
774
775
|
fixity_value.text = fixity_result[1]
|
|
775
776
|
elif type(fixity_result) == dict:
|
|
776
777
|
for key, val in fixity_result.items():
|
|
777
|
-
fixity = SubElement(fixities, "Fixity")
|
|
778
|
-
fixity_algorithm_ref = SubElement(fixity, "FixityAlgorithmRef")
|
|
779
|
-
fixity_value = SubElement(fixity, "FixityValue")
|
|
778
|
+
fixity = SubElement(fixities, "xip:Fixity")
|
|
779
|
+
fixity_algorithm_ref = SubElement(fixity, "xip:FixityAlgorithmRef")
|
|
780
|
+
fixity_value = SubElement(fixity, "xip:FixityValue")
|
|
780
781
|
fixity_algorithm_ref.text = key
|
|
781
782
|
fixity_value.text = val
|
|
782
783
|
else:
|
|
@@ -790,12 +791,12 @@ def multi_asset_package(asset_file_list=None, export_folder=None, parent_folder=
|
|
|
790
791
|
for identifier_key, identifier_value in identifier_map_values.items():
|
|
791
792
|
if identifier_key:
|
|
792
793
|
if identifier_value:
|
|
793
|
-
identifier = SubElement(xip, 'Identifier')
|
|
794
|
-
id_type = SubElement(identifier, "Type")
|
|
794
|
+
identifier = SubElement(xip, 'xip:Identifier')
|
|
795
|
+
id_type = SubElement(identifier, "xip:Type")
|
|
795
796
|
id_type.text = identifier_key
|
|
796
|
-
id_value = SubElement(identifier, "Value")
|
|
797
|
+
id_value = SubElement(identifier, "xip:Value")
|
|
797
798
|
id_value.text = identifier_value
|
|
798
|
-
id_io = SubElement(identifier, "Entity")
|
|
799
|
+
id_io = SubElement(identifier, "xip:Entity")
|
|
799
800
|
id_io.text = io_ref
|
|
800
801
|
|
|
801
802
|
src_file = file
|
pyPreservica/workflowAPI.py
CHANGED
|
@@ -245,13 +245,13 @@ class WorkflowAPI(AuthenticatedAPI):
|
|
|
245
245
|
assert instance_id == w_id
|
|
246
246
|
workflow_instance = WorkflowInstance(int(instance_id))
|
|
247
247
|
started_element = entity_response.find(f".//{{{NS_WORKFLOW}}}Started")
|
|
248
|
-
if started_element:
|
|
248
|
+
if started_element is not None:
|
|
249
249
|
if hasattr(started_element, "text"):
|
|
250
250
|
workflow_instance.started = datetime.datetime.strptime(started_element.text,
|
|
251
251
|
'%Y-%m-%dT%H:%M:%S.%fZ')
|
|
252
252
|
|
|
253
253
|
finished_element = entity_response.find(f".//{{{NS_WORKFLOW}}}Finished")
|
|
254
|
-
if finished_element:
|
|
254
|
+
if finished_element is not None:
|
|
255
255
|
if hasattr(finished_element, "text"):
|
|
256
256
|
workflow_instance.finished = datetime.datetime.strptime(finished_element.text,
|
|
257
257
|
'%Y-%m-%dT%H:%M:%S.%fZ')
|
|
@@ -353,13 +353,13 @@ class WorkflowAPI(AuthenticatedAPI):
|
|
|
353
353
|
workflow_instance = WorkflowInstance(int(instance_id))
|
|
354
354
|
|
|
355
355
|
started_element = instance.find(f".//{{{NS_WORKFLOW}}}Started")
|
|
356
|
-
if started_element:
|
|
356
|
+
if started_element is not None:
|
|
357
357
|
if hasattr(started_element, "text"):
|
|
358
358
|
workflow_instance.started = datetime.datetime.strptime(started_element.text,
|
|
359
359
|
'%Y-%m-%dT%H:%M:%S.%fZ')
|
|
360
360
|
|
|
361
361
|
finished_element = instance.find(f".//{{{NS_WORKFLOW}}}Finished")
|
|
362
|
-
if finished_element:
|
|
362
|
+
if finished_element is not None:
|
|
363
363
|
if hasattr(finished_element, "text"):
|
|
364
364
|
workflow_instance.finished = datetime.datetime.strptime(finished_element.text,
|
|
365
365
|
'%Y-%m-%dT%H:%M:%S.%fZ')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
pyPreservica/__init__.py,sha256=
|
|
1
|
+
pyPreservica/__init__.py,sha256=P43ePSmYs5TNWNeovJk4fDofqeOnOMPORRNB7U_1XQw,1117
|
|
2
2
|
pyPreservica/adminAPI.py,sha256=511bc5KtrCAXbDyBk39dmDnxUVDaOu6xaiyu0jYhxa4,37781
|
|
3
3
|
pyPreservica/authorityAPI.py,sha256=Eule8g6LXr8c8SFcJgpRah4lH1FgevUItO5HhHDEaZE,9172
|
|
4
4
|
pyPreservica/common.py,sha256=upTmwvPK9kcgSO3L8mfIMVrCOWJCCYIHi5GK516jOok,36518
|
|
@@ -9,12 +9,11 @@ pyPreservica/monitorAPI.py,sha256=HD-PUPdSI9wGAa07e2_2_-FLINH8PoWUwpFogz7F-j4,62
|
|
|
9
9
|
pyPreservica/opex.py,sha256=ccra1S4ojUXS3PlbU8WfxajOkJrwG4OykBnNrYP_jus,4875
|
|
10
10
|
pyPreservica/parAPI.py,sha256=bgaQvYfWNnzdD7ibKMV3ZV85pNkEdSoLsgVigoiFFfw,10771
|
|
11
11
|
pyPreservica/retentionAPI.py,sha256=Cx1ofz9V31a8c8utEfKYLlfQaHSaaqg_D4R3LUFBEx0,23612
|
|
12
|
-
pyPreservica/uploadAPI.py,sha256=
|
|
13
|
-
pyPreservica/vocabularyAPI.py,sha256=jPl6KDZoBGqlY0oEYjTpZ9kNEPzchDW-gyp-HH-MSKk,5729
|
|
12
|
+
pyPreservica/uploadAPI.py,sha256=4-WFkIYH825sO3Eche-35VVod7JLylzq8cTdaxPPpMo,94154
|
|
14
13
|
pyPreservica/webHooksAPI.py,sha256=0wP-59mep8gtlIZ9P5vV68-HnNdTuuo2kzGcDWj0bNg,6790
|
|
15
|
-
pyPreservica/workflowAPI.py,sha256=
|
|
16
|
-
pyPreservica-2.7.
|
|
17
|
-
pyPreservica-2.7.
|
|
18
|
-
pyPreservica-2.7.
|
|
19
|
-
pyPreservica-2.7.
|
|
20
|
-
pyPreservica-2.7.
|
|
14
|
+
pyPreservica/workflowAPI.py,sha256=WprAIqq_iLFZWB20CEhH30f3b9_lv_C4_3HP6cEFa6s,17371
|
|
15
|
+
pyPreservica-2.7.3.dist-info/LICENSE.txt,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
|
16
|
+
pyPreservica-2.7.3.dist-info/METADATA,sha256=yr3jrAmSy5J1nMluuhSlqtwDz_BSlgb8TUgGs1cTmwA,2784
|
|
17
|
+
pyPreservica-2.7.3.dist-info/WHEEL,sha256=YiKiUUeZQGmGJoR_0N1Y933DOBowq4AIvDe2-UIy8E4,91
|
|
18
|
+
pyPreservica-2.7.3.dist-info/top_level.txt,sha256=iIBh6NAznYQHOV8mv_y_kGKSDITek9rANyFDwJsbU-c,13
|
|
19
|
+
pyPreservica-2.7.3.dist-info/RECORD,,
|
pyPreservica/vocabularyAPI.py
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
pyPreservica ControlledVocabularyAPI module definition
|
|
3
|
-
|
|
4
|
-
A client library for the Preservica Repository web services Webhook API
|
|
5
|
-
https://us.preservica.com/api/reference-metadata/documentation.html
|
|
6
|
-
|
|
7
|
-
author: James Carr
|
|
8
|
-
licence: Apache License 2.0
|
|
9
|
-
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
from pyPreservica.common import *
|
|
13
|
-
|
|
14
|
-
logger = logging.getLogger(__name__)
|
|
15
|
-
|
|
16
|
-
BASE_ENDPOINT = '/api/reference-metadata'
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class Table:
|
|
20
|
-
def __init__(self, reference: str, name: str, security_tag: str, displayField: str, metadataConnections: list):
|
|
21
|
-
self.reference = reference
|
|
22
|
-
self.name = name
|
|
23
|
-
self.security_tag = security_tag
|
|
24
|
-
self.displayField = displayField
|
|
25
|
-
self.metadataConnections = metadataConnections
|
|
26
|
-
self.fields = None
|
|
27
|
-
|
|
28
|
-
def __str__(self):
|
|
29
|
-
return f"Ref:\t\t\t{self.reference}\n" \
|
|
30
|
-
f"Name:\t\t\t{self.name}\n" \
|
|
31
|
-
f"Security Tag:\t{self.security_tag}\n" \
|
|
32
|
-
f"Display Field:\t\t\t{self.displayField}\n" \
|
|
33
|
-
f"Metadata Connections:\t\t\t{self.metadataConnections}\n" \
|
|
34
|
-
f"Fields:\t\t\t{self.fields}\n"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class ControlledVocabularyAPI(AuthenticatedAPI):
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def load_skos(self, uri):
|
|
41
|
-
"""
|
|
42
|
-
Load a SKOS controlled vocabulary in skos RDF format
|
|
43
|
-
|
|
44
|
-
Simple Knowledge Organization System (SKOS)
|
|
45
|
-
|
|
46
|
-
:param uri:
|
|
47
|
-
:return:
|
|
48
|
-
"""
|
|
49
|
-
pass
|
|
50
|
-
|
|
51
|
-
def record(self, reference: str):
|
|
52
|
-
"""
|
|
53
|
-
Get individual record by its ref.
|
|
54
|
-
:param reference:
|
|
55
|
-
:return:
|
|
56
|
-
"""
|
|
57
|
-
headers = {HEADER_TOKEN: self.token, 'accept': 'application/json;charset=UTF-8'}
|
|
58
|
-
response = self.session.get(f'{self.protocol}://{self.server}{BASE_ENDPOINT}/records/{reference}',
|
|
59
|
-
headers=headers)
|
|
60
|
-
if response.status_code == requests.codes.unauthorized:
|
|
61
|
-
self.token = self.__token__()
|
|
62
|
-
return self.record(reference)
|
|
63
|
-
if response.status_code == requests.codes.ok:
|
|
64
|
-
json_response = str(response.content.decode('utf-8'))
|
|
65
|
-
return json.loads(json_response)
|
|
66
|
-
else:
|
|
67
|
-
exception = HTTPException("", response.status_code, response.url, "record",
|
|
68
|
-
response.content.decode('utf-8'))
|
|
69
|
-
logger.error(exception)
|
|
70
|
-
raise exception
|
|
71
|
-
|
|
72
|
-
def records(self, table: Table):
|
|
73
|
-
"""
|
|
74
|
-
Get all records from a table.
|
|
75
|
-
:return:
|
|
76
|
-
"""
|
|
77
|
-
headers = {HEADER_TOKEN: self.token, 'accept': 'application/json;charset=UTF-8'}
|
|
78
|
-
response = self.session.get(f'{self.protocol}://{self.server}{BASE_ENDPOINT}/tables/{table.reference}/records',
|
|
79
|
-
headers=headers)
|
|
80
|
-
if response.status_code == requests.codes.unauthorized:
|
|
81
|
-
self.token = self.__token__()
|
|
82
|
-
return self.records(table)
|
|
83
|
-
if response.status_code == requests.codes.ok:
|
|
84
|
-
json_response = str(response.content.decode('utf-8'))
|
|
85
|
-
return json.loads(json_response)['records']
|
|
86
|
-
else:
|
|
87
|
-
exception = HTTPException("", response.status_code, response.url, "records",
|
|
88
|
-
response.content.decode('utf-8'))
|
|
89
|
-
logger.error(exception)
|
|
90
|
-
raise exception
|
|
91
|
-
|
|
92
|
-
def table(self, reference: str):
|
|
93
|
-
"""
|
|
94
|
-
fetch a metadata table by id
|
|
95
|
-
|
|
96
|
-
:param reference:
|
|
97
|
-
:return:
|
|
98
|
-
"""
|
|
99
|
-
headers = {HEADER_TOKEN: self.token, 'accept': 'application/json;charset=UTF-8'}
|
|
100
|
-
response = self.session.get(f'{self.protocol}://{self.server}{BASE_ENDPOINT}/tables/{reference}',
|
|
101
|
-
headers=headers)
|
|
102
|
-
if response.status_code == requests.codes.unauthorized:
|
|
103
|
-
self.token = self.__token__()
|
|
104
|
-
return self.table(reference)
|
|
105
|
-
if response.status_code == requests.codes.ok:
|
|
106
|
-
json_response = str(response.content.decode('utf-8'))
|
|
107
|
-
doc = json.loads(json_response)
|
|
108
|
-
table = Table(doc['ref'], doc['name'], doc['securityDescriptor'], doc['displayField'],
|
|
109
|
-
doc['metadataConnections'])
|
|
110
|
-
table.fields = doc['fields']
|
|
111
|
-
return table
|
|
112
|
-
else:
|
|
113
|
-
exception = HTTPException("", response.status_code, response.url, "table",
|
|
114
|
-
response.content.decode('utf-8'))
|
|
115
|
-
logger.error(exception)
|
|
116
|
-
raise exception
|
|
117
|
-
|
|
118
|
-
def tables(self):
|
|
119
|
-
"""
|
|
120
|
-
List reference metadata tables, optionally filtering by metadata connections.
|
|
121
|
-
:return:
|
|
122
|
-
"""
|
|
123
|
-
headers = {HEADER_TOKEN: self.token, 'accept': 'application/json;charset=UTF-8'}
|
|
124
|
-
response = self.session.get(f'{self.protocol}://{self.server}{BASE_ENDPOINT}/tables', headers=headers)
|
|
125
|
-
if response.status_code == requests.codes.unauthorized:
|
|
126
|
-
self.token = self.__token__()
|
|
127
|
-
return self.tables()
|
|
128
|
-
if response.status_code == requests.codes.ok:
|
|
129
|
-
json_response = str(response.content.decode('utf-8'))
|
|
130
|
-
doc = json.loads(json_response)
|
|
131
|
-
results = set()
|
|
132
|
-
for table in doc['tables']:
|
|
133
|
-
t = Table(table['ref'], table['name'], table['securityDescriptor'], table['displayField'],
|
|
134
|
-
table['metadataConnections'])
|
|
135
|
-
results.add(t)
|
|
136
|
-
return results
|
|
137
|
-
else:
|
|
138
|
-
exception = HTTPException("", response.status_code, response.url, "tables",
|
|
139
|
-
response.content.decode('utf-8'))
|
|
140
|
-
logger.error(exception)
|
|
141
|
-
raise exception
|
|
File without changes
|
|
File without changes
|