Added a proper setup.py

This commit is contained in:
jaseg 2013-07-29 19:29:32 +02:00
parent 1466970c71
commit 13f954f4ec
10 changed files with 149 additions and 75 deletions

4
.gitignore vendored
View file

@ -2,4 +2,8 @@
*.swp
genpngs
genponies
build
dist
setuptest
ponysay.egg-info
__pycache__

View file

@ -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

View file

@ -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

1
TODO Normal file
View file

@ -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

51
ponysay Normal file
View file

@ -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))

47
ponysay.py Executable file → Normal file
View file

@ -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))

1
ponythink Symbolic link
View file

@ -0,0 +1 @@
ponysay

64
setup.py Executable file
View file

@ -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 = [],
)

22
termcenter Executable file
View file

@ -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))