2022-07-02 16:00:54 +02:00
|
|
|
import glob
|
|
|
|
import re
|
|
|
|
|
2022-07-10 18:07:11 +02:00
|
|
|
from bs4 import BeautifulSoup
|
2022-07-02 16:00:54 +02:00
|
|
|
|
2022-09-07 13:04:16 +02:00
|
|
|
from utils import deduplicate_list, write_to_file
|
2022-07-02 16:00:54 +02:00
|
|
|
|
|
|
|
|
2022-12-29 00:22:53 +01:00
|
|
|
def build_notification_providers(root):
|
2022-07-10 18:07:11 +02:00
|
|
|
providers = []
|
2022-12-29 00:22:53 +01:00
|
|
|
for path in glob.glob(f'{root}/server/notification-providers/*'):
|
2022-07-10 18:07:11 +02:00
|
|
|
with open(path) as f:
|
|
|
|
content = f.read()
|
|
|
|
match = re.search(r'class [^ ]+ extends NotificationProvider {', content)
|
|
|
|
if match:
|
|
|
|
match = re.search(r'name = "([^"]+)";', content)
|
|
|
|
name = match.group(1)
|
2022-07-02 16:00:54 +02:00
|
|
|
|
2022-07-10 18:07:11 +02:00
|
|
|
inputs = re.findall(r'notification\.([^ ,.;})\]]+)', content)
|
|
|
|
inputs = deduplicate_list(inputs)
|
|
|
|
inputs = [i.strip() for i in inputs]
|
2022-07-02 16:00:54 +02:00
|
|
|
|
2022-07-10 18:07:11 +02:00
|
|
|
providers.append({
|
|
|
|
"name": name,
|
|
|
|
"inputs": inputs,
|
|
|
|
})
|
|
|
|
return providers
|
2022-07-02 16:00:54 +02:00
|
|
|
|
2022-07-10 18:07:11 +02:00
|
|
|
|
2022-12-29 00:22:53 +01:00
|
|
|
def build_notification_provider_conditions(root):
|
2022-07-10 18:07:11 +02:00
|
|
|
conditions = {}
|
2022-12-29 00:22:53 +01:00
|
|
|
for path in glob.glob(f'{root}/src/components/notifications/*'):
|
2022-07-10 18:07:11 +02:00
|
|
|
if path.endswith("index.js"):
|
|
|
|
continue
|
|
|
|
with open(path) as f:
|
|
|
|
content = f.read()
|
|
|
|
match = re.search(r'<template>[\s\S]+</template>', content, re.MULTILINE)
|
|
|
|
html = match.group(0)
|
|
|
|
soup = BeautifulSoup(html, "html.parser")
|
|
|
|
inputs = soup.find_all("input")
|
|
|
|
for input in inputs:
|
|
|
|
condition = {}
|
|
|
|
attrs = input.attrs
|
|
|
|
v_model = attrs.get("v-model")
|
|
|
|
min_ = attrs.get("min")
|
|
|
|
max_ = attrs.get("max")
|
|
|
|
if min_:
|
|
|
|
condition["min"] = int(min_)
|
|
|
|
if max_:
|
|
|
|
condition["max"] = int(max_)
|
|
|
|
param_name = re.match(r'\$parent.notification.(.*)$', v_model).group(1)
|
|
|
|
if condition:
|
|
|
|
conditions[param_name] = condition
|
|
|
|
return conditions
|
2022-07-02 16:00:54 +02:00
|
|
|
|
|
|
|
|
2022-12-29 00:22:53 +01:00
|
|
|
def diff(old, new):
|
|
|
|
for i in new:
|
|
|
|
if i not in old:
|
|
|
|
print("+", i)
|
|
|
|
for i in old:
|
|
|
|
if i not in new:
|
|
|
|
print("-", i)
|
|
|
|
print("")
|
2022-07-02 16:00:54 +02:00
|
|
|
|
2022-12-29 00:22:53 +01:00
|
|
|
|
|
|
|
# write_to_file(
|
|
|
|
# "notification_providers.py.j2", "./../uptime_kuma_api/notification_providers.py",
|
|
|
|
# notification_providers=notification_providers,
|
|
|
|
# notification_provider_conditions=notification_provider_conditions
|
|
|
|
# )
|
|
|
|
|
|
|
|
notification_providers_old = build_notification_providers("uptime-kuma-old")
|
|
|
|
notification_providers_new = build_notification_providers("uptime-kuma")
|
|
|
|
diff(notification_providers_old, notification_providers_new)
|
|
|
|
|
|
|
|
notification_provider_conditions_old = build_notification_provider_conditions("uptime-kuma-old")
|
|
|
|
notification_provider_conditions_new = build_notification_provider_conditions("uptime-kuma")
|
|
|
|
diff(notification_provider_conditions_old, notification_provider_conditions_new)
|