|
9 | 9 | # All configuration parameters defined in
|
10 | 10 | # this file can be overriden in instance/config.py
|
11 | 11 |
|
| 12 | +import json |
12 | 13 | import os
|
13 | 14 | from os import environ
|
14 | 15 | import subprocess
|
|
136 | 137 | :type: string
|
137 | 138 | """
|
138 | 139 |
|
139 |
| -# Page information |
140 |
| -run = subprocess.run( |
141 |
| - ["git", "describe", "--tags"], |
142 |
| - stdout=subprocess.PIPE, |
143 |
| - check=False, |
144 |
| - cwd=os.path.dirname(__file__), |
145 |
| -) |
146 |
| -VERSION = run.stdout.decode("utf-8") |
| 140 | + |
| 141 | +if os.path.exists(".git"): |
| 142 | + # If git is here, version is extracted from git tags |
| 143 | + run = subprocess.run( |
| 144 | + ["git", "describe", "--tags"], |
| 145 | + stdout=subprocess.PIPE, |
| 146 | + check=False, |
| 147 | + cwd=os.path.dirname(__file__), |
| 148 | + ) |
| 149 | + VERSION = run.stdout.decode("utf-8") |
| 150 | +elif os.path.exists("metadata.json"): |
| 151 | + # If metadata is here, version is extracted from docker metadata |
| 152 | + try: |
| 153 | + with open("metadata.json", "r", encoding="utf-8") as file: |
| 154 | + VERSION = json.load(file)["labels"]["org.opencontainers.image.version"] |
| 155 | + except json.JSONDecodeError: |
| 156 | + print("Erreur : Le fichier 'metadata.json' est mal formé.") |
| 157 | + VERSION = "" |
| 158 | + except KeyError as e: |
| 159 | + print(f"Erreur : La clé {e} est manquante dans le fichier 'metadata.json'.") |
| 160 | + VERSION = "" |
| 161 | + except TypeError: |
| 162 | + print("Erreur : Le format du fichier JSON n'est pas valide.") |
| 163 | + VERSION = "" |
| 164 | +else: |
| 165 | + VERSION = "" |
| 166 | + |
147 | 167 | # FAVICON= "img/icon/favicon.ico"
|
148 | 168 | FAVICON = "caf/favicon.ico"
|
149 | 169 | """URL to the site favicon
|
|
0 commit comments