tools: Extract png generation code to separate module.

This commit is contained in:
Puneeth Chaganti 2020-04-20 18:57:36 +05:30 committed by Tim Abbott
parent 0b9bea4566
commit e97c39c587
3 changed files with 24 additions and 13 deletions

View File

@ -35,7 +35,7 @@ from zerver.lib.upload import upload_avatar_image
from zerver.lib.actions import do_change_avatar_fields
from zerver.lib.integrations import WebhookIntegration, INTEGRATIONS, split_fixture_path
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
def create_integration_bot(integration: WebhookIntegration) -> UserProfile:

View 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

View File

@ -4,8 +4,7 @@ import glob
import os
import sys
import shutil
import tempfile
from typing import List, Optional
from typing import List
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if ZULIP_PATH not in sys.path:
@ -44,15 +43,5 @@ def generate_zulip_bots_static_files() -> None:
docs = glob.glob(doc_glob_pattern)
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__":
generate_zulip_bots_static_files()