aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <s@jaseg.de>2013-07-29 19:29:32 +0200
committerjaseg <s@jaseg.de>2013-07-29 19:56:31 +0200
commit13f954f4ecace0c4888e194c75a26666fa3fc305 (patch)
tree73935ab0012f0e722efee915ecb77af58b930350
parent1466970c712fbd3f8579fdc995acc80e0e115299 (diff)
downloadponysay-13f954f4ecace0c4888e194c75a26666fa3fc305.tar.gz
ponysay-13f954f4ecace0c4888e194c75a26666fa3fc305.tar.bz2
ponysay-13f954f4ecace0c4888e194c75a26666fa3fc305.zip
Added a proper setup.py
-rw-r--r--.gitignore4
-rw-r--r--COPYING2
-rw-r--r--Makefile32
-rw-r--r--TODO1
-rw-r--r--ponysay51
-rwxr-xr-xponysay-qotd (renamed from ponysay-qotd.py)0
-rw-r--r--[-rwxr-xr-x]ponysay.py47
l---------ponythink1
-rwxr-xr-xsetup.py64
-rwxr-xr-xtermcenter22
10 files changed, 149 insertions, 75 deletions
diff --git a/.gitignore b/.gitignore
index 9957bed..684a411 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,8 @@
*.swp
genpngs
genponies
+build
+dist
+setuptest
+ponysay.egg-info
__pycache__
diff --git a/COPYING b/COPYING
index 4a6e30d..33d7e11 100644
--- a/COPYING
+++ b/COPYING
@@ -24,7 +24,7 @@ Jannis
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
- Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+ Copyright (C) 2013 Authors
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
diff --git a/Makefile b/Makefile
index 9575354..69c10e8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,37 +1,11 @@
-PREFIX?=/usr/local
+all: genponies
-install: genponies
- install -m 0755 ponysay.py $(PREFIX)/bin
- ln -s $(PREFIX)/bin/ponysay.py $(PREFIX)/bin/ponysay
- ln -s $(PREFIX)/bin/ponysay.py $(PREFIX)/bin/ponythink
- install -m 0755 -d $(PREFIX)/share/ponysay
- install -m 0755 -t $(PREFIX)/share/ponysay quotes/*
- install -m 0755 -t $(PREFIX)/share/ponysay genponies/*
- install -m 0755 -d $(PREFIX)/share/doc/ponysay
- install -m 0755 -t $(PREFIX)/share/doc/ponysay COPYING
- install -m 0755 -t $(PREFIX)/share/doc/ponysay README.md
- install -m 0644 completion/zsh-completion.sh /usr/share/zsh/site-functions/_ponysay
- install -m 0755 completion/bash-completion.sh /etc/bash_completion.d/ponysay.sh
-
-uninstall:
- rm $(PREFIX)/bin/ponysay
- rm $(PREFIX)/bin/ponythink
- rm $(PREFIX)/bin/ponysay.py
- rm $(PREFIX)/share/ponysay/*
- rmdir $(PREFIX)/share/ponysay
- rm $(PREFIX)/share/doc/ponysay/*
- rmdir $(PREFIX)/share/doc/ponysay
- rm /usr/share/zsh/site-functions/_ponysay
- rm /etc/bash_completion.d/ponysay.sh
-
-reinstall: uninstall install
-
-genpngs:
+genpngs: ponies/*
mkdir genpngs
unpixelterm -d genpngs ponies/*.pony
-genponies:
+genponies: pngs/*
mkdir genponies
pixelterm -d genponies pngs/*.png
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..71619e4
--- /dev/null
+++ b/TODO
@@ -0,0 +1 @@
+ * Move package data into actual package data to make this work on non-standard platforms and out of zip archives and so on. See also: http://peak.telecommunity.com/DevCenter/PythonEggs#resource-management
diff --git a/ponysay b/ponysay
new file mode 100644
index 0000000..65a0339
--- /dev/null
+++ b/ponysay
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+
+import os, sys, random
+from os.path import dirname, realpath, exists
+import ponysay
+import argparse, textwrap
+
+if __name__ == '__main__':
+ termwidth = 80
+ try:
+ termwidth = os.get_terminal_size()[0]
+ except:
+ pass
+
+ parser = argparse.ArgumentParser(description='Cowsay with ponies')
+ parser.add_argument('-p', '--pony', type=str, default='random', help='The name of the pony to be used. Use "-p list" to list all ponies, "-p random" (default) to use a random pony.')
+ parser.add_argument('-q', '--quote', action='store_true', help='Use a random quote of the pony being displayed as text')
+ parser.add_argument('-c', '--center', action='store_true', help='Use a random quote of the pony being displayed as text')
+ parser.add_argument('-C', '--center-text', action='store_true', help='Center the text in the bubble')
+ parser.add_argument('-w', '--width', type=int, default=termwidth, help='Terminal width. Use 0 for unlimited width. Default: autodetect')
+ parser.add_argument('-b', '--balloon', type=str, default='cowsay', help='Balloon style to use. Use "-b list" to list available styles.')
+ parser.add_argument('text', type=str, nargs='*', help='The text to be placed in the speech bubble')
+ args = parser.parse_args()
+
+ think = sys.argv[0].endswith('think')
+ if args.pony == "list":
+ print('\n'.join(sorted(ponysay.list_ponies() if not args.quote else ponysay.list_ponies_with_quotes())))
+ sys.exit()
+ if args.balloon == 'list':
+ print('\n'.join([ s.replace('.think', '') for s in ponysay.balloonstyles.keys() if s.endswith('.think') == think ]))
+ sys.exit()
+ pony = args.pony
+ if pony == "random":
+ pony = random.choice(ponysay.list_ponies() if not args.quote else ponysay.list_ponies_with_quotes())
+ text = ' '.join(args.text) or None
+ if text == '-':
+ text = '\n'.join(sys.stdin.readlines())
+ if args.quote:
+ text = ponysay.random_quote(pony)
+
+ balloonstyle = None
+ if think:
+ balloonstyle = ponysay.balloonstyles[args.balloon+'.think']
+ else:
+ balloonstyle = ponysay.balloonstyles[args.balloon]
+
+ print(ponysay.render_pony(pony, text,
+ balloonstyle=balloonstyle,
+ width=args.width or sys.maxint,
+ center=args.center,
+ centertext=args.center_text))
diff --git a/ponysay-qotd.py b/ponysay-qotd
index 2530d8f..2530d8f 100755
--- a/ponysay-qotd.py
+++ b/ponysay-qotd
diff --git a/ponysay.py b/ponysay.py
index bccd54c..779ad17 100755..100644
--- a/ponysay.py
+++ b/ponysay.py
@@ -19,14 +19,9 @@ balloonstyles= {'cowsay': (((' ', '', '< '), (' ', '', '> ')), ((' /', '|', '\\
'round': ((('╭││', '', '│╰ '), ('╮││', '', '│╯ ')), (('╭││', '│', '││╰'), ('╮││', '│', '││╯')), '─', '─', '╲', '╱'),
'linux-vt': ((('┌││', '', '│└ '), ('┐││', '', '│┘ ')), (('┌││', '│', '││└'), ('┐││', '│', '││┘')), '─', '─', '\\', '/')}
-ponypath = realpath(dirname(__file__)+'/../share/ponysay')
+ponypath=realpath(dirname(__file__)+'/ponies')
if not exists(ponypath):
- ponypath=realpath(dirname(__file__)+'/ponies')
-termwidth = 80
-try:
- termwidth = os.get_terminal_size()[0]
-except:
- pass
+ ponypath=realpath(dirname(__file__)+'/../../ponies')
def list_ponies(markQuotes=False):
quotes = lambda n: ' (quotes)' if markQuotes and exists(ponypath+'/'+n+'.quotes') else ''
@@ -83,41 +78,3 @@ def render_pony(name, text, balloonstyle, width=80, center=False, centertext=Fal
wre = re.compile('((\x1B\[[0-9;]+m)*.){0,%s}' % width)
return ''.join([ indent+wre.search(line).group()+'\n' for line in pony ])
-if __name__ == '__main__':
- parser = argparse.ArgumentParser(description='Cowsay with ponies')
- parser.add_argument('-p', '--pony', type=str, default='random', help='The name of the pony to be used. Use "-p list" to list all ponies, "-p random" (default) to use a random pony.')
- parser.add_argument('-q', '--quote', action='store_true', help='Use a random quote of the pony being displayed as text')
- parser.add_argument('-c', '--center', action='store_true', help='Use a random quote of the pony being displayed as text')
- parser.add_argument('-C', '--center-text', action='store_true', help='Center the text in the bubble')
- parser.add_argument('-w', '--width', type=int, default=termwidth, help='Terminal width. Use 0 for unlimited width. Default: autodetect')
- parser.add_argument('-b', '--balloon', type=str, default='cowsay', help='Balloon style to use. Use "-b list" to list available styles.')
- parser.add_argument('text', type=str, nargs='*', help='The text to be placed in the speech bubble')
- args = parser.parse_args()
-
- think = sys.argv[0].endswith('think')
- if args.pony == "list":
- print('\n'.join(sorted(list_ponies() if not args.quote else list_ponies_with_quotes())))
- sys.exit()
- if args.balloon == 'list':
- print('\n'.join([ s.replace('.think', '') for s in balloonstyles.keys() if s.endswith('.think') == think ]))
- sys.exit()
- pony = args.pony
- if pony == "random":
- pony = random.choice(list_ponies() if not args.quote else list_ponies_with_quotes())
- text = ' '.join(args.text) or None
- if text == '-':
- text = '\n'.join(sys.stdin.readlines())
- if args.quote:
- text = random_quote(pony)
-
- balloonstyle = None
- if think:
- balloonstyle = balloonstyles[args.balloon+'.think']
- else:
- balloonstyle = balloonstyles[args.balloon]
-
- print(render_pony(pony, text,
- balloonstyle=balloonstyle,
- width=args.width or sys.maxint,
- center=args.center,
- centertext=args.center_text))
diff --git a/ponythink b/ponythink
new file mode 120000
index 0000000..31b2aba
--- /dev/null
+++ b/ponythink
@@ -0,0 +1 @@
+ponysay \ No newline at end of file
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..b5c11bd
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+import distutils.core
+from setuptools import setup
+import subprocess
+import os, os.path
+import sys
+
+ver = "1.0"
+
+def read(filename):
+ return open(os.path.join(os.path.dirname(__file__), filename)).read()
+
+def dir_copy(dirname):
+ return (dirname, [dirname+'/'+f for f in os.listdir(dirname)])
+
+
+if sys.version_info < (3,0):
+ print('Oops, only python >= 3.0 supported!')
+ sys.exit()
+
+class MakeCommand(distutils.core.Command):
+ sub_commands = None
+ user_options = []
+ def initialize_options(self):
+ pass
+ def finalize_options(self):
+ pass
+ def run(self):
+ subprocess.call('make')
+
+setup(name = 'ponysay',
+ version = ver,
+ description = 'cowsay with ponies',
+ license = 'WTFPL',
+ author = 'jaseg',
+ author_email = 'ponysay@jaseg.net',
+ url = 'https://github.com/jaseg/ponysay',
+ py_modules = ['ponysay'],
+ data_files = [dir_copy('quotes'),
+ dir_copy('ponies')],
+ scripts = ['ponysay',
+ 'ponythink',
+ 'termcenter',
+ 'ponysay-qotd'],
+ zip_safe = False,
+ classifiers = [
+ 'Development Status :: 5 - Production/Stable',
+ 'Environment :: Console',
+ 'Intended Audience :: Information Technology',
+ 'Intended Audience :: Intended Audience :: End Users/Desktop',
+ 'License :: Freely Distributable',
+ 'License :: Public Domain',
+ 'Natural Language :: English',
+ 'Programming Language :: Python :: 3',
+ 'Topic :: Games/Entertainment',
+ 'Topic :: Internet',
+ 'Topic :: System :: Networking'
+ 'Topic :: Text Processing :: Filters',
+ 'Topic :: Utilities',
+ ],
+ cmdclass = {'build_ext': MakeCommand},
+ long_description = read('README.md'),
+ dependency_links = [],
+)
diff --git a/termcenter b/termcenter
new file mode 100755
index 0000000..54fffa0
--- /dev/null
+++ b/termcenter
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+
+import os,sys,time, itertools
+import argparse
+from subprocess import *
+try:
+ import re2 as re
+except:
+ import re
+
+parser = argparse.ArgumentParser(description='Center stuff on terminals')
+parser.add_argument('string', nargs='*', type=str)
+args = parser.parse_args()
+
+for e in [sys.stdin] + args.string:
+ lines = [e] if isinstance(e, str) else e.readlines()
+ if lines:
+ width = max(map(len, map(lambda s: re.sub(r'\x1B\[[0-9;]+m|\$.*\$', '', s), lines)))
+ pad = int((os.get_terminal_size()[0]- width)/2)
+ for line in lines:
+ print(' '*pad + re.sub(r'\$.*\$|\n', '', line))
+