-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cba20e2
commit 90dd6e9
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
...lectrical_heating/electrical_heating_job/entry_points/job_args/electrical_heating_args.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from dataclasses import dataclass | ||
|
||
@dataclass | ||
class ElectricalHeatingArgs: | ||
electrical_heating_id: str |
40 changes: 40 additions & 0 deletions
40
...rical_heating/electrical_heating_job/entry_points/job_args/electrical_heating_job_args.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import argparse | ||
import sys | ||
import configargparse | ||
from argparse import Namespace | ||
from telemetry_logging import Logger, logging_configuration | ||
from source.electrical_heating.electrical_heating_job.entry_points.job_args.electrical_heating_args import ElectricalHeatingArgs | ||
|
||
def parse_command_line_arguments() -> Namespace: | ||
return _parse_args_or_throw(sys.argv[1:]) | ||
|
||
|
||
def parse_job_arguments( | ||
job_args: Namespace, | ||
) -> ElectricalHeatingArgs: | ||
logger = Logger(__name__) | ||
logger.info(f"Command line arguments: {repr(job_args)}") | ||
|
||
with logging_configuration.start_span("electrical_heating.parse_job_arguments"): | ||
|
||
electrical_heating_args = ElectricalHeatingArgs( | ||
electrical_heating_id=job_args.electrical_heating_id, | ||
) | ||
|
||
return electrical_heating_args | ||
|
||
def _parse_args_or_throw(command_line_args: list[str]) -> argparse.Namespace: | ||
p = configargparse.ArgParser( | ||
description="Execute electrical heating calculation", | ||
formatter_class=configargparse.ArgumentDefaultsHelpFormatter, | ||
) | ||
|
||
# Run parameters | ||
p.add_argument("--electrical-heating-id", type=str, required=True) | ||
|
||
args, unknown_args = p.parse_known_args(args=command_line_args) | ||
if len(unknown_args): | ||
unknown_args_text = ", ".join(unknown_args) | ||
raise Exception(f"Unknown args: {unknown_args_text}") | ||
|
||
return args |