From cae718f18464bd69d2d3f2e080415e33ce3f0011 Mon Sep 17 00:00:00 2001 From: Sumanth V Rao Date: Sun, 9 Dec 2018 20:43:46 +0530 Subject: [PATCH] provision: Rename generate_zulip_bots_static_files to .py. This should make it possible to call this script as a function without starting up a new Python interpreter. --- docs/development/setup-advanced.md | 2 +- tools/setup/generate_zulip_bots_static_files | 51 ------------------ .../setup/generate_zulip_bots_static_files.py | 53 +++++++++++++++++++ tools/update-prod-static | 2 +- 4 files changed, 55 insertions(+), 53 deletions(-) delete mode 100755 tools/setup/generate_zulip_bots_static_files create mode 100755 tools/setup/generate_zulip_bots_static_files.py diff --git a/docs/development/setup-advanced.md b/docs/development/setup-advanced.md index e60c8b4acd..3b04d7a5f5 100644 --- a/docs/development/setup-advanced.md +++ b/docs/development/setup-advanced.md @@ -356,7 +356,7 @@ sudo chown -R `whoami`:`whoami` /srv/zulip-emoji-cache ./tools/inline-email-css ./tools/setup/generate-custom-icon-webfont ./tools/setup/build_pygments_data -./tools/setup/generate_zulip_bots_static_files +./tools/setup/generate_zulip_bots_static_files.py ./scripts/setup/generate_secrets.py --development if [ $(uname) = "OpenBSD" ]; then sudo cp ./puppet/zulip/files/postgresql/zulip_english.stop /var/postgresql/tsearch_data/ diff --git a/tools/setup/generate_zulip_bots_static_files b/tools/setup/generate_zulip_bots_static_files deleted file mode 100755 index 513b4f39eb..0000000000 --- a/tools/setup/generate_zulip_bots_static_files +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python3 - -import glob -import os -import sys -import shutil - -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 typing import List -from zproject import settings -from zulip_bots.lib import get_bots_directory_path - - -bots_dir = os.path.join(settings.STATIC_ROOT, 'generated/bots') -if os.path.isdir(bots_dir): - # delete old static files, they could be outdated - try: - shutil.rmtree(bots_dir) - except OSError: - print("There was a permission error with Vagrant's NFS file sharing on old versions of " + - "OSX. You can fix this by upgrading to the latest OSX High Sierra, or work around it " + - "by giving read/write permissions to your /zulip folder to everyone.") - sys.exit(1) - - -os.makedirs(bots_dir, exist_ok=True) - -def copyfiles(paths): - # type: (List[str]) -> None - 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) diff --git a/tools/setup/generate_zulip_bots_static_files.py b/tools/setup/generate_zulip_bots_static_files.py new file mode 100755 index 0000000000..9838148b78 --- /dev/null +++ b/tools/setup/generate_zulip_bots_static_files.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +def generate_zulip_bots_static_files() -> None: + import glob + import os + import sys + import shutil + + 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 typing import List + from zproject import settings + from zulip_bots.lib import get_bots_directory_path + + bots_dir = os.path.join(settings.STATIC_ROOT, 'generated/bots') + if os.path.isdir(bots_dir): + # delete old static files, they could be outdated + try: + shutil.rmtree(bots_dir) + except OSError: + print("There was a permission error with Vagrant's NFS file sharing on old versions of " + + "OSX. You can fix this by upgrading to the latest OSX High Sierra, or work around it " + + "by giving read/write permissions to your /zulip folder to everyone.") + sys.exit(1) + + os.makedirs(bots_dir, exist_ok=True) + + def copyfiles(paths): + # type: (List[str]) -> None + 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) + +if __name__ == "__main__": + generate_zulip_bots_static_files() diff --git a/tools/update-prod-static b/tools/update-prod-static index 5c74a6be4d..55d33a980c 100755 --- a/tools/update-prod-static +++ b/tools/update-prod-static @@ -44,7 +44,7 @@ run(['./tools/setup/emoji/build_emoji'], stdout=fp, stderr=fp) run(['./tools/inline-email-css'], stdout=fp, stderr=fp) # Copy over static files from the zulip_bots package -run(['./tools/setup/generate_zulip_bots_static_files'], stdout=fp, stderr=fp) +run(['./tools/setup/generate_zulip_bots_static_files.py'], stdout=fp, stderr=fp) # Generate custom icon webfont run(['./tools/setup/generate-custom-icon-webfont'], stdout=fp, stderr=fp)