mirror of
https://github.com/zulip/zulip.git
synced 2025-10-25 09:03:57 +00:00
tools: Extract png generation code to separate module.
This commit is contained in:
committed by
Tim Abbott
parent
0b9bea4566
commit
e97c39c587
@@ -35,7 +35,7 @@ from zerver.lib.upload import upload_avatar_image
|
|||||||
from zerver.lib.actions import do_change_avatar_fields
|
from zerver.lib.actions import do_change_avatar_fields
|
||||||
from zerver.lib.integrations import WebhookIntegration, INTEGRATIONS, split_fixture_path
|
from zerver.lib.integrations import WebhookIntegration, INTEGRATIONS, split_fixture_path
|
||||||
from zerver.lib.webhooks.common import get_fixture_http_headers
|
from zerver.lib.webhooks.common import get_fixture_http_headers
|
||||||
from setup.generate_zulip_bots_static_files import create_png_from_svg
|
from setup.generate_integration_bots_avatars import create_png_from_svg
|
||||||
from tools.lib.test_script import prepare_puppeteer_run
|
from tools.lib.test_script import prepare_puppeteer_run
|
||||||
|
|
||||||
def create_integration_bot(integration: WebhookIntegration) -> UserProfile:
|
def create_integration_bot(integration: WebhookIntegration) -> UserProfile:
|
||||||
|
|||||||
22
tools/setup/generate_integration_bots_avatars.py
Normal file
22
tools/setup/generate_integration_bots_avatars.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
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)
|
||||||
|
from scripts.lib.setup_path import setup_path
|
||||||
|
setup_path()
|
||||||
|
|
||||||
|
import cairosvg
|
||||||
|
|
||||||
|
def create_png_from_svg(svg_path: str, destination_dir: Optional[str]=None) -> str:
|
||||||
|
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
|
||||||
@@ -4,8 +4,7 @@ import glob
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
from typing import List
|
||||||
from typing import List, Optional
|
|
||||||
|
|
||||||
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
if ZULIP_PATH not in sys.path:
|
if ZULIP_PATH not in sys.path:
|
||||||
@@ -44,15 +43,5 @@ def generate_zulip_bots_static_files() -> None:
|
|||||||
docs = glob.glob(doc_glob_pattern)
|
docs = glob.glob(doc_glob_pattern)
|
||||||
copyfiles(docs)
|
copyfiles(docs)
|
||||||
|
|
||||||
def create_png_from_svg(svg_path: str, destination_dir: Optional[str]=None) -> str:
|
|
||||||
import cairosvg
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
generate_zulip_bots_static_files()
|
generate_zulip_bots_static_files()
|
||||||
|
|||||||
Reference in New Issue
Block a user