mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-25 22:07:58 +01:00
split out logic for get selected ponies
Signed-off-by: Mattias Andrée <maandree@operamail.com>
This commit is contained in:
parent
acc543cfe0
commit
f47199bc74
1 changed files with 25 additions and 16 deletions
|
@ -879,21 +879,8 @@ class Ponysay():
|
||||||
@param args:ArgParser Parsed command line arguments
|
@param args:ArgParser Parsed command line arguments
|
||||||
'''
|
'''
|
||||||
## Get the pony
|
## Get the pony
|
||||||
(selection, standard, extra) = ([], [], [])
|
selection = []
|
||||||
for ponydir in self.ponydirs:
|
self.__getSelectedPonies(args, selection)
|
||||||
for pony in os.listdir(ponydir):
|
|
||||||
if endswith(pony, '.pony'):
|
|
||||||
standard.append(ponydir + pony)
|
|
||||||
for ponydir in self.extraponydirs:
|
|
||||||
for pony in os.listdir(ponydir):
|
|
||||||
if endswith(pony, '.pony'):
|
|
||||||
extra.append(ponydir + pony)
|
|
||||||
both = standard + extra
|
|
||||||
for (opt, ponies, quotes) in [('-f', standard, False), ('+f', extra, False), ('-F', both, False), ('-q', standard, True)]:
|
|
||||||
if args.opts[opt] is not None:
|
|
||||||
for pony in args.opts[opt]:
|
|
||||||
selection.append((pony, ponies, quotes))
|
|
||||||
## TODO +q -Q
|
|
||||||
(pony, quote) = self.__getPony(selection, args)
|
(pony, quote) = self.__getPony(selection, args)
|
||||||
|
|
||||||
## Get message and manipulate it
|
## Get message and manipulate it
|
||||||
|
@ -943,11 +930,33 @@ class Ponysay():
|
||||||
if output.endswith('\n'):
|
if output.endswith('\n'):
|
||||||
output = output[:-1]
|
output = output[:-1]
|
||||||
|
|
||||||
|
|
||||||
## Print the output, truncated on the height
|
## Print the output, truncated on the height
|
||||||
self.__printOutput(output)
|
self.__printOutput(output)
|
||||||
|
|
||||||
|
|
||||||
|
def __getSelectedPonies(self, args, selection):
|
||||||
|
'''
|
||||||
|
Get all selected ponies
|
||||||
|
|
||||||
|
@param args:ArgParser Command line options
|
||||||
|
@param selection:list<(name:str, file:str, quotes:bool)> List to fill with tuples of selected pony names, pony files and whether quotes are used
|
||||||
|
'''
|
||||||
|
(standard, extra) = ([], [])
|
||||||
|
for ponydir in self.ponydirs:
|
||||||
|
for pony in os.listdir(ponydir):
|
||||||
|
if endswith(pony, '.pony'):
|
||||||
|
standard.append(ponydir + pony)
|
||||||
|
for ponydir in self.extraponydirs:
|
||||||
|
for pony in os.listdir(ponydir):
|
||||||
|
if endswith(pony, '.pony'):
|
||||||
|
extra.append(ponydir + pony)
|
||||||
|
both = standard + extra
|
||||||
|
for (opt, ponies, quotes) in [('-f', standard, False), ('+f', extra, False), ('-F', both, False), ('-q', standard, True)]: ## TODO +q -Q
|
||||||
|
if args.opts[opt] is not None:
|
||||||
|
for pony in args.opts[opt]:
|
||||||
|
selection.append((pony, ponies, quotes))
|
||||||
|
|
||||||
|
|
||||||
def __getMessage(self, args, quote):
|
def __getMessage(self, args, quote):
|
||||||
'''
|
'''
|
||||||
Get message and remove tailing whitespace from stdin (but not for each line)
|
Get message and remove tailing whitespace from stdin (but not for each line)
|
||||||
|
|
Loading…
Reference in a new issue