mirror of
https://github.com/erkin/ponysay.git
synced 2025-02-07 13:36:43 +01:00
support quotes in ~/.local/share/ponysay/quotes (new feature)
This commit is contained in:
parent
90fbb875f9
commit
c4f07a8b00
1 changed files with 20 additions and 4 deletions
24
ponysay.py
24
ponysay.py
|
@ -37,6 +37,17 @@ for ponydir in _ponydirs:
|
||||||
if os.path.isdir(ponydir):
|
if os.path.isdir(ponydir):
|
||||||
ponydirs.append(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 = argparse.ArgumentParser(description = 'Ponysay, like cowsay with ponies')
|
||||||
|
|
||||||
parser.add_argument('-v', '--version', action = 'version', version = '%s %s' % ("ponysay", VERSION))
|
parser.add_argument('-v', '--version', action = 'version', version = '%s %s' % ("ponysay", VERSION))
|
||||||
|
@ -61,7 +72,9 @@ class ponysay():
|
||||||
def __quoters(self):
|
def __quoters(self):
|
||||||
quotes = []
|
quotes = []
|
||||||
quoteshash = set()
|
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:
|
for quote in _quotes:
|
||||||
if not quote == '':
|
if not quote == '':
|
||||||
if not quote in quoteshash:
|
if not quote in quoteshash:
|
||||||
|
@ -85,7 +98,9 @@ class ponysay():
|
||||||
Returns a list with all (pony, quote file) pairs
|
Returns a list with all (pony, quote file) pairs
|
||||||
'''
|
'''
|
||||||
def __quotes(self):
|
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 = []
|
rc = []
|
||||||
|
|
||||||
for ponydir in ponydirs:
|
for ponydir in ponydirs:
|
||||||
|
@ -93,8 +108,9 @@ class ponysay():
|
||||||
if not pony[0] == '.':
|
if not pony[0] == '.':
|
||||||
p = pony[:-5] # remove .pony
|
p = pony[:-5] # remove .pony
|
||||||
for quote in quotes:
|
for quote in quotes:
|
||||||
if ('+' + p + '+') in ('+' + quote + '+'):
|
q = quote[quote.rindex('/') + 1:]
|
||||||
rc.append((p, qoute))
|
if ('+' + p + '+') in ('+' + q + '+'):
|
||||||
|
rc.append((p, quote))
|
||||||
|
|
||||||
return rc
|
return rc
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue