def transfer_session(src: Path, dst: Path, force: bool = False): print(src, dst) # log.info(f"Attempting to copy from {src} to {dst}...") src = Path(folders.session_path(src)) dst_sess = Path(folders.session_path(dst)) if src is None: return if dst_sess is None: dst = dst / Path(*src.parts[-3:]) src_flag_file = src / "transfer_me.flag" if not src_flag_file.exists(): return flag = flags.read_flag_file(src_flag_file) if isinstance(flag, list): raise (NotImplementedError) else: if force: shutil.rmtree(dst, ignore_errors=True) log.info(f"Copying all files from {src} to {dst} ...") shutil.copytree(src, dst, ignore=ig(str(src_flag_file.name))) # If folder was created delete the src_flag_file if (dst / 'raw_video_data').exists(): log.info( f"{Path(*src.parts[-3:]) / 'raw_video_data'} copied to {dst.parent.parent.parent}" ) src_flag_file.unlink()
def main(local_folder: str, remote_folder: str, force: bool = False) -> None: local_folder = Path(local_folder) remote_folder = Path(remote_folder) src_session_paths = [ x.parent for x in local_folder.rglob("transfer_me.flag") ] if not src_session_paths: log.info("Nothing to transfer, exiting...") return # Create all dst paths dst_session_paths = [] for s in src_session_paths: mouse = s.parts[-3] date = s.parts[-2] sess = s.parts[-1] d = remote_folder / mouse / date / sess dst_session_paths.append(d) for src, dst in zip(src_session_paths, dst_session_paths): src_flag_file = src / "transfer_me.flag" flag = flags.read_flag_file(src_flag_file) if isinstance(flag, list): raise NotImplementedError else: if force: shutil.rmtree(dst, ignore_errors=True) log.info(f"Copying {src}...") shutil.copytree(src, dst, ignore=ig(str(src_flag_file.name))) # finally if folder was created delete the src flag_file and create compress_me.flag if dst.exists(): task_type = ibllib.io.extractors.base.get_session_extractor_type( Path(src)) if task_type not in ['ephys', 'ephys_sync', 'ephys_mock']: flags.write_flag_file(dst.joinpath('raw_session.flag')) settings = raw.load_settings(dst) if 'ephys' in settings[ 'PYBPOD_BOARD']: # Any traing task on an ephys rig dst.joinpath('raw_session.flag').unlink() log.info( f"Copied to {remote_folder}: Session {src_flag_file.parent}") src_flag_file.unlink() # Cleanup src_video_file = src / 'raw_video_data' / '_iblrig_leftCamera.raw.avi' dst_video_file = dst / 'raw_video_data' / '_iblrig_leftCamera.raw.avi' src_audio_file = src / 'raw_behavior_data' / '_iblrig_micData.raw.wav' dst_audio_file = dst / 'raw_behavior_data' / '_iblrig_micData.raw.wav' if src_audio_file.exists() and \ src_audio_file.stat().st_size == dst_audio_file.stat().st_size: src_audio_file.unlink() if src_video_file.exists() and \ src_video_file.stat().st_size == dst_video_file.stat().st_size: src_video_file.unlink()
def main(local_folder: str, remote_folder: str, force: bool = True) -> None: local_folder = Path(local_folder) remote_folder = Path(remote_folder) src_session_paths = [ x.parent for x in local_folder.rglob("transfer_me.flag") ] if not src_session_paths: log.info("Nothing to transfer, exiting...") return # Create all dst paths dst_session_paths = [] for s in src_session_paths: mouse = s.parts[-3] date = s.parts[-2] sess = s.parts[-1] d = remote_folder / mouse / date / sess dst_session_paths.append(d) for src, dst in zip(src_session_paths, dst_session_paths): src_flag_file = src / "transfer_me.flag" flag = flags.read_flag_file(src_flag_file) if isinstance(flag, list): raise NotImplementedError else: if force: shutil.rmtree(dst, ignore_errors=True) log.info(f"Copying {src}...") shutil.copytree(src, dst, ignore=ig(str(src_flag_file.name))) # finally if folder was created delete the src flag_file and create compress_me.flag if dst.exists(): dst_flag_file = dst / 'extract_me.flag' flags.write_flag_file(dst_flag_file) flags.create_compress_flags(dst) log.info( f"Copied to {remote_folder}: Session {src_flag_file.parent}") src_flag_file.unlink() # Cleanup src_audio_file = src / 'raw_behavior_data' / '_iblrig_micData.raw.wav' src_video_file = src / 'raw_video_data' / '_iblrig_leftCamera.raw.avi' dst_audio_file = dst / 'raw_behavior_data' / '_iblrig_micData.raw.wav' dst_video_file = dst / 'raw_video_data' / '_iblrig_leftCamera.raw.avi' if src_audio_file.exists() and \ src_audio_file.stat().st_size == dst_audio_file.stat().st_size: src_audio_file.unlink() if src_video_file.exists() and \ src_video_file.stat().st_size == dst_video_file.stat().st_size: src_video_file.unlink()