From c4f07a8b002b218d19b09f5d2ad06c491b275c98 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 18 Aug 2012 16:20:49 +0200 Subject: support quotes in ~/.local/share/ponysay/quotes (new feature) --- ponysay.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'ponysay.py') diff --git a/ponysay.py b/ponysay.py index b7b3eb4..e7c671f 100755 --- a/ponysay.py +++ b/ponysay.py @@ -37,6 +37,17 @@ for ponydir in _ponydirs: if os.path.isdir(ponydir): ponydirs.append(ponydir) +''' +The directories where quotes files are stored +''' +quotedirs = [] +_quotedirs = [INSTALLDIR + '/share/ponysay/quotes/', os.environ['HOME'] + '/.local/share/ponysay/quotes/'] +for quotedir in _quotedirs: + if os.path.isdir(quotedir): + quotedirs.append(quotedir) + + + parser = argparse.ArgumentParser(description = 'Ponysay, like cowsay with ponies') parser.add_argument('-v', '--version', action = 'version', version = '%s %s' % ("ponysay", VERSION)) @@ -61,7 +72,9 @@ class ponysay(): def __quoters(self): quotes = [] quoteshash = set() - _quotes = [item[:item.index('.')] for item in os.listdir(INSTALLDIR + '/share/ponysay/quotes/')] + _quotes = [] + for quotedir in quotedirs: + _quotes += [item[:item.index('.')] for item in os.listdir(INSTALLDIR + '/share/ponysay/quotes/')] for quote in _quotes: if not quote == '': if not quote in quoteshash: @@ -85,7 +98,9 @@ class ponysay(): Returns a list with all (pony, quote file) pairs ''' def __quotes(self): - quotes = os.listdir(INSTALLDIR + '/share/ponysay/quotes/') + quotes = [] + for quotedir in quotedirs: + quotes += [quotedir + item for item in os.listdir(quotedir)] rc = [] for ponydir in ponydirs: @@ -93,8 +108,9 @@ class ponysay(): if not pony[0] == '.': p = pony[:-5] # remove .pony for quote in quotes: - if ('+' + p + '+') in ('+' + quote + '+'): - rc.append((p, qoute)) + q = quote[quote.rindex('/') + 1:] + if ('+' + p + '+') in ('+' + q + '+'): + rc.append((p, quote)) return rc -- cgit 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