ckanapi-harvesters 0.0.0__py3-none-any.whl → 0.0.2__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.
Files changed (110) hide show
  1. ckanapi_harvesters/__init__.py +32 -10
  2. ckanapi_harvesters/auxiliary/__init__.py +26 -0
  3. ckanapi_harvesters/auxiliary/ckan_action.py +93 -0
  4. ckanapi_harvesters/auxiliary/ckan_api_key.py +213 -0
  5. ckanapi_harvesters/auxiliary/ckan_auxiliary.py +293 -0
  6. ckanapi_harvesters/auxiliary/ckan_configuration.py +50 -0
  7. ckanapi_harvesters/auxiliary/ckan_defs.py +10 -0
  8. ckanapi_harvesters/auxiliary/ckan_errors.py +129 -0
  9. ckanapi_harvesters/auxiliary/ckan_map.py +509 -0
  10. ckanapi_harvesters/auxiliary/ckan_model.py +992 -0
  11. ckanapi_harvesters/auxiliary/ckan_vocabulary_deprecated.py +104 -0
  12. ckanapi_harvesters/auxiliary/deprecated.py +82 -0
  13. ckanapi_harvesters/auxiliary/error_level_message.py +51 -0
  14. ckanapi_harvesters/auxiliary/external_code_import.py +98 -0
  15. ckanapi_harvesters/auxiliary/list_records.py +60 -0
  16. ckanapi_harvesters/auxiliary/login.py +163 -0
  17. ckanapi_harvesters/auxiliary/path.py +208 -0
  18. ckanapi_harvesters/auxiliary/proxy_config.py +298 -0
  19. ckanapi_harvesters/auxiliary/urls.py +40 -0
  20. ckanapi_harvesters/builder/__init__.py +40 -0
  21. ckanapi_harvesters/builder/builder_aux.py +20 -0
  22. ckanapi_harvesters/builder/builder_ckan.py +238 -0
  23. ckanapi_harvesters/builder/builder_errors.py +36 -0
  24. ckanapi_harvesters/builder/builder_field.py +122 -0
  25. ckanapi_harvesters/builder/builder_package.py +9 -0
  26. ckanapi_harvesters/builder/builder_package_1_basic.py +1291 -0
  27. ckanapi_harvesters/builder/builder_package_2_harvesters.py +40 -0
  28. ckanapi_harvesters/builder/builder_package_3_multi_threaded.py +45 -0
  29. ckanapi_harvesters/builder/builder_package_example.xlsx +0 -0
  30. ckanapi_harvesters/builder/builder_resource.py +589 -0
  31. ckanapi_harvesters/builder/builder_resource_datastore.py +561 -0
  32. ckanapi_harvesters/builder/builder_resource_datastore_multi_abc.py +367 -0
  33. ckanapi_harvesters/builder/builder_resource_datastore_multi_folder.py +273 -0
  34. ckanapi_harvesters/builder/builder_resource_datastore_multi_harvester.py +278 -0
  35. ckanapi_harvesters/builder/builder_resource_datastore_unmanaged.py +145 -0
  36. ckanapi_harvesters/builder/builder_resource_datastore_url.py +150 -0
  37. ckanapi_harvesters/builder/builder_resource_init.py +126 -0
  38. ckanapi_harvesters/builder/builder_resource_multi_abc.py +361 -0
  39. ckanapi_harvesters/builder/builder_resource_multi_datastore.py +146 -0
  40. ckanapi_harvesters/builder/builder_resource_multi_file.py +505 -0
  41. ckanapi_harvesters/builder/example/__init__.py +21 -0
  42. ckanapi_harvesters/builder/example/builder_example.py +21 -0
  43. ckanapi_harvesters/builder/example/builder_example_aux_fun.py +24 -0
  44. ckanapi_harvesters/builder/example/builder_example_download.py +44 -0
  45. ckanapi_harvesters/builder/example/builder_example_generate_data.py +73 -0
  46. ckanapi_harvesters/builder/example/builder_example_patch_upload.py +51 -0
  47. ckanapi_harvesters/builder/example/builder_example_policy.py +114 -0
  48. ckanapi_harvesters/builder/example/builder_example_test_sql.py +53 -0
  49. ckanapi_harvesters/builder/example/builder_example_tests.py +87 -0
  50. ckanapi_harvesters/builder/example/builder_example_tests_offline.py +57 -0
  51. ckanapi_harvesters/builder/example/package/ckan-dpg.svg +74 -0
  52. ckanapi_harvesters/builder/example/package/users_local.csv +3 -0
  53. ckanapi_harvesters/builder/mapper_datastore.py +93 -0
  54. ckanapi_harvesters/builder/mapper_datastore_multi.py +262 -0
  55. ckanapi_harvesters/builder/specific/__init__.py +11 -0
  56. ckanapi_harvesters/builder/specific/configuration_builder.py +66 -0
  57. ckanapi_harvesters/builder/specific_builder_abc.py +23 -0
  58. ckanapi_harvesters/ckan_api/__init__.py +20 -0
  59. ckanapi_harvesters/ckan_api/ckan_api.py +11 -0
  60. ckanapi_harvesters/ckan_api/ckan_api_0_base.py +896 -0
  61. ckanapi_harvesters/ckan_api/ckan_api_1_map.py +1028 -0
  62. ckanapi_harvesters/ckan_api/ckan_api_2_readonly.py +934 -0
  63. ckanapi_harvesters/ckan_api/ckan_api_3_policy.py +229 -0
  64. ckanapi_harvesters/ckan_api/ckan_api_4_readwrite.py +579 -0
  65. ckanapi_harvesters/ckan_api/ckan_api_5_manage.py +1225 -0
  66. ckanapi_harvesters/ckan_api/ckan_api_params.py +192 -0
  67. ckanapi_harvesters/ckan_api/deprecated/__init__.py +9 -0
  68. ckanapi_harvesters/ckan_api/deprecated/ckan_api_deprecated.py +267 -0
  69. ckanapi_harvesters/ckan_api/deprecated/ckan_api_deprecated_vocabularies.py +189 -0
  70. ckanapi_harvesters/harvesters/__init__.py +23 -0
  71. ckanapi_harvesters/harvesters/data_cleaner/__init__.py +17 -0
  72. ckanapi_harvesters/harvesters/data_cleaner/data_cleaner_abc.py +240 -0
  73. ckanapi_harvesters/harvesters/data_cleaner/data_cleaner_errors.py +23 -0
  74. ckanapi_harvesters/harvesters/data_cleaner/data_cleaner_upload.py +9 -0
  75. ckanapi_harvesters/harvesters/data_cleaner/data_cleaner_upload_1_basic.py +430 -0
  76. ckanapi_harvesters/harvesters/data_cleaner/data_cleaner_upload_2_geom.py +98 -0
  77. ckanapi_harvesters/harvesters/file_formats/__init__.py +10 -0
  78. ckanapi_harvesters/harvesters/file_formats/csv_format.py +43 -0
  79. ckanapi_harvesters/harvesters/file_formats/file_format_abc.py +39 -0
  80. ckanapi_harvesters/harvesters/file_formats/file_format_init.py +25 -0
  81. ckanapi_harvesters/harvesters/file_formats/shp_format.py +129 -0
  82. ckanapi_harvesters/harvesters/harvester_abc.py +190 -0
  83. ckanapi_harvesters/harvesters/harvester_errors.py +31 -0
  84. ckanapi_harvesters/harvesters/harvester_init.py +30 -0
  85. ckanapi_harvesters/harvesters/harvester_model.py +49 -0
  86. ckanapi_harvesters/harvesters/harvester_params.py +323 -0
  87. ckanapi_harvesters/harvesters/postgre_harvester.py +495 -0
  88. ckanapi_harvesters/harvesters/postgre_params.py +86 -0
  89. ckanapi_harvesters/harvesters/pymongo_data_cleaner.py +173 -0
  90. ckanapi_harvesters/harvesters/pymongo_harvester.py +355 -0
  91. ckanapi_harvesters/harvesters/pymongo_params.py +54 -0
  92. ckanapi_harvesters/policies/__init__.py +20 -0
  93. ckanapi_harvesters/policies/data_format_policy.py +269 -0
  94. ckanapi_harvesters/policies/data_format_policy_abc.py +97 -0
  95. ckanapi_harvesters/policies/data_format_policy_custom_fields.py +156 -0
  96. ckanapi_harvesters/policies/data_format_policy_defs.py +135 -0
  97. ckanapi_harvesters/policies/data_format_policy_errors.py +79 -0
  98. ckanapi_harvesters/policies/data_format_policy_lists.py +234 -0
  99. ckanapi_harvesters/policies/data_format_policy_tag_groups.py +35 -0
  100. ckanapi_harvesters/reports/__init__.py +11 -0
  101. ckanapi_harvesters/reports/admin_report.py +292 -0
  102. {ckanapi_harvesters-0.0.0.dist-info → ckanapi_harvesters-0.0.2.dist-info}/METADATA +74 -38
  103. ckanapi_harvesters-0.0.2.dist-info/RECORD +105 -0
  104. ckanapi_harvesters/divider/__init__.py +0 -27
  105. ckanapi_harvesters/divider/divider.py +0 -53
  106. ckanapi_harvesters/divider/divider_error.py +0 -59
  107. ckanapi_harvesters/main.py +0 -30
  108. ckanapi_harvesters-0.0.0.dist-info/RECORD +0 -9
  109. {ckanapi_harvesters-0.0.0.dist-info → ckanapi_harvesters-0.0.2.dist-info}/WHEEL +0 -0
  110. {ckanapi_harvesters-0.0.0.dist-info → ckanapi_harvesters-0.0.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,50 @@
1
+ #!python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Parameters which apply to the package
5
+ """
6
+ from typing import Union
7
+
8
+
9
+ ## Package containing CKAN data format policy
10
+ configuration_package_name = "configuration"
11
+ policy_resource = "data_format_policy.json"
12
+
13
+ default_ckan_has_postgis: bool = True
14
+ epsg_wgs84 = 4326 # WGS-84
15
+ default_ckan_target_epsg: Union[int,None] = epsg_wgs84 # default target geodesic system
16
+
17
+
18
+ allow_no_ca = False
19
+
20
+ def unlock_no_ca(value:bool=True) -> None:
21
+ """
22
+ This function enables you to disable the CA verification of the CKAN server.
23
+
24
+ __Warning__:
25
+ Only allow in a local environment!
26
+
27
+ :return:
28
+ """
29
+ global allow_no_ca
30
+ allow_no_ca = value
31
+
32
+ ## Resource download from external urls
33
+ download_external_resource_urls:bool = True
34
+
35
+ def unlock_external_url_resource_download(value:bool=True) -> None:
36
+ """
37
+ This function enables the download of resources external from the CKAN server.
38
+
39
+ :return:
40
+ """
41
+ global download_external_resource_urls
42
+ download_external_resource_urls = value
43
+
44
+
45
+ ## External code execution
46
+ # see: external_code_import
47
+
48
+ ## Defining a data policy from an url
49
+ allow_policy_from_url:bool = False
50
+
@@ -0,0 +1,10 @@
1
+ #!python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Data model to represent a CKAN database architecture
5
+ """
6
+
7
+ ckan_tags_sep = ',' # separator for tags, fields in primary key, indexes, queries
8
+ ckan_timestamp_sep = 'T' # separator for timestamp ISO format
9
+ environ_keyword = "environ"
10
+
@@ -0,0 +1,129 @@
1
+ #!python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ CKAN error types
5
+ """
6
+ from typing import Iterable
7
+ import requests
8
+
9
+ # import to make these error codes available from here:
10
+ from ckanapi_harvesters.auxiliary.ckan_action import (CkanActionError, CkanAuthorizationError, CkanNotFoundError,
11
+ CkanSqlCapabilityError)
12
+ from ckanapi_harvesters.auxiliary.path import BaseDirUndefError
13
+
14
+
15
+ ## Specific error types ------------------
16
+ class ApiKeyFileError(Exception):
17
+ pass
18
+
19
+ class InvalidParameterError(Exception):
20
+ pass
21
+
22
+ class FileOrDirNotExistError(Exception):
23
+ def __init__(self, path: str):
24
+ super().__init__(f"Path doesn't lead to a file or directory: {path}")
25
+
26
+ class CkanMandatoryArgumentError(Exception):
27
+ def __init__(self, action_name: str, attribute_name: str):
28
+ super().__init__(f"Argument '{attribute_name}' is required for {action_name}")
29
+
30
+ class MandatoryAttributeError(Exception):
31
+ def __init__(self, object_type: str, attribute_name: str):
32
+ super().__init__(f"Attribute '{attribute_name}' is required for {object_type} to initiate builder")
33
+
34
+ class MissingIdError(Exception):
35
+ def __init__(self, object_type: str, object_name):
36
+ super().__init__(f"Attribute 'id' is required for {object_type} '{object_name}' to update CKAN map")
37
+
38
+ class CkanServerError(Exception):
39
+ def __init__(self, ckan, response: requests.Response, msg:str, display_request:bool=True):
40
+ super().__init__(msg)
41
+ self.response = response
42
+ self.status_code = response.status_code
43
+ if display_request:
44
+ ckan._error_print_debug_response(response)
45
+
46
+ def __str__(self):
47
+ return f"Server code [{self.status_code}]: " + super().__str__()
48
+
49
+ class DataStoreNotFoundError(Exception):
50
+ def __init__(self, resource_id:str, error_message: str):
51
+ super().__init__(f"DataStore not found for resource id {resource_id}. This could mean the DataStore was not initialized. Server message: {error_message}")
52
+
53
+ class DuplicateNameError(Exception):
54
+ def __init__(self, object_type:str, names:Iterable[str]):
55
+ super().__init__(f"Duplicate names were found for {object_type}: {','.join(names)}")
56
+
57
+ class ForbiddenNameError(Exception):
58
+ def __init__(self, object_type:str, names:Iterable[str]):
59
+ super().__init__(f"Forbidden name for {object_type}: {','.join(names)}")
60
+
61
+ class IntegrityError(Exception):
62
+ pass
63
+
64
+ class ReadOnlyError(Exception):
65
+ def __init__(self):
66
+ super().__init__("Mode is set to read only. Please set the read_only flag to False.")
67
+
68
+ class AdminFeatureLockedError(Exception):
69
+ def __init__(self):
70
+ super().__init__("Admin features are locked. Please set the enable_admin flag to True.")
71
+
72
+ class NotMappedObjectNameError(Exception):
73
+ pass
74
+
75
+ class UnexpectedError(RuntimeError):
76
+ pass
77
+
78
+ class UrlError(Exception):
79
+ pass
80
+
81
+ class MaxRequestsCountError(Exception):
82
+ def __init__(self):
83
+ super().__init__("Maximum requests count was reached.")
84
+
85
+ class CkanArgumentError(Exception):
86
+ def __init__(self, api_name:str, argument_name:str):
87
+ super().__init__(f"Argument {argument_name} is not supported by API {api_name}.")
88
+
89
+ class ArgumentError(Exception):
90
+ pass
91
+
92
+ class SearchAllNoCountsError(ArgumentError):
93
+ def __init__(self, api_name:str, argument_name_value:str=None):
94
+ if argument_name_value is None:
95
+ super().__init__(f"{api_name} must parse results to compute the number of rows returned. Argument return_df=False is incompatible with multi-request mode search_all=True")
96
+ else:
97
+ super().__init__(f"{api_name} must parse results to compute the number of rows returned. Arguments return_df=False and {argument_name_value} are incompatible with multi-request mode search_all=True")
98
+
99
+ class FunctionMissingArgumentError(Exception):
100
+ def __init__(self, function_name:str, argument_name:str):
101
+ super().__init__(f"Argument {argument_name} is mandatory for function {function_name}.")
102
+
103
+ class NoDefaultView(Exception):
104
+ def __init__(self, resource_format:str):
105
+ super().__init__(f"No default view defined for resource format {resource_format}")
106
+
107
+ class ExternalUrlLockedError(Exception):
108
+ def __init__(self, url:str):
109
+ super().__init__(f"Downloading external urls is blocked by parameter download_external_urls (url {url}). Run unlock_external_url_resource_download to enable this feature.")
110
+
111
+ class NoCAVerificationError(Exception):
112
+ def __init__(self):
113
+ super().__init__("The CA verification cannot be disabled. To unlock this feature, run unlock_no_ca to enable this feature. Warning: Only allow in a local environment!")
114
+
115
+ class RequestError(Exception):
116
+ pass
117
+
118
+ class RequirementError(Exception):
119
+ pass
120
+
121
+ class FileFormatRequirementError(RequirementError):
122
+ def __init__(self, requirement:str, file_format:str):
123
+ super().__init__(f"The package {requirement} is required to support this file format ({file_format}).")
124
+
125
+ # PostGIS
126
+ class UnknownTargetCRSError(RequirementError):
127
+ def __init__(self, source_crs, context:str):
128
+ super().__init__(f"Unknown destination CRS (source={source_crs}) for {context}.")
129
+