Skip to content

Commit

Permalink
fixed env2conf
Browse files Browse the repository at this point in the history
  • Loading branch information
Meisterschueler committed Feb 10, 2025
1 parent 290049d commit 4e407f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
- .env
environment:
Demodulator_PipeName: ogn-rf:50010
APRS_Server: "aprs-filter:14580"
volumes:
- shared_data:/shared_data
healthcheck:
Expand Down
17 changes: 15 additions & 2 deletions scripts/env2conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def unflatten_dict(d: Dict[str, str]) -> Dict[str, Any]:
if part not in d:
d[part] = {}
d = d[part]
d[parts[-1]] = value
d[parts[-1]] = correct_datatype(value)
return unflattened_dict

def flatten_dict(d: Dict[str, Any], parent_key: str ='') -> Dict[str, str]:
Expand All @@ -40,10 +40,23 @@ def is_numeric(value):
if isinstance(value, (int, float)):
return True
elif isinstance(value, str):
return bool(re.match(r'^-?\d+(\.\d+)?$', value))
return bool(re.match(r'^\s*[+-]?\d+(\.\d+)?\s*$', value))
else:
return False

def correct_datatype(value):
if isinstance(value, (int, float)):
return value
elif isinstance(value, str):
if re.match(r'^\s*[+-]?\d+\s*$', value):
return int(value)
elif re.match(r'^\s*[+-]?\d+\.\d+\s*$', value):
return float(value)
else:
return value
else:
raise NotImplementedError(value)

def validate_mandatory_parameters(parameters: Dict[str, Any]) -> None:
"""Check if mandatory parameter APRS_Call, and Position_xxx are correctly set."""

Expand Down

0 comments on commit 4e407f5

Please sign in to comment.