From 76fcf7df54531741f6005210ddbea7c0e81ea01a Mon Sep 17 00:00:00 2001 From: Aiden Gardner <19619206+aiden2480@users.noreply.github.com> Date: Sun, 5 Sep 2021 13:02:16 +1000 Subject: [PATCH] Use regex to sort files to be zipped --- .github/workflows/webstore.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/webstore.py b/.github/workflows/webstore.py index fba6a1a..1203b18 100644 --- a/.github/workflows/webstore.py +++ b/.github/workflows/webstore.py @@ -21,6 +21,7 @@ import io import os +import re import time import json import zipfile @@ -91,18 +92,16 @@ def generate_zipfile() -> io.BytesIO: chrome webstore. The zipped file is stored in memory, in a BytesIO object """ - buffer = io.BytesIO() - zipped = zipfile.ZipFile(buffer, "w") - skipfils = [".git\\", ".github\\", ".gitignore", "README.md"] print("\nGenerating zip file") + zipped = zipfile.ZipFile(buffer := io.BytesIO(), "w") + pattern = re.compile(r".\\(.git\\|.github\\|.gitignore|README.md)") for root, dirs, files in os.walk("."): for name in files: concat = os.path.join(root, name) - # TODO Find a better way to compare - if list(filter(lambda i: concat.startswith(".\\" + i), skipfils)): - continue + if re.match(pattern, concat): + continue # Skip certain files and dirs print("* zipping", concat) zipped.write(concat)