2018-12-09 16:13:46 +01:00
|
|
|
#!/usr/bin/env python3
|
2020-04-16 07:03:42 +02:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import shutil
|
2020-06-11 00:54:34 +02:00
|
|
|
import sys
|
2020-04-20 15:27:36 +02:00
|
|
|
from typing import List
|
2020-04-09 19:33:49 +02:00
|
|
|
|
2020-04-16 07:03:42 +02:00
|
|
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
if ZULIP_PATH not in sys.path:
|
|
|
|
sys.path.append(ZULIP_PATH)
|
2020-04-17 18:24:31 +02:00
|
|
|
from scripts.lib.setup_path import setup_path
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2020-04-17 18:24:31 +02:00
|
|
|
setup_path()
|
|
|
|
|
2020-04-16 07:03:42 +02:00
|
|
|
from zulip_bots.lib import get_bots_directory_path
|
2018-12-09 16:13:46 +01:00
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2020-04-16 07:03:42 +02:00
|
|
|
def generate_zulip_bots_static_files() -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
bots_dir = "static/generated/bots"
|
2018-12-09 16:13:46 +01:00
|
|
|
if os.path.isdir(bots_dir):
|
|
|
|
# delete old static files, they could be outdated
|
2019-09-09 22:06:07 +02:00
|
|
|
shutil.rmtree(bots_dir)
|
2018-12-09 16:13:46 +01:00
|
|
|
|
|
|
|
os.makedirs(bots_dir, exist_ok=True)
|
|
|
|
|
2023-06-05 12:19:19 +02:00
|
|
|
package_bots_dir = get_bots_directory_path()
|
2018-12-09 16:13:46 +01:00
|
|
|
|
2023-06-05 12:19:19 +02:00
|
|
|
def copy_bots_data(bot_names: List[str]) -> None:
|
|
|
|
for name in bot_names:
|
|
|
|
src_dir = os.path.join(package_bots_dir, name)
|
|
|
|
dst_dir = os.path.join(bots_dir, name)
|
|
|
|
doc_path = os.path.join(src_dir, "doc.md")
|
2018-12-09 16:13:46 +01:00
|
|
|
|
2023-06-05 12:19:19 +02:00
|
|
|
if os.path.isfile(doc_path):
|
|
|
|
os.makedirs(dst_dir, exist_ok=True)
|
|
|
|
shutil.copyfile(doc_path, os.path.join(dst_dir, "doc.md"))
|
2018-12-09 16:13:46 +01:00
|
|
|
|
2023-06-05 12:19:19 +02:00
|
|
|
logo_pattern = os.path.join(src_dir, "logo.*")
|
|
|
|
logos = glob.glob(logo_pattern)
|
|
|
|
for logo in logos:
|
|
|
|
shutil.copyfile(logo, os.path.join(dst_dir, os.path.basename(logo)))
|
2018-12-09 16:13:46 +01:00
|
|
|
|
2023-06-05 12:19:19 +02:00
|
|
|
assets_path = os.path.join(src_dir, "assets")
|
|
|
|
if os.path.isdir(assets_path):
|
|
|
|
shutil.copytree(
|
|
|
|
assets_path, os.path.join(dst_dir, os.path.basename(assets_path))
|
|
|
|
)
|
2018-12-09 16:13:46 +01:00
|
|
|
|
2023-06-05 12:19:19 +02:00
|
|
|
copy_bots_data(os.listdir(package_bots_dir))
|
2018-12-09 16:13:46 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-12-09 16:13:46 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
generate_zulip_bots_static_files()
|