pyPreservica 2.0.3__py3-none-any.whl → 3.3.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.
Potentially problematic release.
This version of pyPreservica might be problematic. Click here for more details.
- pyPreservica/__init__.py +19 -7
- pyPreservica/adminAPI.py +43 -33
- pyPreservica/authorityAPI.py +9 -9
- pyPreservica/common.py +198 -54
- pyPreservica/contentAPI.py +199 -18
- pyPreservica/entityAPI.py +944 -250
- pyPreservica/mdformsAPI.py +572 -0
- pyPreservica/monitorAPI.py +3 -3
- pyPreservica/parAPI.py +7 -40
- pyPreservica/retentionAPI.py +58 -26
- pyPreservica/settingsAPI.py +295 -0
- pyPreservica/uploadAPI.py +426 -609
- pyPreservica/webHooksAPI.py +3 -1
- pyPreservica/workflowAPI.py +21 -37
- {pyPreservica-2.0.3.dist-info → pypreservica-3.3.3.dist-info}/METADATA +93 -84
- pypreservica-3.3.3.dist-info/RECORD +20 -0
- {pyPreservica-2.0.3.dist-info → pypreservica-3.3.3.dist-info}/WHEEL +1 -1
- pyPreservica/vocabularyAPI.py +0 -141
- pyPreservica-2.0.3.dist-info/RECORD +0 -19
- {pyPreservica-2.0.3.dist-info → pypreservica-3.3.3.dist-info/licenses}/LICENSE.txt +0 -0
- {pyPreservica-2.0.3.dist-info → pypreservica-3.3.3.dist-info}/top_level.txt +0 -0
pyPreservica/__init__.py
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
"""
|
|
2
|
-
pyPreservica
|
|
2
|
+
pyPreservica package definition
|
|
3
3
|
import API classes, for entity, content, upload, workflows & retention
|
|
4
4
|
|
|
5
5
|
author: James Carr
|
|
6
6
|
licence: Apache License 2.0
|
|
7
7
|
|
|
8
8
|
"""
|
|
9
|
+
|
|
9
10
|
from .common import *
|
|
10
|
-
from .contentAPI import ContentAPI
|
|
11
|
+
from .contentAPI import ContentAPI, Field, SortOrder
|
|
11
12
|
from .entityAPI import EntityAPI
|
|
12
|
-
from .uploadAPI import
|
|
13
|
-
|
|
13
|
+
from .uploadAPI import (
|
|
14
|
+
UploadAPI,
|
|
15
|
+
simple_asset_package,
|
|
16
|
+
complex_asset_package,
|
|
17
|
+
cvs_to_xsd,
|
|
18
|
+
cvs_to_xml,
|
|
19
|
+
cvs_to_cmis_xslt,
|
|
20
|
+
csv_to_search_xml,
|
|
21
|
+
generic_asset_package,
|
|
22
|
+
upload_config,
|
|
23
|
+
multi_asset_package,
|
|
24
|
+
)
|
|
14
25
|
from .workflowAPI import WorkflowAPI, WorkflowContext, WorkflowInstance
|
|
15
26
|
from .retentionAPI import RetentionAPI, RetentionAssignment, RetentionPolicy
|
|
16
27
|
from .parAPI import PreservationActionRegistry
|
|
@@ -18,11 +29,12 @@ from .adminAPI import AdminAPI
|
|
|
18
29
|
from .monitorAPI import MonitorAPI, MonitorCategory, MonitorStatus, MessageStatus
|
|
19
30
|
from .webHooksAPI import WebHooksAPI, TriggerType, WebHookHandler
|
|
20
31
|
from .authorityAPI import AuthorityAPI, Table
|
|
21
|
-
|
|
32
|
+
from .mdformsAPI import MetadataGroupsAPI, Group, GroupField, GroupFieldType
|
|
33
|
+
from .settingsAPI import SettingsAPI
|
|
22
34
|
|
|
23
35
|
__author__ = "James Carr (drjamescarr@gmail.com)"
|
|
24
36
|
|
|
25
|
-
# Version of the
|
|
26
|
-
__version__ = "
|
|
37
|
+
# Version of the pyPreservica package
|
|
38
|
+
__version__ = "3.3.3"
|
|
27
39
|
|
|
28
40
|
__license__ = "Apache License Version 2.0"
|
pyPreservica/adminAPI.py
CHANGED
|
@@ -10,7 +10,7 @@ licence: Apache License 2.0
|
|
|
10
10
|
"""
|
|
11
11
|
import csv
|
|
12
12
|
import xml.etree.ElementTree
|
|
13
|
-
from typing import List, Any
|
|
13
|
+
from typing import List, Any, Union
|
|
14
14
|
|
|
15
15
|
from pyPreservica.common import *
|
|
16
16
|
|
|
@@ -36,7 +36,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
36
36
|
request = self.session.delete(f'{self.protocol}://{self.server}/api/admin/security/roles/{role_name}',
|
|
37
37
|
headers=headers)
|
|
38
38
|
if request.status_code == requests.codes.no_content:
|
|
39
|
-
return
|
|
39
|
+
return None
|
|
40
40
|
elif request.status_code == requests.codes.unauthorized:
|
|
41
41
|
self.token = self.__token__()
|
|
42
42
|
return self.delete_system_role(role_name)
|
|
@@ -61,7 +61,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
61
61
|
request = self.session.delete(f'{self.protocol}://{self.server}/api/admin/security/tags/{tag_name}',
|
|
62
62
|
headers=headers)
|
|
63
63
|
if request.status_code == requests.codes.no_content:
|
|
64
|
-
return
|
|
64
|
+
return None
|
|
65
65
|
elif request.status_code == requests.codes.unauthorized:
|
|
66
66
|
self.token = self.__token__()
|
|
67
67
|
return self.delete_security_tag(tag_name)
|
|
@@ -211,7 +211,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
211
211
|
headers = {HEADER_TOKEN: self.token, 'Content-Type': 'application/xml;charset=UTF-8'}
|
|
212
212
|
request = self.session.delete(f'{self.protocol}://{self.server}/api/admin/users/{username}', headers=headers)
|
|
213
213
|
if request.status_code == requests.codes.no_content:
|
|
214
|
-
return
|
|
214
|
+
return None
|
|
215
215
|
elif request.status_code == requests.codes.unauthorized:
|
|
216
216
|
self.token = self.__token__()
|
|
217
217
|
return self.delete_user(username)
|
|
@@ -251,8 +251,9 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
251
251
|
xml.etree.ElementTree.SubElement(xml_roles, "Role").text = role
|
|
252
252
|
xml_request = xml.etree.ElementTree.tostring(xml_object, encoding='utf-8')
|
|
253
253
|
logger.debug(xml_request)
|
|
254
|
+
params = {"source": "UX2"}
|
|
254
255
|
request = self.session.post(f'{self.protocol}://{self.server}/api/admin/users', data=xml_request,
|
|
255
|
-
headers=headers)
|
|
256
|
+
headers=headers, params=params)
|
|
256
257
|
if request.status_code == requests.codes.created:
|
|
257
258
|
return self.user_details(username)
|
|
258
259
|
elif request.status_code == requests.codes.unauthorized:
|
|
@@ -373,16 +374,16 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
373
374
|
self._check_if_user_has_manager_role()
|
|
374
375
|
return self._account_status_(username, "false", "disable_user")
|
|
375
376
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
377
|
+
def enable_user(self, username):
|
|
378
|
+
"""
|
|
379
|
+
Enable a Preservica User
|
|
380
|
+
|
|
381
|
+
:param username: email address of the preservica user
|
|
382
|
+
:type username: str
|
|
383
|
+
|
|
384
|
+
"""
|
|
385
|
+
self._check_if_user_has_manager_role()
|
|
386
|
+
return self._account_status_(username, "true", "enable_user")
|
|
386
387
|
|
|
387
388
|
def user_report(self, report_name="users.csv"):
|
|
388
389
|
"""
|
|
@@ -444,7 +445,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
444
445
|
:param xml_data: The xml schema as a UTF-8 string or a file like object
|
|
445
446
|
:type xml_data: Any
|
|
446
447
|
|
|
447
|
-
:return:
|
|
448
|
+
:return:
|
|
448
449
|
:rtype: None
|
|
449
450
|
"""
|
|
450
451
|
|
|
@@ -463,7 +464,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
463
464
|
params=params,
|
|
464
465
|
data=xml_data)
|
|
465
466
|
if request.status_code == requests.codes.created:
|
|
466
|
-
return
|
|
467
|
+
return None
|
|
467
468
|
elif request.status_code == requests.codes.unauthorized:
|
|
468
469
|
self.token = self.__token__()
|
|
469
470
|
return self.add_xml_schema(name, description, originalName, xml_data)
|
|
@@ -493,7 +494,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
493
494
|
:param document_type: The type of the XML document, defaults to descriptive metadata templates
|
|
494
495
|
:type document_type: str
|
|
495
496
|
|
|
496
|
-
:return:
|
|
497
|
+
:return:
|
|
497
498
|
:rtype: None
|
|
498
499
|
|
|
499
500
|
"""
|
|
@@ -513,7 +514,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
513
514
|
params=params,
|
|
514
515
|
data=xml_data)
|
|
515
516
|
if request.status_code == requests.codes.created:
|
|
516
|
-
return
|
|
517
|
+
return None
|
|
517
518
|
elif request.status_code == requests.codes.unauthorized:
|
|
518
519
|
self.token = self.__token__()
|
|
519
520
|
return self.add_xml_document(name, xml_data, document_type)
|
|
@@ -523,12 +524,12 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
523
524
|
|
|
524
525
|
def delete_xml_document(self, uri: str):
|
|
525
526
|
"""
|
|
526
|
-
Delete
|
|
527
|
+
Delete an XML document from Preservica's XML document store
|
|
527
528
|
|
|
528
529
|
:param uri: The URI of the xml document to delete
|
|
529
530
|
:type uri: str
|
|
530
531
|
|
|
531
|
-
:return:
|
|
532
|
+
:return:
|
|
532
533
|
:rtype: None
|
|
533
534
|
|
|
534
535
|
"""
|
|
@@ -543,13 +544,14 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
543
544
|
f"{self.protocol}://{self.server}/api/admin/documents/{document['ApiId']}",
|
|
544
545
|
headers=headers)
|
|
545
546
|
if request.status_code == requests.codes.no_content:
|
|
546
|
-
return
|
|
547
|
+
return None
|
|
547
548
|
elif request.status_code == requests.codes.unauthorized:
|
|
548
549
|
self.token = self.__token__()
|
|
549
550
|
return self.delete_xml_document(uri)
|
|
550
551
|
else:
|
|
551
552
|
logger.error(request.content.decode('utf-8'))
|
|
552
553
|
raise RuntimeError(request.status_code, "delete_xml_document failed")
|
|
554
|
+
return None
|
|
553
555
|
|
|
554
556
|
def delete_xml_schema(self, uri: str):
|
|
555
557
|
"""
|
|
@@ -558,7 +560,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
558
560
|
:param uri: The URI of the xml schema to delete
|
|
559
561
|
:type uri: str
|
|
560
562
|
|
|
561
|
-
:return:
|
|
563
|
+
:return:
|
|
562
564
|
:rtype: None
|
|
563
565
|
|
|
564
566
|
"""
|
|
@@ -572,17 +574,18 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
572
574
|
request = self.session.delete(f"{self.protocol}://{self.server}/api/admin/schemas/{schema['ApiId']}",
|
|
573
575
|
headers=headers)
|
|
574
576
|
if request.status_code == requests.codes.no_content:
|
|
575
|
-
return
|
|
577
|
+
return None
|
|
576
578
|
elif request.status_code == requests.codes.unauthorized:
|
|
577
579
|
self.token = self.__token__()
|
|
578
580
|
return self.delete_xml_schema(uri)
|
|
579
581
|
else:
|
|
580
582
|
logger.error(request.content.decode('utf-8'))
|
|
581
583
|
raise RuntimeError(request.status_code, "delete_xml_schema failed")
|
|
584
|
+
return None
|
|
582
585
|
|
|
583
|
-
def xml_schema(self, uri: str) -> str:
|
|
586
|
+
def xml_schema(self, uri: str) -> Union[str, None]:
|
|
584
587
|
"""
|
|
585
|
-
|
|
588
|
+
Fetch the metadata schema XSD document as a string by its URI
|
|
586
589
|
|
|
587
590
|
:param uri: The URI of the xml schema
|
|
588
591
|
:type uri: str
|
|
@@ -607,8 +610,9 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
607
610
|
else:
|
|
608
611
|
logger.error(request.content.decode('utf-8'))
|
|
609
612
|
raise RuntimeError(request.status_code, "xml_schema failed")
|
|
613
|
+
return None
|
|
610
614
|
|
|
611
|
-
def xml_document(self, uri: str) -> str:
|
|
615
|
+
def xml_document(self, uri: str) -> Union[str, None]:
|
|
612
616
|
"""
|
|
613
617
|
fetch the metadata XML document as a string by its URI
|
|
614
618
|
|
|
@@ -634,6 +638,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
634
638
|
else:
|
|
635
639
|
logger.error(request.content.decode('utf-8'))
|
|
636
640
|
raise RuntimeError(request.status_code, "xml_document failed")
|
|
641
|
+
return None
|
|
637
642
|
|
|
638
643
|
def xml_documents(self) -> List:
|
|
639
644
|
"""
|
|
@@ -695,7 +700,10 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
695
700
|
aip_id = schema.find(f'.//{{{self.admin_ns}}}ApiId')
|
|
696
701
|
schema_dict['SchemaUri'] = schema_uri.text
|
|
697
702
|
schema_dict['Name'] = name.text
|
|
698
|
-
|
|
703
|
+
if description is not None:
|
|
704
|
+
schema_dict['Description'] = description.text
|
|
705
|
+
else:
|
|
706
|
+
schema_dict['Description'] = ""
|
|
699
707
|
schema_dict['ApiId'] = aip_id.text
|
|
700
708
|
results.append(schema_dict)
|
|
701
709
|
return results
|
|
@@ -751,7 +759,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
751
759
|
logger.error(request.content.decode('utf-8'))
|
|
752
760
|
raise RuntimeError(request.status_code, "xml_transforms failed")
|
|
753
761
|
|
|
754
|
-
def xml_transform(self, input_uri: str, output_uri: str) -> str:
|
|
762
|
+
def xml_transform(self, input_uri: str, output_uri: str) -> Union[str, None]:
|
|
755
763
|
"""
|
|
756
764
|
fetch the XML transform as a string by its URIs
|
|
757
765
|
|
|
@@ -779,6 +787,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
779
787
|
else:
|
|
780
788
|
logger.error(request.content.decode('utf-8'))
|
|
781
789
|
raise RuntimeError(request.status_code, "xml_transform failed")
|
|
790
|
+
return None
|
|
782
791
|
|
|
783
792
|
def delete_xml_transform(self, input_uri: str, output_uri: str):
|
|
784
793
|
"""
|
|
@@ -790,7 +799,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
790
799
|
:param output_uri: The URI of the output XML document
|
|
791
800
|
:type output_uri: str
|
|
792
801
|
|
|
793
|
-
:return:
|
|
802
|
+
:return:
|
|
794
803
|
:rtype: None
|
|
795
804
|
|
|
796
805
|
"""
|
|
@@ -805,13 +814,14 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
805
814
|
f"{self.protocol}://{self.server}/api/admin/transforms/{transform['ApiId']}",
|
|
806
815
|
headers=headers)
|
|
807
816
|
if request.status_code == requests.codes.no_content:
|
|
808
|
-
return
|
|
817
|
+
return None
|
|
809
818
|
elif request.status_code == requests.codes.unauthorized:
|
|
810
819
|
self.token = self.__token__()
|
|
811
820
|
return self.delete_xml_transform(input_uri, output_uri)
|
|
812
821
|
else:
|
|
813
822
|
logger.error(request.content.decode('utf-8'))
|
|
814
823
|
raise RuntimeError(request.status_code, "delete_xml_transform failed")
|
|
824
|
+
return None
|
|
815
825
|
|
|
816
826
|
def add_xml_transform(self, name: str, input_uri: str, output_uri: str, purpose: str, originalName: str,
|
|
817
827
|
xml_data: Any):
|
|
@@ -836,7 +846,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
836
846
|
:param xml_data: The transform xml as a string or file like object
|
|
837
847
|
:type xml_data: Any
|
|
838
848
|
|
|
839
|
-
:return:
|
|
849
|
+
:return:
|
|
840
850
|
:rtype: None
|
|
841
851
|
|
|
842
852
|
"""
|
|
@@ -857,7 +867,7 @@ class AdminAPI(AuthenticatedAPI):
|
|
|
857
867
|
params=params,
|
|
858
868
|
data=xml_data)
|
|
859
869
|
if request.status_code == requests.codes.created:
|
|
860
|
-
return
|
|
870
|
+
return None
|
|
861
871
|
|
|
862
872
|
if request.status_code == requests.codes.unauthorized:
|
|
863
873
|
self.token = self.__token__()
|
pyPreservica/authorityAPI.py
CHANGED
|
@@ -8,9 +8,9 @@ author: James Carr
|
|
|
8
8
|
licence: Apache License 2.0
|
|
9
9
|
|
|
10
10
|
"""
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
import csv
|
|
13
|
-
import
|
|
13
|
+
from typing import List, Set
|
|
14
14
|
|
|
15
15
|
from pyPreservica.common import *
|
|
16
16
|
|
|
@@ -54,7 +54,7 @@ class AuthorityAPI(AuthenticatedAPI):
|
|
|
54
54
|
self.token = self.__token__()
|
|
55
55
|
return self.delete_record(reference)
|
|
56
56
|
if response.status_code == requests.codes.no_content:
|
|
57
|
-
return
|
|
57
|
+
return None
|
|
58
58
|
else:
|
|
59
59
|
exception = HTTPException("", response.status_code, response.url, "delete_record",
|
|
60
60
|
response.content.decode('utf-8'))
|
|
@@ -91,7 +91,7 @@ class AuthorityAPI(AuthenticatedAPI):
|
|
|
91
91
|
:param table: The Table to add the record to
|
|
92
92
|
:type: table: Table
|
|
93
93
|
|
|
94
|
-
:param record: The record
|
|
94
|
+
:param record: The record as a dictionary
|
|
95
95
|
:type: record: dict
|
|
96
96
|
|
|
97
97
|
:return: A single record
|
|
@@ -122,7 +122,7 @@ class AuthorityAPI(AuthenticatedAPI):
|
|
|
122
122
|
"""
|
|
123
123
|
Return a record by its reference
|
|
124
124
|
|
|
125
|
-
:param reference: The record
|
|
125
|
+
:param reference: The reference of the record
|
|
126
126
|
:type: reference: str
|
|
127
127
|
|
|
128
128
|
:return: A single record
|
|
@@ -144,11 +144,11 @@ class AuthorityAPI(AuthenticatedAPI):
|
|
|
144
144
|
logger.error(exception)
|
|
145
145
|
raise exception
|
|
146
146
|
|
|
147
|
-
def records(self, table: Table) ->
|
|
147
|
+
def records(self, table: Table) -> List[dict]:
|
|
148
148
|
"""
|
|
149
149
|
Return all records from a table
|
|
150
150
|
|
|
151
|
-
:param table: The authority table
|
|
151
|
+
:param table: The authority table to return the records from
|
|
152
152
|
:type: table: Table
|
|
153
153
|
|
|
154
154
|
:return: List of records
|
|
@@ -177,7 +177,7 @@ class AuthorityAPI(AuthenticatedAPI):
|
|
|
177
177
|
:param reference: The reference for the authority table
|
|
178
178
|
:type: reference: str
|
|
179
179
|
|
|
180
|
-
:return: An authority table
|
|
180
|
+
:return: An authority table of interest
|
|
181
181
|
:rtype: Table
|
|
182
182
|
|
|
183
183
|
"""
|
|
@@ -200,7 +200,7 @@ class AuthorityAPI(AuthenticatedAPI):
|
|
|
200
200
|
logger.error(exception)
|
|
201
201
|
raise exception
|
|
202
202
|
|
|
203
|
-
def tables(self) ->
|
|
203
|
+
def tables(self) -> Set[Table]:
|
|
204
204
|
"""
|
|
205
205
|
List reference metadata tables
|
|
206
206
|
|