From ec1439028b46be1b71e038abb7194b0f18de8cd5 Mon Sep 17 00:00:00 2001 From: Ronan Date: Thu, 20 Feb 2025 10:23:03 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Suppression=20de=20la=20partie=20extent=20l?= =?UTF-8?q?orsqu'elle=20n'est=20pas=20demand=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdk_entrepot_gpf/scripts/entities.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/sdk_entrepot_gpf/scripts/entities.py b/sdk_entrepot_gpf/scripts/entities.py index 4dfb540..726ba0c 100644 --- a/sdk_entrepot_gpf/scripts/entities.py +++ b/sdk_entrepot_gpf/scripts/entities.py @@ -77,7 +77,8 @@ def __init__(self, datastore: Optional[str], entity_type: str, idu: Optional[str if self.action(o_entity): # si ça retourne True # On affiche l'entité Config().om.info(f"Affichage de l'entité {o_entity}", green_colored=True) - Config().om.info(o_entity.to_json(indent=3)) + Entities.print_entity(o_entity, None) + Config().om.info("Emprise masquée, utilisez la commande --extent pour l'afficher") elif getattr(self.args, "publish_by_label", False) is True: Entities.action_annexe_publish_by_labels(self.args.publish_by_label.split(","), datastore=self.datastore) elif getattr(self.args, "unpublish_by_label", False) is True: @@ -93,6 +94,19 @@ def __init__(self, datastore: Optional[str], entity_type: str, idu: Optional[str l_props = str(Config().get("cli", f"list_{self.entity_type}", "_id,name")) print(tabulate([o_e.get_store_properties(l_props.split(",")) for o_e in l_entities], headers="keys")) + @staticmethod + def print_entity(o_entity: StoreEntity, type: str = None): + o_copy_entity = o_entity + l_possibles_types = ["show", "Geojson", "wkt"] + print(type) + if type not in l_possibles_types: + type = None + if type == None: + if o_entity.get("extent") != None: + del o_copy_entity._store_api_dict["extent"] + + + Config().om.info(o_copy_entity.to_json(indent=3)) def action(self, o_entity: StoreEntity) -> bool: # pylint:disable=too-many-return-statements """Traite les actions s'il y a lieu. Renvoie true si on doit afficher l'entité. @@ -109,6 +123,11 @@ def action(self, o_entity: StoreEntity) -> bool: # pylint:disable=too-many-retu Entities.action_entity_delete(o_entity, self.args.cascade, self.args.force, self.datastore) b_return = False + if getattr(self.args, "extent", False) is True: + assert(issubclass(o_entity.__class__, StoreEntity)) + Entities.print_entity(o_entity, self.args.type) + b_return = False + # Gestion des actions liées aux Livraisons if getattr(self.args, "open", False) is True: assert isinstance(o_entity, Upload) @@ -403,6 +422,7 @@ def complete_parser_entities(o_sub_parsers: argparse._SubParsersAction[argparse. # Filtres o_sub_parser.add_argument("--infos", "-i", type=str, default=None, help=f"Filtrer les {o_entity.entity_titles()} selon les infos") o_sub_parser.add_argument("--page", "-p", type=int, default=None, help="Page à récupérer. Toutes si non indiqué.") + o_sub_parser.add_argument("--extent", type=str, default=None, help="Affichage de toute la donnée selon le type") if issubclass(o_entity, TagInterface): l_epilog.append( f""" * lister les {o_entity.entity_titles()} avec d'optionnels filtres sur les infos et les tags : {o_entity.entity_name()} [--infos INFO=VALEUR] [--tags TAG=VALEUR]""" From 157e3e8d5d78fb88a62677002ecbc57bb27f304c Mon Sep 17 00:00:00 2001 From: Ronan Date: Thu, 20 Feb 2025 14:05:13 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Finalisation=20de=20l'affichage=20de=20la?= =?UTF-8?q?=20g=C3=A9om=C3=A9trie=20uniquemenet=20a=20la=20demande?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdk_entrepot_gpf/scripts/entities.py | 31 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/sdk_entrepot_gpf/scripts/entities.py b/sdk_entrepot_gpf/scripts/entities.py index 726ba0c..30cca0b 100644 --- a/sdk_entrepot_gpf/scripts/entities.py +++ b/sdk_entrepot_gpf/scripts/entities.py @@ -3,6 +3,8 @@ import argparse import re from typing import Callable, List, Optional +from shapely.geometry import shape +from shapely.wkt import dumps from tabulate import tabulate from sdk_entrepot_gpf.Errors import GpfSdkError @@ -95,18 +97,16 @@ def __init__(self, datastore: Optional[str], entity_type: str, idu: Optional[str print(tabulate([o_e.get_store_properties(l_props.split(",")) for o_e in l_entities], headers="keys")) @staticmethod - def print_entity(o_entity: StoreEntity, type: str = None): - o_copy_entity = o_entity - l_possibles_types = ["show", "Geojson", "wkt"] - print(type) - if type not in l_possibles_types: - type = None - if type == None: - if o_entity.get("extent") != None: - del o_copy_entity._store_api_dict["extent"] - - - Config().om.info(o_copy_entity.to_json(indent=3)) + def print_entity(o_entity: StoreEntity, extent: str = None): + if o_entity.get("extent") is not None: + if extent == "wkt": + o_entity._store_api_dict["extent"] = dumps(shape(o_entity.get("extent")["geometry"])) + # if extent == "show": + # coordinates = o_entity.get("extent")["geometry"]["coordinates"] + # m = folium.Map(location = coordinates[0], zoom_start=10) + # folium.Polygon(coordinates, color="blue", fill= True).add_to(m) + Config().om.info(o_entity.to_json(indent=3)) + def action(self, o_entity: StoreEntity) -> bool: # pylint:disable=too-many-return-statements """Traite les actions s'il y a lieu. Renvoie true si on doit afficher l'entité. @@ -123,9 +123,8 @@ def action(self, o_entity: StoreEntity) -> bool: # pylint:disable=too-many-retu Entities.action_entity_delete(o_entity, self.args.cascade, self.args.force, self.datastore) b_return = False - if getattr(self.args, "extent", False) is True: - assert(issubclass(o_entity.__class__, StoreEntity)) - Entities.print_entity(o_entity, self.args.type) + if getattr(self.args, "extent", None) is not None: + Entities.print_entity(o_entity, self.args.extent) b_return = False # Gestion des actions liées aux Livraisons @@ -422,7 +421,7 @@ def complete_parser_entities(o_sub_parsers: argparse._SubParsersAction[argparse. # Filtres o_sub_parser.add_argument("--infos", "-i", type=str, default=None, help=f"Filtrer les {o_entity.entity_titles()} selon les infos") o_sub_parser.add_argument("--page", "-p", type=int, default=None, help="Page à récupérer. Toutes si non indiqué.") - o_sub_parser.add_argument("--extent", type=str, default=None, help="Affichage de toute la donnée selon le type") + o_sub_parser.add_argument("--extent", type=str, default=None, help="Affichage de toute la donnée selon le type", choices=["wkt", "Geojson"]) if issubclass(o_entity, TagInterface): l_epilog.append( f""" * lister les {o_entity.entity_titles()} avec d'optionnels filtres sur les infos et les tags : {o_entity.entity_name()} [--infos INFO=VALEUR] [--tags TAG=VALEUR]""" From da391301af3d9cb03980fe39752d617b4a3d7a17 Mon Sep 17 00:00:00 2001 From: Ronan Date: Thu, 20 Feb 2025 14:08:02 +0100 Subject: [PATCH 3/3] Correction d'une suppression --- sdk_entrepot_gpf/scripts/entities.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk_entrepot_gpf/scripts/entities.py b/sdk_entrepot_gpf/scripts/entities.py index 30cca0b..a30e4f4 100644 --- a/sdk_entrepot_gpf/scripts/entities.py +++ b/sdk_entrepot_gpf/scripts/entities.py @@ -99,6 +99,8 @@ def __init__(self, datastore: Optional[str], entity_type: str, idu: Optional[str @staticmethod def print_entity(o_entity: StoreEntity, extent: str = None): if o_entity.get("extent") is not None: + if extent != "Geojson": + del o_entity._store_api_dict["extent"] if extent == "wkt": o_entity._store_api_dict["extent"] = dumps(shape(o_entity.get("extent")["geometry"])) # if extent == "show":