mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-31 01:51:53 +08:00
refactoring
This commit is contained in:
@@ -179,7 +179,7 @@ def _init_config(config_path: str, override_options: list[str], **load_flags: bo
|
||||
scheme = _get_config_scheme()
|
||||
try:
|
||||
yaml_merge(raw_config, (raw_config.pop("override", {}) or {}))
|
||||
yaml_merge(raw_config, build_raw_from_options(override_options), "raw command line options")
|
||||
yaml_merge(raw_config, build_raw_from_options(override_options), "raw CLI options")
|
||||
_patch_raw(raw_config)
|
||||
config = make_config(raw_config, scheme)
|
||||
|
||||
|
||||
@@ -19,10 +19,25 @@
|
||||
# #
|
||||
# ========================================================================== #
|
||||
|
||||
from typing import Optional
|
||||
|
||||
|
||||
# =====
|
||||
def yaml_merge(dest: dict, src: dict, src_name: str="") -> None:
|
||||
""" Merges the source dictionary into the destination dictionary. """
|
||||
|
||||
# Checking if destination is None
|
||||
if dest is None:
|
||||
# We can't merge into a None
|
||||
raise ValueError(f"Could not merge {src_name or 'config'} into None. The destination cannot be None")
|
||||
|
||||
# Checking if source is None or empty
|
||||
if not src:
|
||||
# If src is None or empty, there's nothing to merge
|
||||
return
|
||||
|
||||
_merge(dest, src)
|
||||
|
||||
|
||||
# ======
|
||||
def _merge(dest: dict, src: dict) -> None:
|
||||
for key in src:
|
||||
if key in dest:
|
||||
@@ -30,19 +45,3 @@ def _merge(dest: dict, src: dict) -> None:
|
||||
_merge(dest[key], src[key])
|
||||
continue
|
||||
dest[key] = src[key]
|
||||
|
||||
|
||||
def yaml_merge(dest: dict, src: dict, source_name: Optional[str]=None) -> None:
|
||||
""" Merges the source dictionary into the destination dictionary. """
|
||||
|
||||
# Checking if destination is None
|
||||
if dest is None:
|
||||
# We can't merge into a None
|
||||
raise ValueError(f"Could not merge {source_name} into None. The destination cannot be None")
|
||||
|
||||
# Checking if source is None or empty
|
||||
if src is None:
|
||||
# If src is None or empty, there's nothing to merge
|
||||
return
|
||||
|
||||
_merge(dest, src)
|
||||
|
||||
Reference in New Issue
Block a user