mirror of
https://github.com/Alex38Lyon/Synthese-PSM_LARRA.git
synced 2026-11-29 19:58:36 +00:00
update
This commit is contained in:
1 parent
a62c4b43b5
commit
6aa878c6de
3 files changed
+173
-82
No files matched your search
@@ -90,6 +90,9 @@ class Colors:
|
||||
UNDERLINE = "\033[4m"
|
||||
|
||||
|
||||
INTERACTIF = sys.stdout.isatty() and sys.stderr.isatty()
|
||||
|
||||
|
||||
#################################################################################################
|
||||
# Formatter pour la console avec couleurs
|
||||
#################################################################################################
|
||||
@@ -97,11 +100,12 @@ class ConsoleFormatter(logging.Formatter):
|
||||
def format(self, record):
|
||||
color = COLOR_CODES.get(record.levelno, "")
|
||||
message = super().format(record)
|
||||
return f"{color}{message}{RESET}"
|
||||
|
||||
return f"{color}{message}{RESET}" if INTERACTIF else strip_ansi_codes(message)
|
||||
|
||||
|
||||
#################################################################################################
|
||||
# Supprime les codes ANSI (pour l'écriture dans les fichiers)
|
||||
# Supprime les codes ANSI (pour l'écriture dans les fichiers ou en mode non interactif)
|
||||
#################################################################################################
|
||||
def strip_ansi_codes(text):
|
||||
ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
|
||||
@@ -115,6 +119,7 @@ class FileFormatter(logging.Formatter):
|
||||
def format(self, record):
|
||||
clean_msg = strip_ansi_codes(record.getMessage())
|
||||
prefix = "!!! " if record.levelno >= logging.ERROR else ""
|
||||
|
||||
record_copy = logging.LogRecord(
|
||||
name=record.name,
|
||||
level=record.levelno,
|
||||
@@ -139,17 +144,17 @@ def setup_logger(logfile="app.log", debug_log=False):
|
||||
|
||||
min_level = logging.DEBUG if debug_log else logging.INFO
|
||||
|
||||
# Console stderr handler — affichage à l'écran avec couleurs
|
||||
# Console stderr handler — couleurs uniquement en mode interactif
|
||||
stderr_handler = logging.StreamHandler(sys.stderr)
|
||||
stderr_handler.setLevel(min_level)
|
||||
stderr_formatter = ConsoleFormatter("%(levelname)s: %(message)s") # <-- Ta classe personnalisée
|
||||
stderr_formatter = ConsoleFormatter("%(levelname)s: %(message)s")
|
||||
stderr_handler.setFormatter(stderr_formatter)
|
||||
logger.addHandler(stderr_handler)
|
||||
|
||||
# File handler — fichier de log
|
||||
# File handler — fichier de log sans codes ANSI
|
||||
file_handler = logging.FileHandler(logfile, encoding="utf-8")
|
||||
file_handler.setLevel(min_level)
|
||||
file_formatter = FileFormatter("%(asctime)s - %(levelname)s - %(message)s") # <-- Ta classe personnalisée
|
||||
file_formatter = FileFormatter("%(asctime)s - %(levelname)s - %(message)s")
|
||||
file_handler.setFormatter(file_formatter)
|
||||
logger.addHandler(file_handler)
|
||||
|
||||
|
||||
@@ -1,67 +1,69 @@
|
||||
2026-10-14 15:29:53,697 - INFO - ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
2026-10-14 15:29:53,698 - INFO - INFORMATIONS DU PROJET MERGIN MAPS
|
||||
2026-10-14 15:29:53,698 - INFO - ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
2026-10-14 15:29:53,868 - INFO - Projet : ARR
|
||||
2026-10-14 15:29:53,869 - INFO - Identifiant : 1707d35a-d99f-47a9-a714-519d7d9c147e
|
||||
2026-10-14 15:29:53,870 - INFO - Version : v17
|
||||
2026-10-14 15:29:53,870 - INFO - Créé le : 2026-08-19T09:31:30Z
|
||||
2026-10-14 15:29:53,870 - INFO - Mis à jour : 2026-10-14T08:39:10Z
|
||||
2026-10-14 15:29:53,870 - INFO - Taille totale : 128415971 Octets
|
||||
2026-10-14 15:29:53,871 - INFO - Public : True
|
||||
2026-10-14 15:29:53,871 - INFO - Nbre de fichiers : 14
|
||||
2026-10-14 15:29:53,871 - INFO - Taille totale : 122.47 Mo
|
||||
2026-10-14 15:29:53,872 - INFO - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
2026-10-14 15:29:53,872 - INFO - 20260819_115533.jpeg 2.632 Mo
|
||||
2026-10-14 15:29:53,872 - INFO - ARR.gpkg 93.309 Mo
|
||||
2026-10-14 15:29:53,872 - INFO - ARR.qgs 0.713 Mo
|
||||
2026-10-14 15:29:53,873 - INFO - ARR_attachments.zip 0.002 Mo
|
||||
2026-10-14 15:29:53,873 - INFO - Inventaire Cavités.gpkg 0.660 Mo
|
||||
2026-10-14 15:29:53,873 - INFO - JPEG_20260819_113638_3152669861975410066.jpg 3.024 Mo
|
||||
2026-10-14 15:29:53,873 - INFO - JPEG_20260819_113919_5886287470656202827.jpg 3.034 Mo
|
||||
2026-10-14 15:29:53,874 - INFO - JPEG_20260819_121951_8365685850227103103.jpg 2.974 Mo
|
||||
2026-10-14 15:29:53,874 - INFO - JPEG_20260819_122929_1446792337025110147.jpg 3.007 Mo
|
||||
2026-10-14 15:29:53,874 - INFO - JPEG_20260819_123117_33265926990508961.jpg 2.516 Mo
|
||||
2026-10-14 15:29:53,875 - INFO - JPEG_20260819_124915_3186813976814177670.jpg 2.899 Mo
|
||||
2026-10-14 15:29:53,875 - INFO - JPEG_20260819_125124_7007318829424129864.jpg 3.165 Mo
|
||||
2026-10-14 15:29:53,875 - INFO - Tests/areas2dMasked.gpkg 4.531 Mo
|
||||
2026-10-14 15:29:53,875 - INFO - karstpro_etude.json 0.001 Mo
|
||||
2026-10-14 15:29:53,875 - INFO - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
2026-10-14 15:29:53,876 - INFO - ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
2026-10-14 15:29:53,876 - INFO - Envoi des données GitHub vers Mergin Maps
|
||||
2026-10-14 15:29:53,876 - INFO - ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
2026-10-14 15:29:53,878 - INFO - [1/5] Téléchargement desfichiers depuis le GitHub : Alex38Lyon/Synthese-PSM_LARRA@main:Outputs/SHP/QGis_GPKG_Files/areas2dMasked.gpkg
|
||||
2026-10-14 15:29:55,701 - INFO - [2/5] Synchronisation du projet local existant : C:\Users\alexa\Desktop\pyDatatoMergin\Temp_mergin\Projet
|
||||
2026-10-14 15:29:56,655 - INFO - [3/5] Copie des fichiers C:\Users\alexa\Desktop\pyDatatoMergin\Temp_mergin\Github\areas2dMasked.gpkg
|
||||
2026-10-14 15:29:56,663 - INFO - + Tests\areas2dMasked.gpkg
|
||||
2026-10-14 15:29:56,664 - INFO - [4/5] Push vers Mergin Maps...
|
||||
2026-10-14 15:29:57,050 - WARNING - Aucune modification à envoyer.
|
||||
2026-10-14 15:29:57,050 - INFO - [5/5] Push terminé. Nettoyage...
|
||||
2026-10-14 15:29:57,053 - INFO - Envoi terminé avec succès.
|
||||
2026-10-14 15:29:57,053 - INFO - ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
2026-10-14 15:29:57,053 - INFO - INFORMATIONS DU PROJET MERGIN MAPS
|
||||
2026-10-14 15:29:57,053 - INFO - ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
2026-10-14 15:29:57,225 - INFO - Projet : ARR
|
||||
2026-10-14 15:29:57,225 - INFO - Identifiant : 1707d35a-d99f-47a9-a714-519d7d9c147e
|
||||
2026-10-14 15:29:57,225 - INFO - Version : v17
|
||||
2026-10-14 15:29:57,225 - INFO - Créé le : 2026-08-19T09:31:30Z
|
||||
2026-10-14 15:29:57,226 - INFO - Mis à jour : 2026-10-14T08:39:10Z
|
||||
2026-10-14 15:29:57,226 - INFO - Taille totale : 128415971 Octets
|
||||
2026-10-14 15:29:57,226 - INFO - Public : True
|
||||
2026-10-14 15:29:57,226 - INFO - Nbre de fichiers : 14
|
||||
2026-10-14 15:29:57,227 - INFO - Taille totale : 122.47 Mo
|
||||
2026-10-14 15:29:57,227 - INFO - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
2026-10-14 15:29:57,227 - INFO - 20260819_115533.jpeg 2.632 Mo
|
||||
2026-10-14 15:29:57,227 - INFO - ARR.gpkg 93.309 Mo
|
||||
2026-10-14 15:29:57,228 - INFO - ARR.qgs 0.713 Mo
|
||||
2026-10-14 15:29:57,228 - INFO - ARR_attachments.zip 0.002 Mo
|
||||
2026-10-14 15:29:57,228 - INFO - Inventaire Cavités.gpkg 0.660 Mo
|
||||
2026-10-14 15:29:57,228 - INFO - JPEG_20260819_113638_3152669861975410066.jpg 3.024 Mo
|
||||
2026-10-14 15:29:57,228 - INFO - JPEG_20260819_113919_5886287470656202827.jpg 3.034 Mo
|
||||
2026-10-14 15:29:57,228 - INFO - JPEG_20260819_121951_8365685850227103103.jpg 2.974 Mo
|
||||
2026-10-14 15:29:57,228 - INFO - JPEG_20260819_122929_1446792337025110147.jpg 3.007 Mo
|
||||
2026-10-14 15:29:57,229 - INFO - JPEG_20260819_123117_33265926990508961.jpg 2.516 Mo
|
||||
2026-10-14 15:29:57,229 - INFO - JPEG_20260819_124915_3186813976814177670.jpg 2.899 Mo
|
||||
2026-10-14 15:29:57,229 - INFO - JPEG_20260819_125124_7007318829424129864.jpg 3.165 Mo
|
||||
2026-10-14 15:29:57,229 - INFO - Tests/areas2dMasked.gpkg 4.531 Mo
|
||||
2026-10-14 15:29:57,230 - INFO - karstpro_etude.json 0.001 Mo
|
||||
2026-10-14 15:29:57,230 - INFO - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
2026-10-14 22:42:00,253 - INFO - ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
2026-10-14 22:42:00,253 - INFO - INFORMATIONS DU PROJET MERGIN MAPS
|
||||
2026-10-14 22:42:00,253 - INFO - ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
2026-10-14 22:42:00,389 - INFO - Projet : ARR
|
||||
2026-10-14 22:42:00,391 - INFO - Identifiant : 1707d35a-d99f-47a9-a714-519d7d9c147e
|
||||
2026-10-14 22:42:00,391 - INFO - Version : v17
|
||||
2026-10-14 22:42:00,391 - INFO - Créé le : 2026-08-19T09:31:30Z
|
||||
2026-10-14 22:42:00,391 - INFO - Mis à jour : 2026-10-14T08:39:10Z
|
||||
2026-10-14 22:42:00,392 - INFO - Taille totale : 128415971 Octets
|
||||
2026-10-14 22:42:00,392 - INFO - Public : True
|
||||
2026-10-14 22:42:00,392 - INFO - Nbre de fichiers : 14
|
||||
2026-10-14 22:42:00,392 - INFO - Taille totale : 122.47 Mo
|
||||
2026-10-14 22:42:00,393 - INFO - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
2026-10-14 22:42:00,393 - INFO - 20260819_115533.jpeg 2.632 Mo
|
||||
2026-10-14 22:42:00,393 - INFO - ARR.gpkg 93.309 Mo
|
||||
2026-10-14 22:42:00,393 - INFO - ARR.qgs 0.713 Mo
|
||||
2026-10-14 22:42:00,393 - INFO - ARR_attachments.zip 0.002 Mo
|
||||
2026-10-14 22:42:00,394 - INFO - Inventaire Cavités.gpkg 0.660 Mo
|
||||
2026-10-14 22:42:00,394 - INFO - JPEG_20260819_113638_3152669861975410066.jpg 3.024 Mo
|
||||
2026-10-14 22:42:00,394 - INFO - JPEG_20260819_113919_5886287470656202827.jpg 3.034 Mo
|
||||
2026-10-14 22:42:00,394 - INFO - JPEG_20260819_121951_8365685850227103103.jpg 2.974 Mo
|
||||
2026-10-14 22:42:00,394 - INFO - JPEG_20260819_122929_1446792337025110147.jpg 3.007 Mo
|
||||
2026-10-14 22:42:00,394 - INFO - JPEG_20260819_123117_33265926990508961.jpg 2.516 Mo
|
||||
2026-10-14 22:42:00,394 - INFO - JPEG_20260819_124915_3186813976814177670.jpg 2.899 Mo
|
||||
2026-10-14 22:42:00,395 - INFO - JPEG_20260819_125124_7007318829424129864.jpg 3.165 Mo
|
||||
2026-10-14 22:42:00,395 - INFO - Tests/areas2dMasked.gpkg 4.531 Mo
|
||||
2026-10-14 22:42:00,395 - INFO - karstpro_etude.json 0.001 Mo
|
||||
2026-10-14 22:42:00,395 - INFO - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
2026-10-14 22:42:00,395 - INFO - ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
2026-10-14 22:42:00,395 - INFO - Envoi des données GitHub vers Mergin Maps
|
||||
2026-10-14 22:42:00,396 - INFO - ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
2026-10-14 22:42:00,396 - INFO - [1/5] Téléchargement desfichiers depuis le GitHub : Alex38Lyon/Synthese-PSM_LARRA@main:Outputs/SHP/QGis_GPKG_Files/areas2dMasked.gpkg
|
||||
2026-10-14 22:42:00,481 - INFO - Téléchargement GitHub : Alex38Lyon/Synthese-PSM_LARRA/main, chemin Outputs/SHP/QGis_GPKG_Files/areas2dMasked.gpkg
|
||||
2026-10-14 22:42:01,300 - INFO - Téléchargement GitHub terminé : 1 fichier(s), 4751360 octets.
|
||||
2026-10-14 22:42:01,302 - INFO - [2/5] Synchronisation du projet local existant : D:\08_GitHub\Synthese-PSM_LARRA\Scripts\pyDatatoMergin\Temp_mergin\Projet
|
||||
2026-10-14 22:42:02,080 - INFO - [3/5] Copie des fichiers D:\08_GitHub\Synthese-PSM_LARRA\Scripts\pyDatatoMergin\Temp_mergin\Github\areas2dMasked.gpkg
|
||||
2026-10-14 22:42:02,085 - INFO - + Tests\areas2dMasked.gpkg
|
||||
2026-10-14 22:42:02,086 - INFO - [4/5] Push vers Mergin Maps...
|
||||
2026-10-14 22:42:02,442 - WARNING - Aucune modification à envoyer.
|
||||
2026-10-14 22:42:02,442 - INFO - [5/5] Push terminé. Nettoyage...
|
||||
2026-10-14 22:42:02,444 - INFO - Envoi terminé avec succès.
|
||||
2026-10-14 22:42:02,444 - INFO - ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
2026-10-14 22:42:02,444 - INFO - INFORMATIONS DU PROJET MERGIN MAPS
|
||||
2026-10-14 22:42:02,444 - INFO - ═══════════════════════════════════════════════════════════════════════════════════════════════
|
||||
2026-10-14 22:42:02,590 - INFO - Projet : ARR
|
||||
2026-10-14 22:42:02,591 - INFO - Identifiant : 1707d35a-d99f-47a9-a714-519d7d9c147e
|
||||
2026-10-14 22:42:02,592 - INFO - Version : v17
|
||||
2026-10-14 22:42:02,592 - INFO - Créé le : 2026-08-19T09:31:30Z
|
||||
2026-10-14 22:42:02,593 - INFO - Mis à jour : 2026-10-14T08:39:10Z
|
||||
2026-10-14 22:42:02,593 - INFO - Taille totale : 128415971 Octets
|
||||
2026-10-14 22:42:02,594 - INFO - Public : True
|
||||
2026-10-14 22:42:02,595 - INFO - Nbre de fichiers : 14
|
||||
2026-10-14 22:42:02,595 - INFO - Taille totale : 122.47 Mo
|
||||
2026-10-14 22:42:02,596 - INFO - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
2026-10-14 22:42:02,597 - INFO - 20260819_115533.jpeg 2.632 Mo
|
||||
2026-10-14 22:42:02,597 - INFO - ARR.gpkg 93.309 Mo
|
||||
2026-10-14 22:42:02,597 - INFO - ARR.qgs 0.713 Mo
|
||||
2026-10-14 22:42:02,598 - INFO - ARR_attachments.zip 0.002 Mo
|
||||
2026-10-14 22:42:02,598 - INFO - Inventaire Cavités.gpkg 0.660 Mo
|
||||
2026-10-14 22:42:02,599 - INFO - JPEG_20260819_113638_3152669861975410066.jpg 3.024 Mo
|
||||
2026-10-14 22:42:02,599 - INFO - JPEG_20260819_113919_5886287470656202827.jpg 3.034 Mo
|
||||
2026-10-14 22:42:02,600 - INFO - JPEG_20260819_121951_8365685850227103103.jpg 2.974 Mo
|
||||
2026-10-14 22:42:02,600 - INFO - JPEG_20260819_122929_1446792337025110147.jpg 3.007 Mo
|
||||
2026-10-14 22:42:02,601 - INFO - JPEG_20260819_123117_33265926990508961.jpg 2.516 Mo
|
||||
2026-10-14 22:42:02,601 - INFO - JPEG_20260819_124915_3186813976814177670.jpg 2.899 Mo
|
||||
2026-10-14 22:42:02,602 - INFO - JPEG_20260819_125124_7007318829424129864.jpg 3.165 Mo
|
||||
2026-10-14 22:42:02,602 - INFO - Tests/areas2dMasked.gpkg 4.531 Mo
|
||||
2026-10-14 22:42:02,602 - INFO - karstpro_etude.json 0.001 Mo
|
||||
2026-10-14 22:42:02,603 - INFO - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
@@ -30,27 +30,44 @@ def suivre_transfert(job, verifier, titre: str) -> None:
|
||||
if taille_totale <= 0:
|
||||
while verifier(job):
|
||||
time.sleep(0.2)
|
||||
logger.info(f"{Colors.ENDC}{titre}{Colors.INFO} : transfert terminé.")
|
||||
return
|
||||
|
||||
precedent = 0
|
||||
interactif = sys.stdout.isatty()
|
||||
|
||||
if interactif:
|
||||
with alive_bar(taille_totale, title=f"{Colors.YELLOW}{titre}{Colors.ENDC}", stats=True, dual_line=True, scale="SI", unit="o") as barre:
|
||||
while verifier(job):
|
||||
actuel = job.transferred_size
|
||||
delta = actuel - precedent
|
||||
|
||||
if delta > 0:
|
||||
barre(delta)
|
||||
precedent = actuel
|
||||
|
||||
time.sleep(0.2)
|
||||
|
||||
# Comptabilise les derniers octets transférés.
|
||||
delta = job.transferred_size - precedent
|
||||
if delta > 0:
|
||||
barre(delta)
|
||||
else:
|
||||
logger.info(f"{Colors.ENDC}{titre}{Colors.INFO} : transfert démarré ({Colors.ENDC}{taille_totale}{Colors.INFO} octets).")
|
||||
|
||||
with alive_bar(taille_totale, title=f"{Colors.YELLOW}{titre}{Colors.ENDC}", stats=True, dual_line=True, scale="SI", unit="o") as barre:
|
||||
while verifier(job):
|
||||
actuel = job.transferred_size
|
||||
delta = actuel - precedent
|
||||
|
||||
if delta > 0:
|
||||
barre(delta)
|
||||
precedent = actuel
|
||||
logger.debug(
|
||||
f"({Colors.ENDC}{titre}{Colors.DEBUG} : {Colors.ENDC}{actuel * 100 / taille_totale:.1f}{Colors.DEBUG} ({Colors.ENDC}{actuel}{Colors.DEBUG} / {Colors.ENDC}{taille_totale}{Colors.DEBUG} octets)"
|
||||
)
|
||||
|
||||
time.sleep(0.2)
|
||||
|
||||
# Comptabilise les derniers octets transférés.
|
||||
actuel = job.transferred_size
|
||||
delta = actuel - precedent
|
||||
|
||||
if delta > 0:
|
||||
barre(delta)
|
||||
logger.info(f"{Colors.ENDC}{titre}{Colors.INFO} : transfert terminé.")
|
||||
|
||||
|
||||
############################################################################################################################################
|
||||
@@ -145,7 +162,7 @@ def lister_fichiers_github(session: requests.Session, depot: str, branche: str,
|
||||
|
||||
|
||||
############################################################################################################################################
|
||||
def telecharger_depuis_github(depot: str, branche: str, chemin: str, dossier_cible: Path, token: str | None = None) -> Path:
|
||||
def telecharger_depuis_githubOld(depot: str, branche: str, chemin: str, dossier_cible: Path, token: str | None = None) -> Path:
|
||||
"""Télécharge uniquement un fichier ou un dossier d'un dépôt GitHub.
|
||||
|
||||
chemin : chemin dans le dépôt, ex. 'data/gpkg' ou 'data/couche.gpkg' ('' = tout le dépôt)
|
||||
@@ -185,6 +202,73 @@ def telecharger_depuis_github(depot: str, branche: str, chemin: str, dossier_cib
|
||||
return dossier_cible / Path(chemin).name if est_fichier else dossier_cible
|
||||
|
||||
|
||||
def telecharger_depuis_github(depot: str, branche: str, chemin: str, dossier_cible: Path, token: str | None = None) -> Path:
|
||||
"""Télécharge uniquement un fichier ou un dossier d'un dépôt GitHub.
|
||||
|
||||
chemin : chemin dans le dépôt, ex. 'data/gpkg' ou 'data/couche.gpkg' ('' = tout le dépôt)
|
||||
Retourne le fichier ou le dossier local téléchargé.
|
||||
"""
|
||||
|
||||
chemin = chemin.strip("/")
|
||||
|
||||
if dossier_cible.exists():
|
||||
shutil.rmtree(dossier_cible)
|
||||
dossier_cible.mkdir(parents=True)
|
||||
|
||||
with requests.Session() as session:
|
||||
fichiers = lister_fichiers_github(session, depot, branche, chemin, token)
|
||||
if not fichiers:
|
||||
raise ValueError(f"Aucun fichier trouvé dans : {chemin or '/'}")
|
||||
|
||||
# Un fichier demandé : destination à plat ; sinon, conserver l'arborescence.
|
||||
est_fichier = len(fichiers) == 1 and fichiers[0]["path"] == chemin
|
||||
base = chemin.rpartition("/")[0] if est_fichier else chemin
|
||||
total = sum(f.get("size", 0) for f in fichiers) or None
|
||||
interactif = sys.stdout.isatty()
|
||||
precedent = 0
|
||||
|
||||
def telecharger_fichiers(barre=None) -> None:
|
||||
nonlocal precedent
|
||||
|
||||
for fichier in fichiers:
|
||||
relatif = fichier["path"][len(base) :].lstrip("/") if base else fichier["path"]
|
||||
local = dossier_cible / relatif
|
||||
local.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
url = f"{GITHUB_API}/repos/{depot}/contents/{quote(fichier['path'])}"
|
||||
with session.get(url, params={"ref": branche}, headers=_entetes_github(token, brut=True), stream=True, timeout=120) as reponse:
|
||||
reponse.raise_for_status()
|
||||
|
||||
with open(local, "wb") as sortie:
|
||||
for morceau in reponse.iter_content(chunk_size=1024 * 256):
|
||||
if not morceau:
|
||||
continue
|
||||
|
||||
sortie.write(morceau)
|
||||
precedent += len(morceau)
|
||||
|
||||
if barre:
|
||||
barre(len(morceau))
|
||||
else:
|
||||
logger.debug(
|
||||
"GitHub : %s — %.1f %% (%s / %s octets)", fichier["path"], precedent * 100 / total if total else 0, precedent, total or "?"
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"Téléchargement GitHub : {Colors.ENDC}{depot}{Colors.INFO}/{Colors.ENDC}{branche}{Colors.INFO}, chemin {Colors.ENDC}{chemin or '/'}{Colors.INFO}"
|
||||
)
|
||||
|
||||
if interactif and total:
|
||||
with alive_bar(total, title=f"{Colors.YELLOW}Téléchargement GitHub{Colors.ENDC}", stats=True, scale="SI", unit="o") as barre:
|
||||
telecharger_fichiers(barre)
|
||||
else:
|
||||
telecharger_fichiers()
|
||||
|
||||
logger.info(f"Téléchargement GitHub terminé : {Colors.ENDC}{len(fichiers)}{Colors.INFO} fichier(s), {Colors.ENDC}{precedent}{Colors.INFO} octets.")
|
||||
|
||||
return dossier_cible / Path(chemin).name if est_fichier else dossier_cible
|
||||
|
||||
|
||||
############################################################################################################################################
|
||||
def envoyer_mergin(
|
||||
projet: str,
|
||||
|
||||
Reference in new issue
Block a user