Skip to content

Commit 3cc5eb6

Browse files
committed
add version parameter to the script
1 parent a8ded3b commit 3cc5eb6

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/videoipath_automation_tool/apps/inventory/model/drivers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from abc import ABC
2-
from typing import Dict, Literal, Type, TypeVar, Union, Optional
2+
from typing import Dict, Literal, Optional, Type, TypeVar, Union
33

44
from pydantic import BaseModel, Field
55

66
# Notes:
77
# - The name of the custom settings model follows the naming convention: CustomSettings_<driver_organization>_<driver_name>_<driver_version> => "." and "-" are replaced by "_"!
8-
# - src/videoipath_automation_tool/apps/inventory/model/driver_schema/2024.1.4.json is used as reference to define the custom settings model!
8+
# - Schema 2024.4.12.json is used as reference to define the custom settings model!
99
# - The "driver_id" attribute is necessary for the discriminator, which is used to determine the correct model for the custom settings in DeviceConfiguration!
1010
# - The "alias" attribute is used to map the attribute to the correct key (with driver organization & name) in the JSON payload for the API!
1111
# - "DriverLiteral" is used to provide a list of all possible drivers in the IDEs IntelliSense!
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
from videoipath_automation_tool.scripts.generate_driver_models import DEFAULT_OUTPUT_FILE, DEFAULT_SCHEMA_FILE, parser
1+
import argparse
2+
import os
3+
24
from videoipath_automation_tool.scripts.generate_driver_models import main as generate_driver_models
35
from videoipath_automation_tool.scripts.generate_overloads import main as generate_overloads
6+
from videoipath_automation_tool.utils.script_utils import ROOT_DIR
7+
8+
parser = argparse.ArgumentParser(description="Generate all version-specific code for a given VideoIPath version")
9+
parser.add_argument("version", help="Version of VideoIPath to use", default="2024.4.12", nargs="?")
10+
411

12+
def main():
13+
args = parser.parse_args()
14+
schema_file = os.path.join(ROOT_DIR, "apps", "inventory", "model", "driver_schema", f"{args.version}.json")
15+
16+
if not os.path.exists(schema_file):
17+
print(
18+
f"VideoIPath version {args.version} is currently not supported. Please create an issue on https://github.com/SWR-MoIP/VideoIPath-Automation-Tool/issues to request support for this version."
19+
)
20+
exit(1)
521

6-
def main(
7-
schema_file: str = DEFAULT_SCHEMA_FILE,
8-
output_file: str = DEFAULT_OUTPUT_FILE,
9-
):
10-
generate_driver_models(schema_file, output_file)
22+
generate_driver_models(schema_file)
1123
generate_overloads()
1224

1325

1426
if __name__ == "__main__":
15-
args = parser.parse_args()
16-
main(args.schema_file, args.output_file)
27+
main()

src/videoipath_automation_tool/scripts/generate_driver_models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
from videoipath_automation_tool.utils.script_utils import ROOT_DIR, load_module
66

7-
DEFAULT_SCHEMA_FILE = os.path.join(ROOT_DIR, "apps", "inventory", "model", "driver_schema", "2024.3.3.json")
7+
DEFAULT_VERSION = "2024.4.12"
8+
DEFAULT_SCHEMA_FILE = os.path.join(ROOT_DIR, "apps", "inventory", "model", "driver_schema", f"{DEFAULT_VERSION}.json")
89
DEFAULT_OUTPUT_FILE = os.path.join(ROOT_DIR, "apps", "inventory", "model", "drivers.py")
910

1011
parser = argparse.ArgumentParser(description="Generate Pydantic models from driver schema")
@@ -134,7 +135,7 @@ def main(
134135
135136
# Notes:
136137
# - The name of the custom settings model follows the naming convention: CustomSettings_<driver_organization>_<driver_name>_<driver_version> => "." and "-" are replaced by "_"!
137-
# - {schema_file} is used as reference to define the custom settings model!
138+
# - Schema {schema_file.split("/")[-1]} is used as reference to define the custom settings model!
138139
# - The "driver_id" attribute is necessary for the discriminator, which is used to determine the correct model for the custom settings in DeviceConfiguration!
139140
# - The "alias" attribute is used to map the attribute to the correct key (with driver organization & name) in the JSON payload for the API!
140141
# - "DriverLiteral" is used to provide a list of all possible drivers in the IDEs IntelliSense!

0 commit comments

Comments
 (0)