Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split groups #34

Merged
merged 13 commits into from
Jan 4, 2024
21 changes: 10 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,36 @@ name: CI
on: [push, pull_request]

env:
TEXLIVE_VERSION: 2021
TEXLIVE_VERSION: 2022
TERM: xterm

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: "3.11"

- name: Setup
run: |
# install current version of inkscape
sudo add-apt-repository -y ppa:inkscape.dev/stable
# sudo add-apt-repository -y ppa:inkscape.dev/stable
sudo apt-get update -q
# curl for download, dbus-x11 fixes a lot of warnings from inkscape that
# cluttered the log
sudo apt-get install inkscape curl dbus-x11 -y
sudo apt-get install inkscape -y
inkscape --version

# install texlive
pip install https://github.com/MaxNoe/texlive-batch-installation/archive/master.tar.gz
pip install https://github.com/MaxNoe/texlive-batch-installation/archive/main.tar.gz
install_texlive -t $TEXLIVE_VERSION --collection='-a' --package-file tex-packages.txt -p $HOME/.local/texlive -v
echo "$HOME/.local/texlive/$TEXLIVE_VERSION/bin/x86_64-linux" >> $GITHUB_PATH
rm -rf ~/.local/share/recently-used.xbel

- name: Build
run: |
dbus-run-session python create_logos.py -n 2
python create_logos.py -n 2

- name: Build Page
# only run on main
Expand Down
16 changes: 16 additions & 0 deletions bundeslaender.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Baden-Württemberg
Bayern
Berlin
Brandenburg
Bremen
Hamburg
Hessen
Mecklenburg-Vorpommern
Niedersachsen
Nordrhein-Westfalen
Rheinland-Pfalz
Saarland
Sachsen
Sachsen-Anhalt
Schleswig-Holstein
Thüringen
103 changes: 57 additions & 46 deletions create_logos.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import shutil
from pathlib import Path
import os
import subprocess as sp
Expand Down Expand Up @@ -50,10 +51,10 @@ def sanitize_name(name):
def call_latex(source_file, out_dir, out_name):
ret = sp.run([
'lualatex',
'--output-directory=' + out_dir,
f'--output-directory={out_dir}',
'--interaction=nonstopmode',
'--halt-on-error',
'--jobname=' + out_name,
f'--jobname={out_name}',
source_file,
], stdout=sp.PIPE, stderr=sp.STDOUT)

Expand All @@ -66,39 +67,40 @@ def call_latex(source_file, out_dir, out_name):


def pdf2png(stem, cwd=None, dpi=600):
name = stem + '.png'
sp.run([
'inkscape',
stem + '.pdf',
f'--export-dpi={dpi}',
'--export-area-page',
'-o', stem + '.png',
'-o', name,
], cwd=cwd, stdout=sp.PIPE, stderr=sp.STDOUT, check=True)
if not os.path.isfile(os.path.join(cwd, stem + '.png')):
if not (cwd / name).is_file():
raise OSError('Call to inkscape failed')


def pdf2svg(stem, cwd=None):
name = stem + '.svg'
sp.run([
'inkscape',
stem + '.pdf',
'--export-text-to-path',
'-o', stem + '.svg',
'-o', name,
], cwd=cwd, stdout=sp.PIPE, stderr=sp.STDOUT, check=True)

if not os.path.isfile(os.path.join(cwd, stem + '.svg')):
if not (cwd / name).is_file():
raise OSError('Call to inkscape failed')


def text_to_path(stem, cwd=None):
name = stem + '.pdf'
sp.run([
'inkscape',
stem + '.pdf',
name,
'--export-text-to-path',
'-o', stem + '.pdf',
], cwd=cwd, stdout=sp.PIPE, stderr=sp.STDOUT, check=True)

if not os.path.isfile(os.path.join(cwd, stem + '.pdf')):
raise OSError('Call to inkscape failed')
'-o', stem + '_ttp.pdf',
], cwd=cwd, check=True) #, stdout=sp.PIPE, stderr=sp.STDOUT, check=True)
shutil.move(cwd / (stem + '_ttp.pdf'), cwd / name)


def create_all_formats(source_file, filename, groupdir, dpi=600):
Expand All @@ -108,39 +110,39 @@ def create_all_formats(source_file, filename, groupdir, dpi=600):
pdf2svg(filename, cwd=groupdir)


