Commit 992ce1ba authored by Anton Pershin's avatar Anton Pershin

Добавил поддержку множественных исследовательских каталогов в Research. Также сделал рефакторинг

parent c5ffd6e9
......@@ -80,21 +80,21 @@ class Research:
"""
def __init__(self, name,
continuing=False,
local_research_path=None,
local_research_paths=None,
remote_comm=None,
remote_research_path=None,
):
# Always create local communication here
# Remote communication is optional then
self.local_research_path = local_research_path
self.local_main_path = os.path.dirname(local_research_path)
self.local_research_path = local_research_paths[0]
self.local_main_path = os.path.dirname(self.local_research_path)
self.remote_research_path = remote_research_path
self._tasks_number = 0
self._local_comm = LocalCommunication(Host())
self._remote_comm = remote_comm
# NOTE: at the moment we do not need features of the distributed storage
#self._distr_storage = DistributedStorage((rset.LOCAL_HOST['main_research_path'], rset.LOCAL_HOST['storage_research_path']), prior_storage_index=1)
self._distr_storage = DistributedStorage((self.local_research_path,), prior_storage_index=0)
self._distr_storage = DistributedStorage(local_research_paths, prior_storage_index=0)
suitable_name = self._make_suitable_name(name)
if not continuing:
# interpret name as name without date
......@@ -132,9 +132,9 @@ class Research:
conf = json.load(f)
res = Research(conf['RESEARCH'][research_sid],
continuing=True,
local_research_path=conf['LOCAL_HOST']['research_path'],
local_research_paths=conf['LOCAL_HOST']['research_paths'],
remote_comm=remote_comm,
remote_research_path=conf['REMOTE_HOSTS'][remote_comm.machine_name]['research_path'])
remote_research_path=conf['REMOTE_HOSTS'][remote_comm.machine_name]['research_path'] if remote_comm is not None else None)
res._add_properties(conf['RESEARCH_PROPS'])
return res
......@@ -203,25 +203,26 @@ class Research:
dir located in the main research location.
'''
task_results_local_path = self.get_task_path(task_number)
task_results_remote_path = self.get_task_path(task_number, self._exec_comm.host)
task_results_remote_path = self.get_task_path(task_number, self._remote_comm.host)
if len(copies_list) == 0: # copy all data
pathes = self._exec_comm.listdir(task_results_remote_path)
pathes = self._remote_comm.listdir(task_results_remote_path)
for file_or_dir in pathes:
self._exec_comm.copy('/'.join((task_results_remote_path, file_or_dir)), task_results_local_path, 'from_remote')
self._remote_comm.copy('/'.join((task_results_remote_path, file_or_dir)), task_results_local_path, 'from_remote', show_msg=True)
else:
for copy_target in copies_list:
remote_copy_target_path = '/'.join((task_results_remote_path, copy_target['path'])) # we consider copy targets as relative to task's dir
self._exec_comm.copy(remote_copy_target_path, task_results_local_path, 'from_remote')
self._remote_comm.copy(remote_copy_target_path, task_results_local_path, 'from_remote', show_msg=True)
if 'new_name' in copy_target:
os.rename(os.path.join(task_results_local_path, os.path.basename(copy_target['path'])), \
os.path.join(task_results_local_path, copy_target['new_name']))
def _make_task_path(self, task_number, task_name, execution_host=None):
task_path = ''
rel_task_dir = os.path.join(self._research_id, self._get_task_full_name(task_number, task_name))
task_dir = self._get_task_full_name(task_number, task_name)
if execution_host is None:
task_path = os.path.join(self.local_research_path, rel_task_dir)
task_path = os.path.join(self.research_path, task_dir)
else:
rel_task_dir = os.path.join(self._research_id, task_dir)
task_path = os.path.join(execution_host.research_abs_path, rel_task_dir)
return task_path
......@@ -289,7 +290,7 @@ class ResearchDoesNotExist(Exception):
pass
def get_all_research_ids():
return os.listdir('.' + self.local_research_path)
return os.listdir('.' + self.research_path)
def retrieve_trailing_float_from_task_dir(task_dir):
matching = re.search('^(?P<task_number>\d+)-(?P<task_name>\S+)_(?P<float_left>\d+)\.(?P<float_right>\d+)', task_dir)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment