Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entities extent #236

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion sdk_entrepot_gpf/scripts/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,7 +79,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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

à déplacer dans la fonction : on ne veut pas l'afficher s'il n'y a pas d'emprise

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:
Expand All @@ -93,6 +96,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, extent: str = None):
if o_entity.get("extent") is not None:
if extent != "Geojson":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if extent != "Geojson":
if extent != "geojson":

del o_entity._store_api_dict["extent"]
Comment on lines +102 to +103
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ça risque pas de détruire l'extent si on veut du wkt ?
il faudrait pas faire if extent is 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é.

Expand All @@ -109,6 +125,10 @@ 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", None) is not None:
Entities.print_entity(o_entity, self.args.extent)
b_return = False

# Gestion des actions liées aux Livraisons
if getattr(self.args, "open", False) is True:
assert isinstance(o_entity, Upload)
Expand Down Expand Up @@ -403,6 +423,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", choices=["wkt", "Geojson"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
o_sub_parser.add_argument("--extent", type=str, default=None, help="Affichage de toute la donnée selon le type", choices=["wkt", "Geojson"])
o_sub_parser.add_argument("--extent", type=str, default=None, help="Affichage de l'emprise selon le format demandé", 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]"""
Expand Down
Loading