aboutsummaryrefslogtreecommitdiff
path: root/ponysay.py
diff options
context:
space:
mode:
authorElis Axelsson <elis.axelsson@gmail.com>2012-08-18 16:51:43 +0200
committerElis Axelsson <elis.axelsson@gmail.com>2012-08-18 16:51:43 +0200
commitb46c13a16e175fb63bc253e914fd8b3717e3087a (patch)
tree6b3774ab5933fd2c3c74f62e093926e2ee7dbfe8 /ponysay.py
parent3a65390937e4bfd7cdd859dea24c728ab3b66063 (diff)
parentf9663c7b1bb21922efb775136e6c75dda9ba83ce (diff)
downloadponysay-b46c13a16e175fb63bc253e914fd8b3717e3087a.tar.gz
ponysay-b46c13a16e175fb63bc253e914fd8b3717e3087a.tar.bz2
ponysay-b46c13a16e175fb63bc253e914fd8b3717e3087a.zip
Merge
Diffstat (limited to 'ponysay.py')
-rwxr-xr-xponysay.py64
1 files changed, 59 insertions, 5 deletions
diff --git a/ponysay.py b/ponysay.py
index 1c3bef2..97c3697 100755
--- a/ponysay.py
+++ b/ponysay.py
@@ -39,6 +39,17 @@ for ponydir in _ponydirs:
'''
+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)
+
+
+
+'''
Argument parsing
'''
parser = argparse.ArgumentParser(description = 'Ponysay, like cowsay with ponies')
@@ -46,6 +57,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')
@@ -56,16 +69,20 @@ 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 = []
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:
@@ -84,6 +101,9 @@ class ponysay():
return ponies
+ '''
+ Returns one .pony-file with full path, names is filter for names, also accepts filepaths
+ '''
def __getponypath(self, names = None):
ponies = {}
@@ -101,7 +121,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:
@@ -109,8 +131,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
@@ -215,6 +238,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()