From f9663c7b1bb21922efb775136e6c75dda9ba83ce Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 18 Aug 2012 16:43:22 +0200 Subject: forgot to commit python script --- ponysay.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'ponysay.py') diff --git a/ponysay.py b/ponysay.py index e7c671f..f8b7723 100755 --- a/ponysay.py +++ b/ponysay.py @@ -53,6 +53,8 @@ parser = argparse.ArgumentParser(description = 'Ponysay, like cowsay with ponies parser.add_argument('-v', '--version', action = 'version', version = '%s %s' % ("ponysay", VERSION)) parser.add_argument('-l', '--list', action = 'store_true', dest = 'list', help = 'list pony files') parser.add_argument('-L', '--altlist', action = 'store_true', dest = 'linklist', help = 'list pony files with alternatives') +parser.add_argument( '--quoters', action = 'store_true', dest = 'quoters', help = 'list ponies with quotes (visible in -l and -L)') # for shell completions +parser.add_argument( '--onelist', action = 'store_true', dest = 'onelist', help = 'list pony files in one columns') # for shell completions parser.add_argument('-f', '--pony', action = 'append', dest = 'pony', help = 'select a pony (either a file name or a pony name)') parser.add_argument('message', nargs = '?', help = 'message to ponysay') @@ -63,11 +65,13 @@ class ponysay(): def __init__(self, args): if args.list: self.list() elif args.linklist: self.linklist() + elif args.quoters: self.quoters() + elif args.onelist: self.onelist() else: self.print_pony(args) ''' - Returns a set with all ponies that have quotes and is displayable + Returns a set with all ponies that have quotes and are displayable ''' def __quoters(self): quotes = [] @@ -215,6 +219,37 @@ class ponysay(): print("\n"); + ''' + Lists with all ponies that have quotes and are displayable + ''' + def quoters(self): + last = "" + ponies = [] + for pony in self.__quoters(): + ponies.append(pony) + ponies.sort() + for pony in ponies: + if not pony == last: + last = pony + print(pony) + + + ''' + Lists the available ponies one one column without anything bold + ''' + def onelist(self): + last = "" + ponies = [] + for ponydir in ponydirs: # Loop ponydirs + ponies += os.listdir(ponydir) + ponies = [item[:-5] for item in ponies] # remove .pony from file name + ponies.sort() + for pony in ponies: + if not pony == last: + last = pony + print(pony) + + def print_pony(self, args): if args.message == None: msg = sys.stdin.read().strip() -- cgit