forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
36 lines (24 loc) · 926 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Utility functions for the scaffold script."""
import argparse
from typing import Any
from .const import COMPONENT_DIR
def valid_integration(integration):
"""Test if it's a valid integration."""
if not (COMPONENT_DIR / integration).exists():
raise argparse.ArgumentTypeError(
f"The integration {integration} does not exist."
)
return integration
_MANIFEST_SORT_KEYS = {"domain": ".domain", "name": ".name"}
def _sort_manifest_keys(key: str) -> str:
"""Sort manifest keys."""
return _MANIFEST_SORT_KEYS.get(key, key)
def sort_manifest(manifest: dict[str, Any]) -> bool:
"""Sort manifest."""
keys = list(manifest)
if (keys_sorted := sorted(keys, key=_sort_manifest_keys)) != keys:
sorted_manifest = {key: manifest[key] for key in keys_sorted}
manifest.clear()
manifest.update(sorted_manifest)
return True
return False