From 7c57ddca510f2c4860d8347b80dbf379589bfc72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Andr=C3=A9e?= Date: Sun, 18 Aug 2013 11:17:22 +0200 Subject: [PATCH] python script for generating tty ponies, for setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- dev/dist.sh | 31 +++---------------------------- setup/ttyponies.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 28 deletions(-) create mode 100755 setup/ttyponies.py diff --git a/dev/dist.sh b/dev/dist.sh index 75168334..23046a65 100755 --- a/dev/dist.sh +++ b/dev/dist.sh @@ -1,47 +1,22 @@ #!/usr/bin/env bash -# USAGE: dev/dist.sh ttyponies -# or dev/dist.sh pdfmanual +# USAGE: dev/dist.sh pdfmanual # or dev/dist.sh tag VERSION [OTHER OPTIONS FOR `git tag`] # or dev/dist.sh beigepdf # 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() { inparams="--left - --right - --top - --bottom -" xtermoutparams="--left - --right - --top - --bottom - --balloon n" - linuxoutparams="--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 "remastering ${x}pony: $pony" if [ ! -L "${x}ponies/$pony" ]; then ponytool --import ponysay --file "${x}ponies/$pony" $inparams \ - --export ponysay --file "${x}ponies/$pony" $xtermoutparams \ - --export ponysay --platform linux --file "${x}ttyponies/$pony" $linuxoutparams - git add "${x}ponies/$pony" "${x}ttyponies/$pony" + --export ponysay --file "${x}ponies/$pony" $xtermoutparams + git add "${x}ponies/$pony" else ln -sf "$(readlink "${x}ponies/$pony")" "${x}ttyponies/$pony" git add "${x}ttyponies/$pony" diff --git a/setup/ttyponies.py b/setup/ttyponies.py new file mode 100755 index 00000000..bf7d4efc --- /dev/null +++ b/setup/ttyponies.py @@ -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) +