Windows compatibility

This commit is contained in:
2026-08-20 12:01:31 +02:00
parent 7c366a9ca4
commit ac4ab782b2
20 changed files with 634 additions and 134 deletions
+19 -49
View File
@@ -1,52 +1,36 @@
import argparse
import sys
import os
from pathlib import Path
from config import EXPORT_DIR
from platform_utils import replace_with_link_or_copy
def process_directory(dir_arg):
# Résolution des chemins
base_dir = Path(dir_arg)
bgnot_dir = base_dir / "BGnot"
sync_dir = EXPORT_DIR / dir_arg
# Création du dossier de destination s'il n'existe pas
def export_directory(base_dir, source_dir_name):
base_dir = Path(base_dir).expanduser().resolve()
source_dir = base_dir / source_dir_name
sync_dir = Path(EXPORT_DIR).expanduser() / base_dir.name
sync_dir.mkdir(parents=True, exist_ok=True)
if not bgnot_dir.is_dir():
print(f"Erreur : le sous-dossier {bgnot_dir} n'existe pas.")
if not source_dir.is_dir():
print(f"Erreur : le sous-dossier {source_dir} n'existe pas.")
return
# Récupération de tous les sous-dossiers
subdirs = [d for d in bgnot_dir.iterdir() if d.is_dir()]
if not subdirs:
return
subdirs = [directory for directory in source_dir.iterdir() if directory.is_dir()]
if source_dir_name == "BGnot" and subdirs:
all_start_with_copie = all(directory.name.startswith("Copie") for directory in subdirs)
if not all_start_with_copie:
subdirs = [directory for directory in subdirs if not directory.name.startswith("Copie")]
# Application des règles de sélection
all_start_with_copie = all(d.name.startswith("Copie") for d in subdirs)
if all_start_with_copie:
chosen_dirs = subdirs
else:
chosen_dirs = [d for d in subdirs if not d.name.startswith("Copie")]
# Traitement des dossiers sélectionnés
for subdir in chosen_dirs:
for subdir in subdirs:
concat_file = subdir / "Concat.pdf"
if not concat_file.is_file():
print(f"Attention : le fichier {concat_file} est introuvable.")
continue
destination = sync_dir / f"{subdir.name}.pdf"
method = replace_with_link_or_copy(concat_file, destination, prefer="hardlink")
print(f"Exported: {destination} ({method})")
symlink_path = sync_dir / f"{subdir.name}.pdf"
# Supprime le lien précédent s'il existe pour éviter une erreur
if symlink_path.is_symlink() or symlink_path.exists():
symlink_path.unlink()
# Création du lien symbolique (pointe vers le chemin absolu pour éviter les problèmes)
os.link(concat_file.absolute(), symlink_path)
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Move to tablette folder.")
@@ -54,21 +38,7 @@ if __name__ == "__main__":
parser.add_argument("--refaire", action="store_true", help="Process only copies/labels defined in refaire.json")
args = parser.parse_args()
root_dir = args.dir
if args.refaire:
base_dir = Path(root_dir)
brnot_dir = base_dir / "BRnot"
sync_dir = EXPORT_DIR / root_dir
sync_dir.mkdir(parents=True, exist_ok=True)
for f in brnot_dir.iterdir():
concat_file = f / "Concat.pdf"
if f.is_dir() and concat_file.is_file():
symlink_path = sync_dir / f"{f.name}.pdf"
if symlink_path.exists():
symlink_path.unlink()
os.link(concat_file.absolute(), symlink_path)
export_directory(args.dir, "BRnot")
sys.exit(0)
else:
process_directory(root_dir)
export_directory(args.dir, "BGnot")