|
@@ -21,26 +21,27 @@
|
|
|
|
|
|
import logging
|
|
|
import os
|
|
|
+import shutil
|
|
|
|
|
|
from consts import ANNOTATION_TYPES
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
-def create_child_project_directories(data_path):
|
|
|
+def create_child_project_directories(project_path, message_definition):
|
|
|
"""
|
|
|
Creates all the directories required by ChildProject
|
|
|
- :param data_path: path where the directories should be created
|
|
|
- :type data_path: str
|
|
|
+ :param project_path: path where the directories should be created
|
|
|
+ :type project_path: str
|
|
|
:return: None
|
|
|
:rtype: None
|
|
|
"""
|
|
|
- child_project_dirs = [os.path.join(data_path, 'extra'),
|
|
|
- os.path.join(data_path, 'metadata'),
|
|
|
- os.path.join(data_path, 'annotations'),
|
|
|
- os.path.join(data_path, 'recordings', 'raw')]
|
|
|
+ child_project_dirs = [os.path.join(project_path, 'extra', 'messages', 'definition'),
|
|
|
+ os.path.join(project_path, 'metadata'),
|
|
|
+ os.path.join(project_path, 'annotations'),
|
|
|
+ os.path.join(project_path, 'recordings', 'raw')]
|
|
|
|
|
|
- annotations_dir = [os.path.join(data_path, 'annotations', ann_type.value[0], 'raw')
|
|
|
+ annotations_dir = [os.path.join(project_path, 'annotations', ann_type.value[0], 'raw')
|
|
|
for ann_type in ANNOTATION_TYPES]
|
|
|
|
|
|
all_dirs = child_project_dirs + annotations_dir
|
|
@@ -53,9 +54,22 @@ def create_child_project_directories(data_path):
|
|
|
else:
|
|
|
logging.info('{} already exists.'.format(p))
|
|
|
|
|
|
+ if message_definition:
|
|
|
+ source_file = message_definition
|
|
|
+ target_file = os.path.join(project_path, 'extra', 'messages', 'definition', 'metrics_messages.yaml')
|
|
|
|
|
|
-def main(project_path):
|
|
|
- create_child_project_directories(project_path)
|
|
|
+ assert os.path.exists(source_file), \
|
|
|
+ ValueError('Message definition file ({}) not found!'.format(source_file))
|
|
|
+ assert source_file.endswith('yaml'), \
|
|
|
+ ValueError('Message definition file ({}) should end with `.yaml`'.format(source_file))
|
|
|
+ assert not os.path.exists(target_file), \
|
|
|
+ ValueError('A message definition file already exists! Delete it first!')
|
|
|
+
|
|
|
+ shutil.copyfile(source_file, target_file)
|
|
|
+
|
|
|
+
|
|
|
+def main(**kwargs):
|
|
|
+ create_child_project_directories(**kwargs)
|
|
|
|
|
|
|
|
|
def _parse_args(argv):
|
|
@@ -64,6 +78,8 @@ def _parse_args(argv):
|
|
|
parser = argparse.ArgumentParser(description='Create a ChildProject data set.')
|
|
|
parser.add_argument('--project-path', required=False, type=str, default='',
|
|
|
help="Path to a ChildProject/datalad project (useful for debugging purposes).")
|
|
|
+ parser.add_argument('--message-definition', required=False, type=str, default='',
|
|
|
+ help="Path to the file containing message definitions.")
|
|
|
args = parser.parse_args(argv)
|
|
|
|
|
|
return vars(args)
|