Skip to content

Commit b6b6b50

Browse files
committed
Early development of command line tool for generating a configuration file
1 parent 7fc5e28 commit b6b6b50

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ murfey = "murfey.client:run"
8484
"murfey.db_sql" = "murfey.cli.murfey_db_sql:run"
8585
"murfey.decrypt_password" = "murfey.cli.decrypt_db_password:run"
8686
"murfey.dlq_murfey" = "murfey.cli.dlq_resubmit:run"
87+
"murfey.generate_config" = "murfey.cli.generate_config:run"
8788
"murfey.generate_key" = "murfey.cli.generate_crypto_key:run"
8889
"murfey.generate_password" = "murfey.cli.generate_db_password:run"
8990
"murfey.instrument_server" = "murfey.instrument_server:run"

src/murfey/cli/generate_config.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pydantic import ValidationError
2+
from pydantic.fields import UndefinedType
3+
from rich.pretty import pprint
4+
from rich.prompt import Prompt
5+
6+
from murfey.util.config import MachineConfig
7+
8+
9+
def run():
10+
new_config = {}
11+
for k, field in MachineConfig.__fields__.items():
12+
pprint(field.name)
13+
pprint(field.field_info.description)
14+
if isinstance(field.field_info.default, UndefinedType):
15+
value = Prompt.ask("Please provide a value")
16+
else:
17+
value = Prompt.ask(
18+
"Please provide a value", default=field.field_info.default
19+
)
20+
new_config[k] = value
21+
22+
try:
23+
MachineConfig.validate(new_config)
24+
except ValidationError as exc:
25+
for ve in exc.errors():
26+
if ve["type"] != "value_error.missing":
27+
print("Validation failed")

src/murfey/util/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class MachineConfig(BaseModel):
103103
def __validate_rsync_basepath_if_transfer_enabled__(
104104
cls, v: Optional[str], values: Mapping[str, Any]
105105
) -> Any:
106-
if values["data_transfer_enabled"]:
106+
if values.get("data_transfer_enabled"):
107107
if v is None:
108108
raise NoneIsNotAllowedError
109109
return v
@@ -112,7 +112,9 @@ def __validate_rsync_basepath_if_transfer_enabled__(
112112
def __validate_default_model_if_processing_enabled_and_spa_possible__(
113113
cls, v: Optional[str], values: Mapping[str, Any]
114114
) -> Any:
115-
if values["processing_enabled"] and "epu" in values["acquisition_software"]:
115+
if values.get("processing_enabled") and "epu" in values.get(
116+
"acquisition_software", []
117+
):
116118
if v is None:
117119
raise NoneIsNotAllowedError
118120
return v

0 commit comments

Comments
 (0)