2019-04-13 20:17:01 +00:00
|
|
|
"""Validate manifests."""
|
|
|
|
import pathlib
|
|
|
|
import sys
|
|
|
|
|
2019-12-09 21:43:38 +00:00
|
|
|
from . import (
|
|
|
|
codeowners,
|
|
|
|
config_flow,
|
|
|
|
dependencies,
|
|
|
|
json,
|
|
|
|
manifest,
|
|
|
|
services,
|
|
|
|
ssdp,
|
|
|
|
zeroconf,
|
|
|
|
)
|
2019-12-09 15:24:03 +00:00
|
|
|
from .model import Config, Integration
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-12-09 21:43:38 +00:00
|
|
|
PLUGINS = [
|
|
|
|
json,
|
|
|
|
codeowners,
|
|
|
|
config_flow,
|
|
|
|
dependencies,
|
|
|
|
manifest,
|
|
|
|
services,
|
|
|
|
ssdp,
|
|
|
|
zeroconf,
|
|
|
|
]
|
2019-04-13 20:17:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_config() -> Config:
|
|
|
|
"""Return config."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if not pathlib.Path("requirements_all.txt").is_file():
|
2019-04-13 20:17:01 +00:00
|
|
|
raise RuntimeError("Run from project root")
|
|
|
|
|
|
|
|
return Config(
|
2019-07-31 19:25:30 +00:00
|
|
|
root=pathlib.Path(".").absolute(),
|
|
|
|
action="validate" if sys.argv[-1] == "validate" else "generate",
|
2019-04-13 20:17:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Validate manifests."""
|
|
|
|
try:
|
|
|
|
config = get_config()
|
|
|
|
except RuntimeError as err:
|
|
|
|
print(err)
|
|
|
|
return 1
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
integrations = Integration.load_dir(pathlib.Path("homeassistant/components"))
|
2019-04-23 06:34:37 +00:00
|
|
|
|
|
|
|
for plugin in PLUGINS:
|
|
|
|
plugin.validate(integrations, config)
|
2019-04-13 20:17:01 +00:00
|
|
|
|
|
|
|
# When we generate, all errors that are fixable will be ignored,
|
|
|
|
# as generating them will be fixed.
|
2019-07-31 19:25:30 +00:00
|
|
|
if config.action == "generate":
|
2019-04-13 20:17:01 +00:00
|
|
|
general_errors = [err for err in config.errors if not err.fixable]
|
|
|
|
invalid_itg = [
|
2019-07-31 19:25:30 +00:00
|
|
|
itg
|
|
|
|
for itg in integrations.values()
|
|
|
|
if any(not error.fixable for error in itg.errors)
|
2019-04-13 20:17:01 +00:00
|
|
|
]
|
|
|
|
else:
|
|
|
|
# action == validate
|
|
|
|
general_errors = config.errors
|
|
|
|
invalid_itg = [itg for itg in integrations.values() if itg.errors]
|
|
|
|
|
|
|
|
print("Integrations:", len(integrations))
|
|
|
|
print("Invalid integrations:", len(invalid_itg))
|
|
|
|
|
|
|
|
if not invalid_itg and not general_errors:
|
2019-04-23 06:34:37 +00:00
|
|
|
for plugin in PLUGINS:
|
2019-07-31 19:25:30 +00:00
|
|
|
if hasattr(plugin, "generate"):
|
2019-04-23 06:34:37 +00:00
|
|
|
plugin.generate(integrations, config)
|
|
|
|
|
2019-04-13 20:17:01 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
print()
|
2019-07-31 19:25:30 +00:00
|
|
|
if config.action == "generate":
|
2019-04-13 20:17:01 +00:00
|
|
|
print("Found errors. Generating files canceled.")
|
|
|
|
print()
|
|
|
|
|
|
|
|
if general_errors:
|
|
|
|
print("General errors:")
|
|
|
|
for error in general_errors:
|
|
|
|
print("*", error)
|
|
|
|
print()
|
|
|
|
|
|
|
|
for integration in sorted(invalid_itg, key=lambda itg: itg.domain):
|
2019-08-23 16:53:33 +00:00
|
|
|
print(f"Integration {integration.domain}:")
|
2019-04-13 20:17:01 +00:00
|
|
|
for error in integration.errors:
|
|
|
|
print("*", error)
|
|
|
|
print()
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|