diff --git a/CHANGELOG.md b/CHANGELOG.md index fdd65ffb..e4dc8160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added + +- added the init command: initiate a new dataset + ## [0.2.0] 2024-06-03 ### Changed diff --git a/ChildProject/cmdline.py b/ChildProject/cmdline.py index 773a0c84..dbabf545 100755 --- a/ChildProject/cmdline.py +++ b/ChildProject/cmdline.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -from .projects import ChildProject +from .projects import ChildProject, RAW_RECORDINGS, METADATA_FOLDER, RECORDINGS_CSV, CHILDREN_CSV from .annotations import AnnotationManager from .pipelines.samplers import SamplerPipeline from .pipelines.eafbuilder import EafBuilderPipeline @@ -17,6 +17,8 @@ import argparse import os +from pathlib import Path +import glob import pandas as pd import sys import random @@ -97,6 +99,37 @@ def perform_validation(project: ChildProject, require_success: bool = True, **ar ) +@subcommand( + [ + arg("source", help="project path"), + arg( + "--force","-f", + help="ignore existing files and create strcture anyway", + action="store_true", + ), + ] +) +def init(args): + path = Path(args.source) + + files = glob.glob(str(path / '*')) + if len(files) != 0 : + raise ValueError("Directory {} not empty, cannot create a project".format(path)) + + os.makedirs(path / RAW_RECORDINGS, exist_ok=args.force) + os.makedirs(path / METADATA_FOLDER, exist_ok=args.force) + os.makedirs(path / 'extra', exist_ok=args.force) + os.makedirs(path / 'scripts', exist_ok=args.force) + os.makedirs(path / 'annotations', exist_ok=args.force) + open(path / 'README.md', 'a').close() + pd.DataFrame(columns = [col.name for col in ChildProject.RECORDINGS_COLUMNS if col.required]).to_csv( + path / METADATA_FOLDER / RECORDINGS_CSV, index=False + ) + pd.DataFrame(columns=[col.name for col in ChildProject.CHILDREN_COLUMNS if col.required]).to_csv( + path / METADATA_FOLDER / CHILDREN_CSV, index=False + ) + + @subcommand( [ arg("source", help="project path"),