def build_logo(regionalgruppe, filename, groupdir):
def build_logo(group, filename, groupdir):
'''
Create the logos for a regionalgroup by running
Create the logos for a group by running
lualatex on a temporary file and then converting the
resulting pdf to svg, png and pdf with text converted to path using inkscape.
'''
with tempfile.NamedTemporaryFile(mode='w') as f:
f.write(head_logo)

if len(regionalgruppe) < MAX_LENGTH:
f.write(rf'\regionallogo{{{regionalgruppe.upper()}}}')
if len(group) < MAX_LENGTH:
f.write(rf'\grouplogo{{{group.upper()}}}')
else:
size = 30 * MAX_LENGTH / len(regionalgruppe)
f.write(rf'\regionallogo[{size:.1f}]{{{regionalgruppe.upper()}}}')
size = 30 * MAX_LENGTH / len(group)
f.write(rf'\grouplogo[{size:.1f}]{{{group.upper()}}}')

f.write(foot)
f.flush()
create_all_formats(f.name, filename, groupdir)


def build_banner(regionalgruppe, filename, groupdir, padding=False):
def build_banner(group, filename, groupdir, padding=False):
'''
Create the logos for a regionalgroup by running
Create the logos for a group by running
lualatex on a temporary file and then converting the
resulting pdf to svg, png and pdf with text converted to path using inkscape.
'''
with tempfile.NamedTemporaryFile(mode='w') as f:
f.write(head_banner)

p = '*' if padding else ''
size = min(30, 30 * MAX_LENGTH / len(regionalgruppe))
size = min(30, 30 * MAX_LENGTH / len(group))

f.write(rf'\regionalbanner{p}[{size:.1f}]{{{regionalgruppe}}}{{{regionalgruppe.upper()}}}')
f.write(rf'\groupbanner{p}[{size:.1f}]{{{group}}}{{{group.upper()}}}')

f.write(foot)
f.flush()
Expand All @@ -149,37 +151,46 @@ def build_banner(regionalgruppe, filename, groupdir, padding=False):
create_all_formats(f.name, filename, groupdir, dpi=dpi)


def build_all(regionalgruppe):
safe_name = sanitize_name(regionalgruppe)
def build_all(group, outdir_category):
safe_name = sanitize_name(group)

groupdir = os.path.join(OUTDIR, 's4f_logos_' + safe_name)
os.makedirs(groupdir, exist_ok=True)
groupdir = outdir_category / ('s4f_logos_' + safe_name)
groupdir.mkdir(exist_ok=True)

build_logo(regionalgruppe, 's4f_logo_' + safe_name, groupdir)
build_banner(regionalgruppe, 's4f_banner_' + safe_name, groupdir)
build_banner(regionalgruppe, 's4f_banner_padding_' + safe_name, groupdir, padding=True)
build_logo(group, 's4f_logo_' + safe_name, groupdir)
build_banner(group, 's4f_banner_' + safe_name, groupdir)
build_banner(group, 's4f_banner_padding_' + safe_name, groupdir, padding=True)

zip_name = f's4f_logos_{safe_name}.zip'
sp.run(['zip', '-FSr', zip_name, os.path.basename(groupdir)], check=True, stdout=sp.PIPE, stderr=sp.STDOUT, cwd=OUTDIR)
sp.run(['zip', '-FSr', zip_name, os.path.basename(groupdir)], check=True, stdout=sp.PIPE, stderr=sp.STDOUT, cwd=outdir_category)

return regionalgruppe
return group


if __name__ == '__main__':
args = parser.parse_args()

with open('regionalgruppen.txt') as f:
regionalgruppen = [l.strip() for l in f]

os.makedirs(OUTDIR, exist_ok=True)

if args.n_parallel == 1:
for regionalgruppe in regionalgruppen:
print('Building', regionalgruppe)
build_all(regionalgruppe)
print('Done')
else:
with ThreadPoolExecutor(args.n_parallel) as pool:
jobs = [pool.submit(build_all, gruppe) for gruppe in regionalgruppen]
for job in as_completed(jobs):
print(job.result())
categories = [
'laender',
'bundeslaender',
'fachgruppen',
'regionalgruppen',
]

for category in categories:
with open(f'{category}.txt') as f:
groups = f.read().splitlines()

outdir = OUTDIR / category
outdir.mkdir(exist_ok=True, parents=True)

if args.n_parallel == 1:
for group in groups:
print('Building', category, group)
build_all(group, outdir)
print('Done')
else:
with ThreadPoolExecutor(args.n_parallel) as pool:
jobs = [pool.submit(build_all, group, outdir) for group in groups]
for job in as_completed(jobs):
print(job.result())
45 changes: 35 additions & 10 deletions create_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,49 @@
OUTDIR = Path('s4f_all_logos').absolute()


