Skip to content

Commit af9856f

Browse files
author
Marc Schöchlin
committed
fix typing
1 parent 65207eb commit af9856f

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/openstack_workload_generator/__main__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from openstack.config import loader
1313

1414
from .entities import WorkloadGeneratorDomain
15-
from .entities.helpers import setup_logging, cloud_checker, item_checker, Config
15+
from .entities.helpers import setup_logging, cloud_checker, item_checker, Config, iso_timestamp, deep_merge_dict
1616

1717
LOGGER = logging.getLogger()
1818

@@ -182,12 +182,19 @@ def establish_connection():
182182
LOGGER.info(f"Creating a a clouds yaml : {args.generate_clouds_yaml}")
183183
clouds_yaml_data_new = {"clouds": clouds_yaml_data}
184184
if os.path.exists(args.generate_clouds_yaml):
185-
with open(args.generate_clouds_yaml, 'r') as file:
185+
with open(args.generate_clouds_yaml, "r") as file:
186186
existing_data = yaml.safe_load(file)
187-
backup_file=f"{args.generate_clouds_yaml}_{iso_timestamp()}"
188-
logging.warning(f"File {args.generate_clouds_yaml}, making an backup to {backup_file} and adding the new values")
189-
shutil.copy2(args.generate_clouds_yaml, f"{args.generate_clouds_yaml}_{iso_timestamp()}")
190-
clouds_yaml_data_new = deep_merge_dict(existing_data,clouds_yaml_data_new)
187+
backup_file = f"{args.generate_clouds_yaml}_{iso_timestamp()}"
188+
logging.warning(
189+
f"File {args.generate_clouds_yaml}, making an backup to {backup_file} and adding the new values"
190+
)
191+
shutil.copy2(
192+
args.generate_clouds_yaml,
193+
f"{args.generate_clouds_yaml}_{iso_timestamp()}",
194+
)
195+
clouds_yaml_data_new = deep_merge_dict(
196+
existing_data, clouds_yaml_data_new
197+
)
191198

192199
with open(args.generate_clouds_yaml, "w") as file:
193200
yaml.dump(

src/openstack_workload_generator/entities/helpers.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import sys
55
from datetime import datetime
6-
from typing import Tuple
6+
from typing import Tuple, Any
77
import coloredlogs
88

99
import re
@@ -252,17 +252,15 @@ def item_checker(value: str) -> str:
252252
raise argparse.ArgumentTypeError("specify a valid name for an item")
253253
return value
254254

255+
255256
def iso_timestamp() -> str:
256257
return datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
257258

258-
def deep_merge_dict(d1: dict, d2: dict) -> dict:
259+
260+
def deep_merge_dict(d1: dict, d2: dict) -> dict[str, Any]:
259261
result = d1.copy()
260262
for key, value in d2.items():
261-
if (
262-
key in result
263-
and isinstance(result[key], dict)
264-
and isinstance(value, dict)
265-
):
263+
if key in result and isinstance(result[key], dict) and isinstance(value, dict):
266264
result[key] = deep_merge_dict(result[key], value)
267265
else:
268266
result[key] = value

0 commit comments

Comments
 (0)