[docs]defmake_symlink_tree(files:dict[str,Path],symdir:Path,obs_name):forfl,fl_absinfiles.items():sym_path=symdir/obs_name/fl# Here we make all the directories, that all have to be symlinks, otherwise# objects whose path is to a directory don't equate.ifnotsym_path.parent.exists():sym_path.parent.mkdir(parents=True)sym_path.symlink_to(fl_abs)
[docs]defget_active_files(path:str|Path)->list[Path]:path=Path(path)ifnotpath.is_dir():raiseValueError(f"{path} is not a directory!")fls=path.glob("*")ok_extra_files=["Notes.txt","calibration_analysis.ipynb","derived","definition.yaml",]return[flforflinflsiffl.suffixnotinIGNORABLE_SUFFIXESandfl.namenotinok_extra_filesandfl.namenotinIGNORABLE_FOLDERS]
def_ask_to_rm(fl:Path)->Path|None:reply="z"whilereplynotin"yniopm":reply=(str(console.input(f"""[bold] Action for '{fl}':>>> [red]y[/]: remove the file>>> [dark_orange]n[/]: ignore/skip the file for now>>> [cyan]i[/]: make it 'invalid'>>> [cyan]o[/]: [bold]make it 'old'>>> [cyan]p[/]: [bold]make it 'output'>>> [green]m[/]: [bold]interactively move/rename""")).lower().strip())ifreply=="y":iffl.is_dir():shutil.rmtree(fl)else:fl.unlink()returnNoneelifreply=="i":shutil.move(fl,str(fl)+".invalid")returnPath(str(fl)+".invalid")elifreply=="o":shutil.move(fl,str(fl)+".old")returnPath(str(fl)+".old")elifreply=="p":shutil.move(fl,str(fl)+".output")returnPath(str(fl)+".output")elifreply=="m":reply=str(console.input(f"[bold]Change '{fl.name}' to:[/] "))newfile=fl.parent/replytry:shutil.move(fl,newfile)exceptException:console.print(f"[bold red]Couldn't rename the file '{newfile}' as you asked.")raisereturnnewfileelifreply=="n":returnflelse:raiseOSError("Something went very wrong.")classFileStructureError(Exception):passclassLoadExistError(Exception):passclassIncompleteObservationError(FileStructureError):passclassInconsistentObservationError(FileStructureError):pass