From 0ed7db3503132663b3c9d146dc329915dca7d0a4 Mon Sep 17 00:00:00 2001 From: Janne Mareike Koschinski Date: Mon, 17 Apr 2023 23:27:35 +0200 Subject: [PATCH] Generate color palettes in more formats --- .github/actions/palette/Dockerfile | 2 +- .github/actions/palette/generate.py | 27 ++++++++++++++++----------- .github/workflows/main.yml | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/actions/palette/Dockerfile b/.github/actions/palette/Dockerfile index e1c0de8..b08a01f 100644 --- a/.github/actions/palette/Dockerfile +++ b/.github/actions/palette/Dockerfile @@ -1,5 +1,5 @@ FROM alpine:3.17 RUN apk add python3 py3-pip git -RUN python3 -m pip install "palettelib @ git+https://github.com/justjanne/palettelib@main" +RUN python3 -m pip install "palettelib @ git+https://github.com/justjanne/palettelib@f18bab2de55d54c1c560ba2419b49d51fe7367ac" COPY generate.py /generate.py ENTRYPOINT [ "/bin/sh", "-c" ] diff --git a/.github/actions/palette/generate.py b/.github/actions/palette/generate.py index a3dca97..3c0f4db 100644 --- a/.github/actions/palette/generate.py +++ b/.github/actions/palette/generate.py @@ -1,8 +1,9 @@ -import pathlib import os.path import sys from typing import Optional +from palettelib.format.format_aco import PaletteFormatACO +from palettelib.format.format_act import PaletteFormatACT from palettelib.format.format_ase import PaletteFormatASE from palettelib.format.format_gpl import PaletteFormatGPL from palettelib.format.format_kpl import PaletteFormatKPL @@ -10,14 +11,13 @@ from palettelib.io import PaletteFormat, PaletteReader, PaletteWriter from palettelib.palette import Palette -formats: list[PaletteFormat] = [PaletteFormatYAML, PaletteFormatGPL, PaletteFormatASE, PaletteFormatKPL] +formats: list[PaletteFormat] = [ + PaletteFormatYAML, PaletteFormatGPL, PaletteFormatASE, + PaletteFormatKPL, PaletteFormatACT, PaletteFormatACO +] readers: dict[str, PaletteReader] = dict([(format, reader) for format, reader, writer in formats]) writers: dict[str, PaletteWriter] = dict([(format, writer) for format, reader, writer in formats]) -formats = [PaletteFormatYAML, PaletteFormatGPL, PaletteFormatASE, PaletteFormatKPL] -readers = dict([(format, reader) for format, reader, writer in formats]) -writers = dict([(format, writer) for format, reader, writer in formats]) - def read_file(filepath: str) -> Palette: reader: Optional[PaletteReader] = None @@ -39,7 +39,7 @@ def write_file(filepath: str, data: Palette): return writer(filepath, data) -def convert(filepath: str): +def convert(filepath: str, formats: Optional[list[str]]): suffix = "" for format in readers: if filepath.endswith(format): @@ -50,13 +50,18 @@ def convert(filepath: str): for format in writers: if filepath.endswith(format): continue - write_file(os.path.join(dirname, "{0}{1}".format(name, format)), data) + if formats is None or format in formats: + write_file(os.path.join(dirname, "{0}{1}".format(name, format)), data) def main(): - filepaths = sys.argv[1:] - for filepath in filepaths: - convert(filepath) + args = sys.argv[1:] + formats = [] + if len(args) > 1 and args[0].startswith('.'): + formats = args[0].split(',') + args = args[1:] + for filepath in args: + convert(filepath, formats) if __name__ == "__main__": diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index da13251..0517ccb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: - uses: "./.github/actions/palette" with: run: | - python3 /generate.py assets/colors/chaosdorf.palette.yaml + python3 /generate.py .ase,.aco,.gpl,.kpl assets/colors/chaosdorf.palette.yaml - uses: "./.github/actions/inkscape" with: run: |