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 sys
|
|
|
|
import shutil
|
2020-04-09 19:33:49 +02:00
|
|
|
import tempfile
|
|
|
|
from typing import List, Optional
|
|
|
|
|
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
|
|
|
|
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-04-16 07:03:42 +02:00
|
|
|
def generate_zulip_bots_static_files() -> None:
|
2019-07-18 23:20:14 +02: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)
|
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def copyfiles(paths: List[str]) -> None:
|
2018-12-09 16:13:46 +01:00
|
|
|
for src_path in paths:
|
|
|
|
bot_name = os.path.basename(os.path.dirname(src_path))
|
|
|
|
|
|
|
|
bot_dir = os.path.join(bots_dir, bot_name)
|
|
|
|
os.makedirs(bot_dir, exist_ok=True)
|
|
|
|
|
|
|
|
dst_path = os.path.join(bot_dir, os.path.basename(src_path))
|
|
|
|
if not os.path.isfile(dst_path):
|
|
|
|
shutil.copyfile(src_path, dst_path)
|
|
|
|
|
|
|
|
package_bots_dir = get_bots_directory_path()
|
|
|
|
|
|
|
|
logo_glob_pattern = os.path.join(package_bots_dir, '*/logo.*')
|
|
|
|
logos = glob.glob(logo_glob_pattern)
|
|
|
|
copyfiles(logos)
|
|
|
|
|
|
|
|
doc_glob_pattern = os.path.join(package_bots_dir, '*/doc.md')
|
|
|
|
docs = glob.glob(doc_glob_pattern)
|
|
|
|
copyfiles(docs)
|
|
|
|
|
2020-04-09 19:33:49 +02:00
|
|
|
def create_png_from_svg(svg_path: str, destination_dir: Optional[str]=None) -> str:
|
2020-04-20 17:47:44 +02:00
|
|
|
import cairosvg
|
|
|
|
|
2020-04-09 19:33:49 +02:00
|
|
|
png_name = os.path.splitext(os.path.basename(svg_path))[0] + '.png'
|
|
|
|
if destination_dir is None:
|
|
|
|
destination_dir = tempfile.gettempdir()
|
|
|
|
png_path = os.path.join(destination_dir, png_name)
|
|
|
|
cairosvg.svg2png(url=svg_path, write_to=png_path)
|
|
|
|
return png_path
|
|
|
|
|
2018-12-09 16:13:46 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
generate_zulip_bots_static_files()
|