Commit 55ad2207 authored by Anton Pershin's avatar Anton Pershin

Added personal task shift to enable multiuser task upload

parent 5e99fc3e
...@@ -52,7 +52,8 @@ class Research: ...@@ -52,7 +52,8 @@ class Research:
continuing=False, continuing=False,
local_research_roots: Optional[Sequence[str]] = None, local_research_roots: Optional[Sequence[str]] = None,
remote_comm: Optional[BaseCommunication] = None, remote_comm: Optional[BaseCommunication] = None,
remote_research_root: Optional[str] = None): remote_research_root: Optional[str] = None,
personal_task_shift=0):
""" """
:param name: research description (if continuing == False) or research directory (if continuing == True) :param name: research description (if continuing == False) or research directory (if continuing == True)
:param continuing: if False, the Research with be read from the root path. Otherwise, a new one will be created :param continuing: if False, the Research with be read from the root path. Otherwise, a new one will be created
...@@ -63,7 +64,8 @@ class Research: ...@@ -63,7 +64,8 @@ class Research:
self._local_research_root = local_research_roots[0] self._local_research_root = local_research_roots[0]
self._local_root = os.path.dirname(self._local_research_root) self._local_root = os.path.dirname(self._local_research_root)
self._remote_research_root = remote_research_root self._remote_research_root = remote_research_root
self._tasks_number = 0 self._personal_task_shift = personal_task_shift
self._tasks_number = personal_task_shift
self._local_comm = LocalCommunication(Host()) # local communication created automatically, no need to pass it self._local_comm = LocalCommunication(Host()) # local communication created automatically, no need to pass it
self._remote_comm = remote_comm self._remote_comm = remote_comm
self._distr_storage = DistributedStorage(local_research_roots, prior_storage_index=0) self._distr_storage = DistributedStorage(local_research_roots, prior_storage_index=0)
...@@ -96,7 +98,8 @@ class Research: ...@@ -96,7 +98,8 @@ class Research:
local_research_roots=conf['LOCAL_HOST']['research_roots'], local_research_roots=conf['LOCAL_HOST']['research_roots'],
remote_comm=remote_comm, remote_comm=remote_comm,
remote_research_root=conf['REMOTE_HOSTS'][remote_comm.machine_name]['research_root'] remote_research_root=conf['REMOTE_HOSTS'][remote_comm.machine_name]['research_root']
if remote_comm is not None else None) if remote_comm is not None else None,
personal_task_shift=conf['PERSONAL_TASK_SHIFT'])
res._add_properties(conf['RESEARCH_PROPS']) res._add_properties(conf['RESEARCH_PROPS'])
return res return res
...@@ -120,7 +123,8 @@ class Research: ...@@ -120,7 +123,8 @@ class Research:
local_research_roots=conf['LOCAL_HOST']['research_roots'], local_research_roots=conf['LOCAL_HOST']['research_roots'],
remote_comm=remote_comm, remote_comm=remote_comm,
remote_research_root=conf['REMOTE_HOSTS'][remote_comm.machine_name]['research_root'] remote_research_root=conf['REMOTE_HOSTS'][remote_comm.machine_name]['research_root']
if remote_comm is not None else None) if remote_comm is not None else None,
personal_task_shift=conf['PERSONAL_TASK_SHIFT'])
res._add_properties(conf['RESEARCH_PROPS']) res._add_properties(conf['RESEARCH_PROPS'])
return res return res
...@@ -145,11 +149,13 @@ class Research: ...@@ -145,11 +149,13 @@ class Research:
'research_dir': self._research_dir, 'research_dir': self._research_dir,
'local_research_path': self._local_research_root, 'local_research_path': self._local_research_root,
'remote_research_path': self._remote_research_root, 'remote_research_path': self._remote_research_root,
'personal_task_shift': self._personal_task_shift,
'remote_comm': self._remote_comm.__getstate__(), 'remote_comm': self._remote_comm.__getstate__(),
} }
def __setstate__(self, state): def __setstate__(self, state):
self._tasks_number = 0 self._personal_task_shift = state['personal_task_shift']
self._tasks_number = self._personal_task_shift
self._local_comm = LocalCommunication(Host()) self._local_comm = LocalCommunication(Host())
self._local_research_root = state['local_research_path'] self._local_research_root = state['local_research_path']
self._remote_research_root = state['remote_research_path'] self._remote_research_root = state['remote_research_path']
...@@ -171,27 +177,18 @@ class Research: ...@@ -171,27 +177,18 @@ class Research:
research_path = self._distr_storage.get_dir_path(self._research_dir) research_path = self._distr_storage.get_dir_path(self._research_dir)
if research_path is None: if research_path is None:
raise ResearchDoesNotExist("Research '{}' does not exist".format(self._research_dir)) raise ResearchDoesNotExist("Research '{}' does not exist".format(self._research_dir))
# if research_path is None:
# # assume date was omitted in research id
# regexp_for_search = '^(?P<year>\d+)-(?P<month>\d+)-(?P<day>\d+)_{}'.format(self._research_name)
# research_path, dir_params = self._distr_storage.find_dir_by_named_regexp('', regexp_for_search)
# if dir_params is None:
# raise ResearchDoesNotExist("Research '{}' does not exist".format(self._research_name))
# self._research_name = '{}-{}-{}_{}'.format(dir_params['year'], dir_params['month'], dir_params['day'],
# self._research_name)
print('Loaded research at {}'.format(research_path)) print('Loaded research at {}'.format(research_path))
# determine maximum task number to set the number for the next possible task # determine maximum task number to set the number for the next possible task
dirnames, _ = self._distr_storage.listdir(self._research_dir) dirnames, _ = self._distr_storage.listdir(self._research_dir)
self._tasks_number = 0
for dir_ in dirnames: for dir_ in dirnames:
if dir_ != 'report': if dir_ != 'report':
task_number, _ = split_task_dir(dir_) task_number, _ = split_task_dir(dir_)
if task_number > self._tasks_number: if task_number > self._tasks_number:
self._tasks_number = task_number self._tasks_number = task_number
self._tasks_number += 1 self._tasks_number += 1
print('Number of tasks in the current research: {}'.format(self._tasks_number)) print('Next created task in the current research will hold the following number: {}'.format(self._tasks_number))
return research_path return research_path
def create_task(self, name: str) -> int: def create_task(self, name: str) -> int:
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
"RESEARCH_PROPS": { "RESEARCH_PROPS": {
... ...
}, },
"PERSONAL_TASK_SHIFT": 0,
"TEMPLATES_PATH": "...", "TEMPLATES_PATH": "...",
"MEETINGS_PATH": "..." "MEETINGS_PATH": "..."
} }
\ No newline at end of file
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