From 58928991147ab8a337fce9be050a1657091dbcfb Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Sat, 13 Mar 2021 17:05:59 +0000 Subject: [PATCH] thread compile_mjml --- scripts/compile_mjml.py | 19 ++++++++++++++----- scripts/enumerate_config.py | 2 ++ scripts/version.sh | 2 ++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/compile_mjml.py b/scripts/compile_mjml.py index 589fd46..f7510bf 100755 --- a/scripts/compile_mjml.py +++ b/scripts/compile_mjml.py @@ -3,6 +3,7 @@ import shutil import os import argparse from pathlib import Path +from threading import Thread parser = argparse.ArgumentParser() parser.add_argument("-o", "--output", help="output directory for .html and .txt files") @@ -15,15 +16,23 @@ def runcmd(cmd): proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) return proc.communicate() +def compile(mjml: Path): + fname = mjml.with_suffix(".html") + runcmd(f"npx mjml {str(mjml)} -o {str(fname)}") + if fname.is_file(): + print(f"Compiled {mjml.name}") local_path = Path("mail") +threads = [] + for mjml in [f for f in local_path.iterdir() if f.is_file() and "mjml" in f.suffix]: - print(f"Compiling {mjml.name}") - fname = mjml.with_suffix(".html") - runcmd(f"npx mjml {str(mjml)} -o {str(fname)}") - if fname.is_file(): - print("Done.") + threads.append(Thread(target=compile, args=(mjml,))) + +for thread in threads: + thread.start() +for thread in threads: + thread.join() html = [f for f in local_path.iterdir() if f.is_file() and "html" in f.suffix] diff --git a/scripts/enumerate_config.py b/scripts/enumerate_config.py index 2cf90b4..b46a46c 100644 --- a/scripts/enumerate_config.py +++ b/scripts/enumerate_config.py @@ -1,3 +1,5 @@ +# Since go doesn't order its json, this script adds ordered lists +# of section/setting names for the settings tab to use. import json, argparse parser = argparse.ArgumentParser() diff --git a/scripts/version.sh b/scripts/version.sh index d9d54c9..f2dd284 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,3 +1,5 @@ #!/bin/bash +# sets version environment variable for goreleaser to use +# scripts/version.sh goreleaser ... JFA_GO_VERSION=$(git describe --exact-match HEAD 2> /dev/null || echo 'vgit') JFA_GO_VERSION="$(echo $JFA_GO_VERSION | sed 's/v//g')" $@