45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
import argparse
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from config import EXPORT_DIR
|
|
from platform_utils import replace_with_link_or_copy
|
|
|
|
|
|
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 source_dir.is_dir():
|
|
print(f"Erreur : le sous-dossier {source_dir} n'existe pas.")
|
|
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")]
|
|
|
|
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})")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="Move to tablette folder.")
|
|
parser.add_argument("dir", help="The directory to process")
|
|
parser.add_argument("--refaire", action="store_true", help="Process only copies/labels defined in refaire.json")
|
|
|
|
args = parser.parse_args()
|
|
if args.refaire:
|
|
export_directory(args.dir, "BRnot")
|
|
sys.exit(0)
|
|
export_directory(args.dir, "BGnot")
|