Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move main.py to cli.py #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion ddlitlab2024/dataset/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
#!/usr/bin/env python

import argparse
import typing
from enum import Enum
from pathlib import Path

from ddlitlab2024 import DB_PATH
if typing.TYPE_CHECKING:
from argparse import Namespace

import os
import sys

from rich.console import Console
from sqlalchemy.orm import Session

from ddlitlab2024 import DB_PATH, __version__
from ddlitlab2024.dataset import logger
from ddlitlab2024.dataset.db import Database

err_console = Console(stderr=True)


class ImportType(str, Enum):
Expand Down Expand Up @@ -47,3 +63,42 @@ def __init__(self):

def parse_args(self) -> argparse.Namespace:
return self.parser.parse_args()


def main():
debug_mode = os.getenv("LOGLEVEL") == "DEBUG"

try:
logger.debug("Parsing CLI args...")
args: Namespace = CLIArgs().parse_args()
logger.debug(f"CLI args: {args}")

if args.version:
logger.info(f"running ddlitlab2024 CLI v{__version__}")
sys.exit(0)

if args.command == CLICommand.DB:
create_schema = args.db_command == "create-schema" or args.db_command == "dummy-data"
db: Session = Database(args.db_path).create_session(create_schema=create_schema)
logger.debug("Database session created")

match args.db_command:
case "recording2mcap":
from ddlitlab2024.dataset.recording2mcap import recording2mcap

recording2mcap(db, args.recording, args.output_dir)

case "dummy-data":
from ddlitlab2024.dataset.dummy_data import insert_dummy_data

insert_dummy_data(db, args.num_recordings, args.num_samples_per_rec, args.image_step)

sys.exit(0)
except Exception as e:
logger.error(e)
err_console.print_exception(show_locals=debug_mode)
sys.exit(1)


if __name__ == "__main__":
main()
58 changes: 0 additions & 58 deletions ddlitlab2024/dataset/main.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ line-length = 120
select = ["F", "E", "B", "W", "I", "N", "UP"]

[tool.poetry.scripts]
cli = "ddlitlab2024.dataset.main:main"
cli = "ddlitlab2024.dataset.cli:main"
Loading