add missing import + support +L and -L at the same time (= +A), and +l and -l at the same time (= -A) + cleaner action selection fromm options

Signed-off-by: Mattias Andrée <maandree@operamail.com>
This commit is contained in:
Mattias Andrée 2013-04-02 18:48:38 +02:00
parent 3bb4790f15
commit 8db29c00b6
2 changed files with 44 additions and 25 deletions

View file

@ -23,6 +23,7 @@ Authors:
''' '''
from common import * from common import *
from argparser import * from argparser import *
from ponysay import *

View file

@ -231,10 +231,28 @@ class Ponysay():
exit(254) exit(254)
return return
'''
Test arguments written in negation-free disjunctive normal form
@param keys:*str|itr<str> A list of keys and set of keys, any of which must exists, a set of keys only passes if all of those exists
@return :bool Whether the check passed
'''
def test(*keys):
for key in keys:
if isinstance(key, str):
if args.opts[key] is not None:
return True
else:
for skey in key:
if args.opts[skey] is None:
return False
return True
return False
## Emulate termial capabilities ## Emulate termial capabilities
if args.opts['-X'] is not None: (self.linuxvt, self.usekms) = (False, False) if test('-X'): (self.linuxvt, self.usekms) = (False, False)
elif args.opts['-V'] is not None: (self.linuxvt, self.usekms) = (True, False) elif test('-V'): (self.linuxvt, self.usekms) = (True, False)
elif args.opts['-K'] is not None: (self.linuxvt, self.usekms) = (True, True) elif test('-K'): (self.linuxvt, self.usekms) = (True, True)
self.ponydirs = self.vtponydirs if self.linuxvt and not self.usekms else self.xponydirs self.ponydirs = self.vtponydirs if self.linuxvt and not self.usekms else self.xponydirs
self.extraponydirs = self.extravtponydirs if self.linuxvt and not self.usekms else self.extraxponydirs self.extraponydirs = self.extravtponydirs if self.linuxvt and not self.usekms else self.extraxponydirs
@ -248,30 +266,30 @@ class Ponysay():
else: args.opts[sl] = args.opts[ssl] else: args.opts[sl] = args.opts[ssl]
## Save whether standard or extra ponies are used ## Save whether standard or extra ponies are used
self.usingstandard = (args.opts['-f'] is not None) or (args.opts['-F'] is not None) or (args.opts['-q'] is not None) #or (args.opts['-Q'] is not None) self.usingstandard = test('-f', '-F', '-q') # -Q
self.usingextra = (args.opts['+f'] is not None) or (args.opts['-F'] is not None) #or (args.opts['+q'] is not None) or (args.opts['-Q'] is not None) self.usingextra = test('+f', '-F') # +q -Q
## Run modes ## Run modes
if args.opts['-h'] is not None: args.help() if test('-h'): args.help()
elif args.opts['--quoters'] is not None: self.quoters() elif test('-v'): self.version()
elif args.opts['--onelist'] is not None: self.onelist() elif test('--quoters'): self.quoters()
elif args.opts['--Onelist'] is not None: self.fullonelist() elif test('--Onelist', ('--onelist', '++onelist')): self.fullonelist()
elif args.opts['-v'] is not None: self.version() elif test('--onelist'): self.onelist()
elif args.opts['-l'] is not None: self.list() elif test('++onelist'): self.__extraponies(); self.onelist()
elif args.opts['-L'] is not None: self.linklist() elif test('+A', ('-L', '+L')): self.linklist(); self.__extraponies(); self.linklist()
elif args.opts['-B'] is not None: self.balloonlist() elif test('-A', ('-l', '+l')): self.list(); self.__extraponies(); self.list()
elif args.opts['++onelist'] is not None: self.__extraponies(); self.onelist() elif test('-L'): self.linklist()
elif args.opts['+l'] is not None: self.__extraponies(); self.list() elif test('-l'): self.list()
elif args.opts['+L'] is not None: self.__extraponies(); self.linklist() elif test('+L'): self.__extraponies(); self.linklist()
elif args.opts['-A'] is not None: self.list(); self.__extraponies(); self.list() elif test('+l'): self.__extraponies(); self.list()
elif args.opts['+A'] is not None: self.linklist(); self.__extraponies(); self.linklist() elif test('-B'): self.balloonlist()
else: else:
## Colouring features ## Colouring features
if args.opts['--colour-pony'] is not None: if test('--colour-pony'):
self.mode += '\033[' + ';'.join(args.opts['--colour-pony']) + 'm' self.mode += '\033[' + ';'.join(args.opts['--colour-pony']) + 'm'
else: else:
self.mode += '\033[0m' self.mode += '\033[0m'
if args.opts['+c'] is not None: if test('+c'):
if args.opts['--colour-msg'] is None: args.opts['--colour-msg'] = args.opts['+c'] if args.opts['--colour-msg'] is None: args.opts['--colour-msg'] = args.opts['+c']
if args.opts['--colour-link'] is None: args.opts['--colour-link'] = args.opts['+c'] if args.opts['--colour-link'] is None: args.opts['--colour-link'] = args.opts['+c']
if args.opts['--colour-bubble'] is None: args.opts['--colour-bubble'] = args.opts['+c'] if args.opts['--colour-bubble'] is None: args.opts['--colour-bubble'] = args.opts['+c']
@ -280,24 +298,24 @@ class Ponysay():
self.__extraponies(args) self.__extraponies(args)
self.__bestpony(args) self.__bestpony(args)
self.__ucsremap(args) self.__ucsremap(args)
if args.opts['-o'] is not None: if test('-o'):
self.mode += '$/= $$\\= $' self.mode += '$/= $$\\= $'
args.message = '' args.message = ''
self.ponyonly = True self.ponyonly = True
else: else:
self.ponyonly = False self.ponyonly = False
if (args.opts['-i'] is not None) or (args.opts['+i'] is not None): if test('-i', '+i'):
args.message = '' args.message = ''
self.restriction = args.opts['-r'] self.restriction = args.opts['-r']
## The stuff ## The stuff
if args.opts['-q'] is not None: if test('-q'):
warn = (args.opts['-f'] is not None) or (args.opts['+f'] is not None) warn = test('-f', '+f')
if (len(args.opts['-q']) == 1) and ((args.opts['-q'][0] == '-f') or (args.opts['-q'][0] == '+f')): if (len(args.opts['-q']) == 1) and ((args.opts['-q'][0] == '-f') or (args.opts['-q'][0] == '+f')):
warn = True warn = True
if args.opts['-q'][0] == '-f': if args.opts['-q'][0] == '-f':
args.opts['-q'] = args.files args.opts['-q'] = args.files
if args.opts['-f'] is not None: if test('-f'):
args.opts['-q'] += args.opts['-f'] args.opts['-q'] += args.opts['-f']
self.quote(args) self.quote(args)
if warn: if warn: