python script for generating tty ponies, for setup

Signed-off-by: Mattias Andrée <maandree@operamail.com>
This commit is contained in:
Mattias Andrée 2013-08-18 11:17:22 +02:00
parent e2aaeba4ac
commit 7c57ddca51
2 changed files with 36 additions and 28 deletions

View file

@ -1,47 +1,22 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# USAGE: dev/dist.sh ttyponies # USAGE: dev/dist.sh pdfmanual
# or dev/dist.sh pdfmanual
# or dev/dist.sh tag VERSION [OTHER OPTIONS FOR `git tag`] # or dev/dist.sh tag VERSION [OTHER OPTIONS FOR `git tag`]
# or dev/dist.sh beigepdf # or dev/dist.sh beigepdf
# or dev/dist.sh remaster # or dev/dist.sh remaster
ttyponies()
{
defaultinparams="--left - --right - --top - --bottom -"
defaultoutparams="--colourful y --left - --right - --top - --bottom - --balloon n --fullcolour y"
for x in '' 'extra'; do
mkdir -p "${x}ttyponies"
for pony in $(find "${x}ponies/" | grep -v '/\.' | grep '\.pony$' | sed -e "s_^${x}ponies/__"); do
echo "building ${x}ttypony: $pony"
if [ ! -L "${x}ponies/$pony" ]; then
ponytool --import ponysay --file "${x}ponies/$pony" $defaultinparams \
--export ponysay --platform linux --file "${x}ttyponies/$pony" $defaultoutparams
git add "${x}ttyponies/$pony"
else
ln -sf "$(readlink "${x}ponies/$pony")" "${x}ttyponies/$pony"
git add "${x}ttyponies/$pony"
fi
done
done
}
remaster() remaster()
{ {
inparams="--left - --right - --top - --bottom -" inparams="--left - --right - --top - --bottom -"
xtermoutparams="--left - --right - --top - --bottom - --balloon n" xtermoutparams="--left - --right - --top - --bottom - --balloon n"
linuxoutparams="--colourful y --left - --right - --top - --bottom - --balloon n --fullcolour y"
for x in '' 'extra'; do for x in '' 'extra'; do
mkdir -p "${x}ttyponies"
for pony in $(find "${x}ponies/" | grep -v '/\.' | grep '\.pony$' | sed -e "s_^${x}ponies/__"); do for pony in $(find "${x}ponies/" | grep -v '/\.' | grep '\.pony$' | sed -e "s_^${x}ponies/__"); do
echo "remastering ${x}pony: $pony" echo "remastering ${x}pony: $pony"
if [ ! -L "${x}ponies/$pony" ]; then if [ ! -L "${x}ponies/$pony" ]; then
ponytool --import ponysay --file "${x}ponies/$pony" $inparams \ ponytool --import ponysay --file "${x}ponies/$pony" $inparams \
--export ponysay --file "${x}ponies/$pony" $xtermoutparams \ --export ponysay --file "${x}ponies/$pony" $xtermoutparams
--export ponysay --platform linux --file "${x}ttyponies/$pony" $linuxoutparams git add "${x}ponies/$pony"
git add "${x}ponies/$pony" "${x}ttyponies/$pony"
else else
ln -sf "$(readlink "${x}ponies/$pony")" "${x}ttyponies/$pony" ln -sf "$(readlink "${x}ponies/$pony")" "${x}ttyponies/$pony"
git add "${x}ttyponies/$pony" git add "${x}ttyponies/$pony"

33
setup/ttyponies.py Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
from subprocess import Popen
def generateTTY(ponydir, ttyponydir, judge):
if ponydir.endswith('/'): ponydir = ponydir[:-1]
if ttyponydir.endswith('/'): ttyponydir = ttyponydir[:-1]
defaultinparams = '--left - --right - --top - --bottom -'.split(' ')
defaultoutparams = '--colourful y --left - --right - --top - --bottom - --balloon n --fullcolour y'.split(' ')
os.makedirs(ttyponydir, Oo755, True)
for pony in os.listdir(ponydir):
infile = '%s/%s' % ( ponydir, pony)
outfile = '%s/%s' % (ttyponydir, pony)
if (not pony.endswith('.pony')) or (len(pony) <= 5) or not judge(infile):
continue
print('Building %s' % outfile)
if os.path.islink(infile):
os.symlink(os.readlink(infile), outfile)
else:
cmd = ['ponytool', '--import', 'ponysay', '--file', infile] + defaultinparams
cmd += ['--export', 'ponysay', '--platform', 'linux', '--file', outfile] + defaultoutparams
Popen(cmd, stdin = sys.stdin, stdout = sys.stdout, stderr = sys.stderr)
if __name__ == '__main__':
generateTTY(sys.args[1], sys.args[1], lambda _ : True)