Skip to content

Commit

Permalink
Generate color palettes in more formats
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Apr 17, 2023
1 parent 7e8ef80 commit 0ed7db3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/actions/palette/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
27 changes: 16 additions & 11 deletions .github/actions/palette/generate.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
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
from palettelib.format.format_yaml import PaletteFormatYAML
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
Expand All @@ -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):
Expand All @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down

0 comments on commit 0ed7db3

Please sign in to comment.