Skip to content

Commit

Permalink
Merge pull request #475 from LAAC-LSCP/cmdline/init
Browse files Browse the repository at this point in the history
add init command
  • Loading branch information
LoannPeurey authored Jun 25, 2024
2 parents 4ffb6d6 + 46e5348 commit a170015
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 34 additions & 1 deletion ChildProject/cmdline.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,6 +17,8 @@

import argparse
import os
from pathlib import Path
import glob
import pandas as pd
import sys
import random
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit a170015

Please sign in to comment.