[BROKEN] Add CLI option for option
This is still slightly broken, as new processes are not able to access the configuration.
This commit is contained in:
parent
4f7a9d2e70
commit
381dcaa0bc
@ -1,18 +1,32 @@
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Annotated
|
||||||
|
|
||||||
|
import typer
|
||||||
|
|
||||||
from .. import collection
|
from .. import collection
|
||||||
|
from .. import config as config_mod
|
||||||
from ..collection import file, ingest
|
from ..collection import file, ingest
|
||||||
|
|
||||||
csi_producer: collection.CSIProducer = collection.noop
|
csi_producer: collection.CSIProducer = collection.noop
|
||||||
is_live = True
|
is_live = True
|
||||||
|
|
||||||
|
|
||||||
def main(from_file: Path | None = None) -> None:
|
def main(
|
||||||
global csi_producer, is_live
|
from_file: Annotated[
|
||||||
|
Path | None,
|
||||||
|
typer.Option(help="Read CSI data from file. Uses live data if not specified"),
|
||||||
|
] = None,
|
||||||
|
config: Annotated[
|
||||||
|
Path, typer.Option(help="Specify path to config file", exists=True)
|
||||||
|
] = Path("config.yaml"),
|
||||||
|
) -> None:
|
||||||
|
global csi_producer, is_live, config_path
|
||||||
if from_file:
|
if from_file:
|
||||||
csi_producer = partial(file.start_processing, file_path=from_file)
|
csi_producer = partial(file.start_processing, file_path=from_file)
|
||||||
is_live = False
|
is_live = False
|
||||||
else:
|
else:
|
||||||
csi_producer = ingest.start_processing
|
csi_producer = ingest.start_processing
|
||||||
is_live = True
|
is_live = True
|
||||||
|
|
||||||
|
config_mod.load(config)
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pydantic
|
import pydantic
|
||||||
import yaml
|
import yaml
|
||||||
@ -8,8 +9,13 @@ from . import models
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
config: models.Config | None = None
|
||||||
|
|
||||||
|
|
||||||
|
def load(path: Path) -> None:
|
||||||
|
global config
|
||||||
try:
|
try:
|
||||||
config = yaml.safe_load(open("config.yaml"))
|
config_yaml = yaml.safe_load(open(path))
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger.error(
|
logger.error(
|
||||||
"No config.yaml file found. Make sure to copy the "
|
"No config.yaml file found. Make sure to copy the "
|
||||||
@ -18,7 +24,7 @@ except FileNotFoundError:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = models.Config(**config)
|
config = models.Config(**config_yaml)
|
||||||
except pydantic.ValidationError as e:
|
except pydantic.ValidationError as e:
|
||||||
logger.error(f"Invalid config.yaml file: {e}")
|
logger.error(f"Invalid config.yaml file: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user