Skip to content

Commit

Permalink
syntactic sugar for copy states
Browse files Browse the repository at this point in the history
  • Loading branch information
oliche committed Jul 19, 2023
1 parent 931fcdf commit 54fd43f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
30 changes: 15 additions & 15 deletions iblrig/test/test_transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def test_behavior_copy(self):
session.paths.SESSION_FOLDER.joinpath('raw_video_data', 'tutu.avi').touch()
sc = SessionCopier(session_path=session.paths.SESSION_FOLDER,
remote_subjects_folder=session.paths.REMOTE_SUBJECT_FOLDER)
assert sc.get_copy_state()[0] == 1
assert sc.state == 1
sc.copy_collections()
assert sc.get_copy_state()[0] == 2
assert sc.state == 2
sc.finalize_copy(number_of_expected_devices=1)
assert sc.get_copy_state()[0] == 3 # this time it's all there and we move on
assert sc.state == 3 # this time it's all there and we move on

def test_behavior_ephys_video_copy(self):
with tempfile.TemporaryDirectory() as td:
Expand Down Expand Up @@ -71,29 +71,29 @@ def test_behavior_ephys_video_copy(self):
sc = SessionCopier(session_path=session.paths.SESSION_FOLDER,
remote_subjects_folder=session.paths.REMOTE_SUBJECT_FOLDER)
assert sc.glob_file_remote_copy_status().suffix == '.status_pending'
assert sc.get_copy_state()[0] == 1
assert sc.state == 1
sc.copy_collections()
assert sc.get_copy_state()[0] == 2
assert sc.state == 2
assert sc.glob_file_remote_copy_status().suffix == '.status_complete'
sc.copy_collections()
assert sc.get_copy_state()[0] == 2
assert sc.state == 2
sc.finalize_copy(number_of_expected_devices=3)
assert sc.get_copy_state()[0] == 2 # here we still don't have all devides so this won't cut it and we stay in state 2
assert sc.state == 2 # here we still don't have all devides so this won't cut it and we stay in state 2

vc = VideoCopier(session_path=folder_session_video, remote_subjects_folder=session.paths.REMOTE_SUBJECT_FOLDER)
assert vc.get_copy_state()[0] == 0
assert vc.state == 0
vc.initialize_experiment()
assert vc.get_copy_state()[0] == 1
assert vc.state == 1
vc.copy_collections()
assert vc.get_copy_state()[0] == 2
assert vc.state == 2
sc.finalize_copy(number_of_expected_devices=3)
assert sc.get_copy_state()[0] == 2 # here we still don't have all devides so this won't cut it and we stay in state 2
assert sc.state == 2 # here we still don't have all devides so this won't cut it and we stay in state 2

ec = EphysCopier(session_path=folder_session_ephys, remote_subjects_folder=session.paths.REMOTE_SUBJECT_FOLDER)
assert ec.get_copy_state()[0] == 0
assert ec.state == 0
ec.initialize_experiment()
assert ec.get_copy_state()[0] == 1
assert ec.state == 1
ec.copy_collections()
assert ec.get_copy_state()[0] == 2
assert ec.state == 2
sc.finalize_copy(number_of_expected_devices=3)
assert sc.get_copy_state()[0] == 3 # this time it's all there and we move on
assert sc.state == 3 # this time it's all there and we move on
9 changes: 6 additions & 3 deletions iblrig/transfer_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def __init__(self, session_path, remote_subjects_folder=None):
def __repr__(self):
return f"{super(SessionCopier, self).__repr__()} \n local: {self.session_path} \n remote: {self.remote_session_path}"

def get_copy_state(self):
@property
def state(self):
return self.get_state()[0]

def get_state(self):
if self.remote_subjects_folder is None or not self.remote_subjects_folder.exists():
return None, f'Remote subjects folder {self.remote_subjects_folder} set to Null or unreachable'
if not self.file_remote_experiment_description.exists():
Expand Down Expand Up @@ -118,8 +122,7 @@ def initialize_experiment(self, acquisition_description=None, overwrite=False):
overwrite : bool
If true, overwrite any existing file with the new one, otherwise, update the existing file.
"""
if not acquisition_description:
return
assert acquisition_description

# First attempt to add the remote description stub to the _device folder on the remote session
if not self.remote_subjects_folder:
Expand Down

0 comments on commit 54fd43f

Please sign in to comment.