Merge branch 'master' of gitea.d1v3.de:matthias/dnd-spellcard-generator
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-01-21 05:45:41 +01:00
4 changed files with 82 additions and 5 deletions

41
.drone.yml Normal file
View File

@@ -0,0 +1,41 @@
kind: pipeline
name: default
steps:
- name: docker
image: plugins/docker
settings:
registry: registry.d1v3.de
repo: registry.d1v3.de/dnd-spellcard-builder
username:
from_secret: docker_username
password:
from_secret: docker_password
tags: latest
auto_tag: true
- name: dockerroot
image: plugins/docker
settings:
registry: registry.d1v3.de
repo: registry.d1v3.de/dnd-spellcard-builder-root
dockerfile: Dockerfile.root
username:
from_secret: docker_username
password:
from_secret: docker_password
tags: latest
auto_tag: true
---
kind: secret
name: docker_username
get:
path: kv/data/drone/docker
name: username
---
kind: secret
name: docker_password
get:
path: kv/data/drone/docker
name: token

17
Dockerfile Normal file
View File

@@ -0,0 +1,17 @@
FROM python:3.8-alpine as base
FROM base as builder
RUN mkdir /install
WORKDIR /install
COPY requirements.txt /requirements.txt
RUN pip install --install-option="--prefix=/install" -r /requirements.txt
FROM base
COPY --from=builder /install /usr/local
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /home/appuser
USER appuser
COPY ./ ./
ENTRYPOINT ["python", "./genspells.py"]

14
Dockerfile.root Normal file
View File

@@ -0,0 +1,14 @@
FROM python:3.8-alpine as base
FROM base as builder
RUN mkdir /install
WORKDIR /install
COPY requirements.txt /requirements.txt
RUN pip install --install-option="--prefix=/install" -r /requirements.txt
FROM base
COPY --from=builder /install /usr/local
WORKDIR /home/appuser
COPY ./ ./
ENTRYPOINT ["python", "./genspells.py"]

View File

@@ -23,7 +23,9 @@ def get_template(name):
line_comment_prefix="%#",
trim_blocks=True,
autoescape=False,
loader=jinja2.FileSystemLoader(os.path.abspath("templates/")),
loader=jinja2.FileSystemLoader(
os.path.abspath(os.path.join(os.path.dirname(__file__), "templates/"))
),
)
template = latex_jinja_env.get_template(f"{name}.tex.jinja")
return template
@@ -59,9 +61,11 @@ def main():
spells.update(json.load(jf))
if args.characterclass != "All":
spells = dict(filter(lambda x: args.characterclass in x[1]["classes"], spells.items()))
spells = dict(
filter(lambda x: args.characterclass in x[1]["classes"], spells.items())
)
spells = dict(sorted(spells.items(), key=spell_sorter(args.sort.split(','))))
spells = dict(sorted(spells.items(), key=spell_sorter(args.sort.split(","))))
pages = generate_pages(spells, args.twosided)
filename = args.output if args.output is not None else args.characterclass
write_doc(filename, pages)
@@ -75,8 +79,8 @@ def write_doc(filename, pages):
def generate_pages(spells, twosided=False):
spellpages = []
back = get_template("spellcard_back").render()
for i in range(0, len(spells)+9, 10):
spellpages.append(generate_page(list(spells.items())[i:i+10]))
for i in range(0, len(spells) + 9, 10):
spellpages.append(generate_page(list(spells.items())[i : i + 10]))
if twosided:
spellpages.append(back)
if not twosided:
@@ -109,5 +113,6 @@ def latex_format(text):
text = re.sub(r"([0-9]+)\sm", r"\1~m", text)
return text
if __name__ == "__main__":
main()