mirror of
https://github.com/zulip/zulip.git
synced 2025-10-25 17:14:02 +00:00
tools: Use pre-generated avatar images for documentation bots.
Avatar images for bots used by the tool to generate integration documentation screenshots are pre-generated and committed to the repository. The `generate-integration-docs-screenshot` tool now uses these images, instead of trying to create these avatar images on the fly. Also, deleted the unused `create_png_from_svg` function.
This commit is contained in:
committed by
Tim Abbott
parent
8ef6addc77
commit
18ae06404b
@@ -35,8 +35,8 @@ 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_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
|
||||||
|
from zerver.lib.storage import static_path
|
||||||
|
|
||||||
def create_integration_bot(integration: WebhookIntegration) -> UserProfile:
|
def create_integration_bot(integration: WebhookIntegration) -> UserProfile:
|
||||||
realm = get_realm('zulip')
|
realm = get_realm('zulip')
|
||||||
@@ -57,16 +57,11 @@ def create_integration_bot(integration: WebhookIntegration) -> UserProfile:
|
|||||||
)
|
)
|
||||||
notify_created_bot(bot)
|
notify_created_bot(bot)
|
||||||
|
|
||||||
if integration.logo_url is None:
|
bot_avatar_path = static_path(integration.DEFAULT_BOT_AVATAR_PATH.format(name=integration.name))
|
||||||
return bot
|
if os.path.isfile(bot_avatar_path):
|
||||||
logo_relative_path = integration.logo_url[len(realm.uri) + 1:]
|
with open(bot_avatar_path, "rb") as f:
|
||||||
logo_path = os.path.join(ROOT_DIR, logo_relative_path)
|
upload_avatar_image(f, owner, bot)
|
||||||
if logo_path.endswith(".svg"):
|
do_change_avatar_fields(bot, UserProfile.AVATAR_FROM_USER)
|
||||||
logo_path = create_png_from_svg(logo_path)
|
|
||||||
|
|
||||||
with open(logo_path, "rb") as f:
|
|
||||||
upload_avatar_image(f, owner, bot)
|
|
||||||
do_change_avatar_fields(bot, UserProfile.AVATAR_FROM_USER)
|
|
||||||
|
|
||||||
return bot
|
return bot
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ import django
|
|||||||
|
|
||||||
django.setup()
|
django.setup()
|
||||||
|
|
||||||
import tempfile
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import cairosvg
|
import cairosvg
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
@@ -25,14 +22,6 @@ from zerver.lib.upload import resize_avatar, DEFAULT_AVATAR_SIZE
|
|||||||
from zerver.lib.integrations import Integration, WEBHOOK_INTEGRATIONS
|
from zerver.lib.integrations import Integration, WEBHOOK_INTEGRATIONS
|
||||||
from zerver.lib.storage import static_path
|
from zerver.lib.storage import static_path
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def create_square_image(png: bytes) -> bytes:
|
def create_square_image(png: bytes) -> bytes:
|
||||||
img = Image.open(io.BytesIO(png))
|
img = Image.open(io.BytesIO(png))
|
||||||
if img.height == img.width:
|
if img.height == img.width:
|
||||||
|
|||||||
Reference in New Issue
Block a user