isogeo_migrations_toolbelt.search_replace.search_and_replace module¶
Name: Backup SearchReplaceManager Purpose: Generic module to perform search and replace into metadatas Author: Isogeo
Python: 3.6+
-
class
isogeo_migrations_toolbelt.search_replace.search_and_replace.
SearchReplaceManager
(api_client: isogeo_pysdk.isogeo.Isogeo, objects_kind: str = 'metadata', attributes_patterns: dict = {'abstract': None, 'title': None}, prepositions: dict = None)[source]¶ Bases:
object
Search and replace Manager makes it easy to search into metadata attributes and replace existing value by a new one.
It uses the Isogeo Python SDK to download data asynchronously.
Parameters: - api_client (Isogeo) – API client authenticated to Isogeo
- objects_kind (str) – API objects type on which to apply the search replace. Defaults to ‘metadata’.
- attributes_patterns (dict) – dictionary of metadata attributes and tuple of “value to be replaced”, “replacement value”.
- prepositions (dict) – dictionary used to manage special cases related to prepositions. Structure: {“preposition to be replaced”: “replacement preposition”}
-
filter_matching_metadatas
(isogeo_search_results: list) → tuple[source]¶ Filter search results basing on matching patterns.
Parameters: isogeo_search_results (MetadataSearch) – Isogeo search results (MetadataSearch.results) Returns: a tuple of objects with the updated attributes Return type: tuple
-
replacer
(in_text: str, pattern: tuple) → str[source]¶ Filter search results basing on matching patterns.
Parameters: - in_text (str) – text into search a match
- pattern (tuple) – tuple of str (“to be replaced”, “replacement”)
-
search_replace
(search_params: dict = {'query': None}, safe: bool = 1) → dict[source]¶ It builds a list of metadata to export before transmitting it to an async loop.
Parameters: - search params (dict) – API client authenticated to Isogeo
- safe (bool) – safe mode enabled or not. In safe mode, the method do not apply modifications online but onyl returns the dictionary with replaced values.
Returns: dictionary of metadata with replaced values
Return type: dict
Example: