|
5 | 5 |
|
6 | 6 | import frontmatter
|
7 | 7 |
|
8 |
| -from geotribu_cli.constants import GeotribuDefaults, YamlHeaderMandatoryKeys |
| 8 | +from geotribu_cli.constants import ( |
| 9 | + GeotribuDefaults, |
| 10 | + YamlHeaderAvailableLicense, |
| 11 | + YamlHeaderMandatoryKeys, |
| 12 | +) |
9 | 13 | from geotribu_cli.json.json_client import JsonFeedClient
|
10 | 14 | from geotribu_cli.utils.check_image_size import get_image_dimensions_by_url
|
11 | 15 | from geotribu_cli.utils.check_path import check_path
|
|
14 | 18 | logger = logging.getLogger(__name__)
|
15 | 19 | defaults_settings = GeotribuDefaults()
|
16 | 20 |
|
| 21 | + |
17 | 22 | # ############################################################################
|
18 | 23 | # ########## CLI #################
|
19 | 24 | # ################################
|
@@ -144,6 +149,18 @@ def check_missing_mandatory_keys(keys: list[str]) -> tuple[bool, set[str]]:
|
144 | 149 | return len(missing) == 0, missing
|
145 | 150 |
|
146 | 151 |
|
| 152 | +def check_license(license_id: str) -> bool: |
| 153 | + """Vérifie que la licence choisie fait partie de celles disponibles. |
| 154 | +
|
| 155 | + Args: |
| 156 | + license: identifiant de la licence. |
| 157 | +
|
| 158 | + Returns: |
| 159 | + True si la licence est l'une de celles disponibles. |
| 160 | + """ |
| 161 | + return YamlHeaderAvailableLicense.has_value(license_id) |
| 162 | + |
| 163 | + |
147 | 164 | def run(args: argparse.Namespace) -> None:
|
148 | 165 | """Run the sub command logic.
|
149 | 166 |
|
@@ -232,3 +249,14 @@ def run(args: argparse.Namespace) -> None:
|
232 | 249 | raise ValueError(msg)
|
233 | 250 | else:
|
234 | 251 | logger.info("Clés de l'entête ok")
|
| 252 | + |
| 253 | + # check that license (if present) is in available licenses |
| 254 | + if "license" in yaml_meta: |
| 255 | + license_ok = check_license(yaml_meta["license"]) |
| 256 | + if not license_ok: |
| 257 | + msg = f"La licence ('{yaml_meta['license']}') n'est pas dans celles disponibles ({','.join([l.value for l in YamlHeaderAvailableLicense])})" |
| 258 | + logger.error(msg) |
| 259 | + if args.raise_exceptions: |
| 260 | + raise ValueError(msg) |
| 261 | + else: |
| 262 | + logger.info("licence ok") |
0 commit comments