categories = {
'laender': "Länder",
'bundeslaender': "Bundesländer",
'fachgruppen': "Fachgruppen",
'regionalgruppen': "Regionalgruppen",
}

edit_url = 'https://github.com/s4f-dortmund/regionalgruppen_logos/edit/main'



if __name__ == "__main__":
with open('regionalgruppen.txt') as f:
regionalgruppen = [l.strip() for l in f]

groups = {}
for category in categories:
with open(f'{category}.txt') as f:
groups[category] = f.read().splitlines()


template = Path("./template.html").read_text()
outputpath = Path("build")
outputpath.mkdir(exist_ok=True)

shutil.copy2(OUTDIR / "s4f_logos_dortmund/s4f_banner_dortmund.svg", outputpath)

lines = []
shutil.copy2(OUTDIR / "regionalgruppen/s4f_logos_dortmund/s4f_banner_dortmund.svg", outputpath)
group_lines = []
edit_lines = []

for category, subgroups in groups.items():
category_label = categories[category]

edit_lines.append(f' <li><a target="_blank" href="{edit_url}/{category}.txt">')
edit_lines.append(f' {category_label}: <code>{category}.txt</code>')
edit_lines.append(f' </a></li>')

for regionalgruppe in regionalgruppen:
name = sanitize_name(regionalgruppe)
lines.append(f'<li><a href="s4f_logos_{name}.zip">{regionalgruppe}</a></li>')
group_lines.append(f"<h4>{category_label}</h4>")
group_lines.append("<ul>")
for group in subgroups:
name = sanitize_name(group)
group_lines.append(f'<li><a href="s4f_logos_{name}.zip">{group}</a></li>')
group_lines.append("</ul>")

content = "<ul>\n" + "\n".join(lines) + "\n</ul>\n"
groups = "\n".join(group_lines)
editing = "\n".join(edit_lines)

with (outputpath / "index.html").open("w") as f:
f.write(template.replace("{% content %}", content))
f.write(template.replace("{% content %}", groups).replace("{% editing %}", editing))
8 changes: 8 additions & 0 deletions fachgruppen.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Agrar-Ernährung
Bauen-Wohnen-Habitat
Energie
Industrie und Unternehmen
Komm Klima
Mobilität
Rohstoffe
Schule
4 changes: 4 additions & 0 deletions laender.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Deutschland
Österreich
Italia
Switzerland
6 changes: 3 additions & 3 deletions logo.tex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
\nopagecolor
\pagestyle{empty}

\NewDocumentCommand \regionallogo {O{30} m} {%
\NewDocumentCommand \grouplogo {O{30} m} {%
\fontsize{30}{30}\selectfont%
\begin{tikzpicture}%
\fill[fill=white] (0, 0) circle (3.4cm);
Expand Down Expand Up @@ -67,7 +67,7 @@

\newlength\namewidth

\NewDocumentCommand \regionalbanner {s O{30} m m} {{%
\NewDocumentCommand \groupbanner {s O{30} m m} {{%
\fontsize{18}{18}\selectfont\bfseries%
\newcommand\groupname{%
\fontsize{24}{24}\selectfont\bfseries #3%
Expand All @@ -92,7 +92,7 @@
\tikzset{padding/.style={fill=white, rounded corners}}

\node[inner sep=0] (logo) at (1.2, 1.3) {%
\resizebox{2cm}{2cm}{\regionallogo[#2]{#4}}%
\resizebox{2cm}{2cm}{\grouplogo[#2]{#4}}%
};
\node[anchor=west, xshift=0.3em, yshift=0.5ex, text=darkBlue] (s4) at (logo.east) {\sff};
\node[groupname] at (name) {\groupname};
Expand Down
4 changes: 0 additions & 4 deletions regionalgruppen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Hamburg
Hannover
Harz
Heidelberg
Hessen
Innsbruck
Kaiserslautern
Karlsruhe
Expand All @@ -57,7 +56,6 @@ Niederösterreich
Oberösterreich
Oldenburg
Osnabrück
Österreich
Paderborn
Passau
Pforzheim
Expand All @@ -66,12 +64,10 @@ Ravensburg
Regensburg
Reutlingen
Rhein / Ruhr
Rheinland-Pfalz
Rosenheim
Rostock
Saarland
Salzburg
Schleswig-Holstein
Schwerin
Steiermark
Stuttgart
Expand Down
Loading