update scripts
This commit is contained in:
parent
a7f571f508
commit
384fd21726
12 changed files with 231 additions and 113 deletions
78
scripts/build_inputs.py
Normal file
78
scripts/build_inputs.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
import glob
|
||||
import re
|
||||
|
||||
from utils import deduplicate_list, parse_vue_template
|
||||
|
||||
|
||||
def parse_model_keys(content, object_name):
|
||||
match = re.findall(object_name + r"\.[0-9a-zA-Z_$]+", content)
|
||||
keys = []
|
||||
for m in match:
|
||||
key = m.replace(object_name + ".", "")
|
||||
keys.append(key)
|
||||
keys = deduplicate_list(keys)
|
||||
return keys
|
||||
|
||||
|
||||
def parse_proxy_keys():
|
||||
content = parse_vue_template("uptime-kuma/src/components/ProxyDialog.vue")
|
||||
keys = parse_model_keys(content, "proxy")
|
||||
return keys
|
||||
|
||||
|
||||
def parse_notification_keys():
|
||||
content = parse_vue_template("uptime-kuma/src/components/NotificationDialog.vue")
|
||||
keys = parse_model_keys(content, "notification")
|
||||
return keys
|
||||
|
||||
|
||||
def parse_settings_keys():
|
||||
all_keys = []
|
||||
for path in glob.glob('uptime-kuma/src/components/settings/*'):
|
||||
content = parse_vue_template(path)
|
||||
keys = parse_model_keys(content, "settings")
|
||||
all_keys.extend(keys)
|
||||
all_keys = deduplicate_list(all_keys)
|
||||
return all_keys
|
||||
|
||||
|
||||
def parse_monitor_keys():
|
||||
content = parse_vue_template("uptime-kuma/src/pages/EditMonitor.vue")
|
||||
keys = parse_model_keys(content, "monitor")
|
||||
return keys
|
||||
|
||||
|
||||
def parse_status_page_keys():
|
||||
all_keys = ["id"]
|
||||
|
||||
content = parse_vue_template("uptime-kuma/src/pages/StatusPage.vue")
|
||||
keys = parse_model_keys(content, "config")
|
||||
all_keys.extend(keys)
|
||||
|
||||
content = parse_vue_template("uptime-kuma/src/pages/ManageStatusPage.vue")
|
||||
keys = parse_model_keys(content, "statusPage")
|
||||
all_keys.extend(keys)
|
||||
|
||||
all_keys = deduplicate_list(all_keys)
|
||||
return all_keys
|
||||
|
||||
|
||||
def main():
|
||||
proxy_keys = parse_proxy_keys()
|
||||
print("proxy:", proxy_keys)
|
||||
|
||||
notification_keys = parse_notification_keys()
|
||||
print("notification:", notification_keys)
|
||||
|
||||
settings_keys = parse_settings_keys()
|
||||
print("settings:", settings_keys)
|
||||
|
||||
monitor_keys = parse_monitor_keys()
|
||||
print("monitor:", monitor_keys)
|
||||
|
||||
status_page_keys = parse_status_page_keys()
|
||||
print("status_page:", status_page_keys)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,8 +1,10 @@
|
|||
import re
|
||||
from pprint import pprint
|
||||
|
||||
from utils import deduplicate_list
|
||||
|
||||
def parse_data_keys(data):
|
||||
|
||||
def parse_json_keys(data):
|
||||
keys = []
|
||||
for line in data.split("\n"):
|
||||
line = line.strip()
|
||||
|
@ -17,19 +19,28 @@ def parse_data_keys(data):
|
|||
return keys
|
||||
|
||||
|
||||
# def parse_object_keys(code, object_name):
|
||||
# match = re.findall(object_name + r'\.[0-9a-zA-Z_$]+', code)
|
||||
# keys = []
|
||||
# for m in match:
|
||||
# key = m.replace(object_name + ".", "")
|
||||
# keys.append(key)
|
||||
# return list(set(keys))
|
||||
|
||||
|
||||
def parse_heartbeat():
|
||||
with open('uptime-kuma/server/model/heartbeat.js') as f:
|
||||
content = f.read()
|
||||
all_keys = []
|
||||
match = re.search(r'toJSON\(\) {\s+return.*{([^}]+)}', content)
|
||||
data = match.group(1)
|
||||
keys = parse_data_keys(data)
|
||||
keys = parse_json_keys(data)
|
||||
all_keys.extend(keys)
|
||||
match = re.search(r'toPublicJSON\(\) {\s+return.*{([^}]+)}', content)
|
||||
data = match.group(1)
|
||||
keys = parse_data_keys(data)
|
||||
keys = parse_json_keys(data)
|
||||
all_keys.extend(keys)
|
||||
all_keys = list(set(all_keys))
|
||||
all_keys = deduplicate_list(all_keys)
|
||||
return all_keys
|
||||
|
||||
|
||||
|
@ -38,7 +49,7 @@ def parse_incident():
|
|||
content = f.read()
|
||||
match = re.search(r'toPublicJSON\(\) {\s+return.*{([^}]+)}', content)
|
||||
data = match.group(1)
|
||||
keys = parse_data_keys(data)
|
||||
keys = parse_json_keys(data)
|
||||
return keys
|
||||
|
||||
|
||||
|
@ -49,9 +60,10 @@ def parse_monitor():
|
|||
matches = re.findall(r'data = {([^}]+)}', content)
|
||||
all_keys = []
|
||||
for match in matches:
|
||||
keys = parse_data_keys(match)
|
||||
keys = parse_json_keys(match)
|
||||
keys = [i for i in keys if i != "...data"]
|
||||
all_keys.extend(keys)
|
||||
all_keys = deduplicate_list(all_keys)
|
||||
return all_keys
|
||||
|
||||
|
||||
|
@ -60,23 +72,54 @@ def parse_proxy():
|
|||
content = f.read()
|
||||
match = re.search(r'toJSON\(\) {\s+return.*{([^}]+)}', content)
|
||||
data = match.group(1)
|
||||
keys = parse_data_keys(data)
|
||||
keys = parse_json_keys(data)
|
||||
return keys
|
||||
|
||||
|
||||
# def parse_function(regex_name, content):
|
||||
# match = re.search(regex_name, content)
|
||||
# name = match.group(0)
|
||||
# rest = "".join(content.split(name)[1:])
|
||||
#
|
||||
# brackets = 0
|
||||
# opening_bracket_found = False
|
||||
# code = ""
|
||||
# for i in rest:
|
||||
# code += i
|
||||
# if i == "{":
|
||||
# opening_bracket_found = True
|
||||
# brackets += 1
|
||||
# if i == "}":
|
||||
# opening_bracket_found = True
|
||||
# brackets -= 1
|
||||
# if opening_bracket_found and brackets == 0:
|
||||
# break
|
||||
# return code
|
||||
|
||||
|
||||
# # input (add, edit proxy)
|
||||
# def parse_proxy2():
|
||||
# with open('uptime-kuma/server/proxy.js') as f:
|
||||
# content = f.read()
|
||||
#
|
||||
# code = parse_function(r'async save\([^)]+\) ', content)
|
||||
# keys = parse_object_keys(code, "proxy")
|
||||
# return keys
|
||||
|
||||
|
||||
def parse_status_page():
|
||||
with open('uptime-kuma/server/model/status_page.js') as f:
|
||||
content = f.read()
|
||||
all_keys = []
|
||||
match = re.search(r'toJSON\(\) {\s+return.*{([^}]+)}', content)
|
||||
data = match.group(1)
|
||||
keys = parse_data_keys(data)
|
||||
keys = parse_json_keys(data)
|
||||
all_keys.extend(keys)
|
||||
match = re.search(r'toPublicJSON\(\) {\s+return.*{([^}]+)}', content)
|
||||
data = match.group(1)
|
||||
keys = parse_data_keys(data)
|
||||
keys = parse_json_keys(data)
|
||||
all_keys.extend(keys)
|
||||
all_keys = list(set(all_keys))
|
||||
all_keys = deduplicate_list(all_keys)
|
||||
return all_keys
|
||||
|
||||
|
||||
|
@ -85,16 +128,37 @@ def parse_tag():
|
|||
content = f.read()
|
||||
match = re.search(r'toJSON\(\) {\s+return.*{([^}]+)}', content)
|
||||
data = match.group(1)
|
||||
keys = parse_data_keys(data)
|
||||
keys = parse_json_keys(data)
|
||||
return keys
|
||||
|
||||
|
||||
print("heartbeat")
|
||||
pprint(parse_heartbeat())
|
||||
print("")
|
||||
|
||||
print("incident")
|
||||
pprint(parse_incident())
|
||||
print("")
|
||||
|
||||
print("monitor")
|
||||
pprint(parse_monitor())
|
||||
print("")
|
||||
|
||||
print("proxy")
|
||||
pprint(parse_proxy())
|
||||
print("")
|
||||
|
||||
# print("prox2")
|
||||
# pprint(parse_proxy2())
|
||||
# print("")
|
||||
|
||||
print("status page")
|
||||
pprint(parse_status_page())
|
||||
print("")
|
||||
|
||||
print("tag")
|
||||
pprint(parse_tag())
|
||||
print("")
|
||||
|
||||
|
||||
# TODO:
|
||||
|
|
25
scripts/build_monitor_types.py
Normal file
25
scripts/build_monitor_types.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from bs4 import BeautifulSoup
|
||||
|
||||
from utils import parse_vue_template, write_to_file
|
||||
|
||||
|
||||
def parse_monitor_types():
|
||||
content = parse_vue_template("uptime-kuma/src/pages/EditMonitor.vue")
|
||||
|
||||
soup = BeautifulSoup(content, "html.parser")
|
||||
select = soup.find("select", id="type")
|
||||
options = select.find_all("option")
|
||||
|
||||
types = []
|
||||
for o in options:
|
||||
type_ = o.attrs["value"]
|
||||
types.append(type_)
|
||||
return types
|
||||
|
||||
|
||||
monitor_types = parse_monitor_types()
|
||||
|
||||
write_to_file(
|
||||
"monitor_type.py.j2", "./../uptime_kuma_api/monitor_type.py",
|
||||
monitor_types=monitor_types
|
||||
)
|
|
@ -1,18 +0,0 @@
|
|||
from uptime_kuma_api import notification_provider_options
|
||||
|
||||
|
||||
def build_providers():
|
||||
providers = []
|
||||
for provider_enum in notification_provider_options:
|
||||
provider = provider_enum.__dict__["_value_"]
|
||||
providers.append(provider)
|
||||
return providers
|
||||
|
||||
|
||||
for provider in build_providers():
|
||||
options = notification_provider_options[provider]
|
||||
for option in options:
|
||||
print(f'{option}:')
|
||||
print(f' description: {provider} provider option.')
|
||||
print(f' returned: if type is {provider}')
|
||||
print(' type: str')
|
|
@ -1,19 +1,9 @@
|
|||
import glob
|
||||
import re
|
||||
from pprint import pprint
|
||||
|
||||
import jinja2
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from uptime_kuma_api import convert_from_socket, params_map_notification_provider_options
|
||||
|
||||
|
||||
def deduplicate_list(l):
|
||||
out = []
|
||||
for i in l:
|
||||
if i not in out:
|
||||
out.append(i)
|
||||
return out
|
||||
from utils import deduplicate_list, write_to_file
|
||||
|
||||
|
||||
def build_notification_providers():
|
||||
|
@ -61,18 +51,14 @@ def build_notification_provider_conditions():
|
|||
param_name = re.match(r'\$parent.notification.(.*)$', v_model).group(1)
|
||||
if condition:
|
||||
conditions[param_name] = condition
|
||||
conditions = convert_from_socket(params_map_notification_provider_options, conditions)
|
||||
return conditions
|
||||
|
||||
|
||||
def write_to_file(template, destination, **kwargs):
|
||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader("./"))
|
||||
template = env.get_template(template)
|
||||
rendered = template.render(**kwargs)
|
||||
with open(destination, "w") as f:
|
||||
f.write(rendered)
|
||||
notification_providers = build_notification_providers()
|
||||
notification_provider_conditions = build_notification_provider_conditions()
|
||||
|
||||
conditions = build_notification_provider_conditions()
|
||||
pprint(conditions)
|
||||
# notification_providers = build_notification_providers()
|
||||
# write_to_file("notification_providers.py.j2", "./../uptimekumaapi/notification_providers.py", notification_providers=notification_providers)
|
||||
write_to_file(
|
||||
"notification_providers.py.j2", "./../uptime_kuma_api/notification_providers.py",
|
||||
notification_providers=notification_providers,
|
||||
notification_provider_conditions=notification_provider_conditions
|
||||
)
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
params_map_notification_provider_options = {
|
||||
{%- for provider in notification_provider_map %}
|
||||
{%- set options = notification_provider_map[provider] %}
|
||||
'{{ provider }}': {
|
||||
{%- for key, value in options.items() %}
|
||||
'{{ key }}': '{{ value }}',
|
||||
{%- endfor %}
|
||||
},
|
||||
{%- endfor %}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
import re
|
||||
import os
|
||||
import jinja2
|
||||
|
||||
from uptime_kuma_api import params_map_notification_providers, notification_provider_options
|
||||
|
||||
|
||||
def build_notification_provider_map():
|
||||
params_map_notification_provider_options = {}
|
||||
|
||||
for provider_sock, provider_py in params_map_notification_providers.items():
|
||||
options_sock = notification_provider_options[provider_sock]
|
||||
|
||||
params_map_notification_provider_options[provider_py] = {}
|
||||
for option in options_sock:
|
||||
option_orig = option
|
||||
|
||||
# for example for rocket_chat
|
||||
prefix = os.path.commonprefix([o.lower() for o in options_sock] + [provider_py])
|
||||
option = option[len(prefix):]
|
||||
|
||||
option = re.sub('([A-Z]+)', r'_\1', option).lower()
|
||||
|
||||
# for example for smtp
|
||||
if option.startswith(provider_py):
|
||||
option = option[len(provider_py):]
|
||||
|
||||
option = provider_py + "_" + option
|
||||
option = option.replace("__", "_")
|
||||
|
||||
params_map_notification_provider_options[provider_py][option_orig] = option
|
||||
return params_map_notification_provider_options
|
||||
|
||||
|
||||
notification_provider_map = build_notification_provider_map()
|
||||
|
||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader("./"))
|
||||
template = env.get_template("build_params_map_notification_provider_options.j2")
|
||||
rendered = template.render(notification_provider_map=notification_provider_map)
|
||||
print(rendered)
|
|
@ -1,12 +0,0 @@
|
|||
import re
|
||||
|
||||
from uptime_kuma_api import notification_provider_options
|
||||
|
||||
|
||||
params_map_notification_providers = {}
|
||||
|
||||
for notification_provider in notification_provider_options:
|
||||
provider_name_orig = notification_provider.__dict__["_value_"]
|
||||
provider_name = re.sub('([A-Z]+)', r'_\1', provider_name_orig).lower().replace(".", "_").strip("_")
|
||||
params_map_notification_providers[provider_name_orig] = provider_name
|
||||
print(params_map_notification_providers)
|
8
scripts/monitor_type.py.j2
Normal file
8
scripts/monitor_type.py.j2
Normal file
|
@ -0,0 +1,8 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class MonitorType(str, Enum):
|
||||
{%- for name in monitor_types %}
|
||||
{{ name.upper() }} = "{{ name }}"
|
||||
{%- endfor %}
|
||||
|
|
@ -19,3 +19,13 @@ notification_provider_options = {
|
|||
{%- endfor %}
|
||||
}
|
||||
|
||||
notification_provider_conditions = {
|
||||
{%- for provider in notification_provider_conditions %}
|
||||
"{{ provider }}": {
|
||||
{%- for key, value in notification_provider_conditions[provider].items() %}
|
||||
"{{ key }}": {{ value }},
|
||||
{%- endfor %}
|
||||
},
|
||||
{%- endfor %}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
Jinja2==3.1.2
|
||||
BeautifulSoup4==4.11.1
|
||||
|
|
26
scripts/utils.py
Normal file
26
scripts/utils.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
import re
|
||||
import jinja2
|
||||
|
||||
|
||||
def deduplicate_list(l):
|
||||
out = []
|
||||
for i in l:
|
||||
if i not in out:
|
||||
out.append(i)
|
||||
return out
|
||||
|
||||
|
||||
def parse_vue_template(path):
|
||||
with open(path) as f:
|
||||
vue = f.read()
|
||||
match = re.search(r'<template>[\s\S]+</template>', vue, re.MULTILINE)
|
||||
template = match.group(0)
|
||||
return template
|
||||
|
||||
|
||||
def write_to_file(template, destination, **kwargs):
|
||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader("./"))
|
||||
template = env.get_template(template)
|
||||
rendered = template.render(**kwargs)
|
||||
with open(destination, "w") as f:
|
||||
f.write(rendered)
|
Loading…
Reference in a new issue