diff options
author | Mattias Andrée <maandree@operamail.com> | 2012-08-21 21:29:24 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2012-08-21 21:29:24 +0200 |
commit | 2eb9342b864725d301a3dbc25423da6fcb174c13 (patch) | |
tree | e46cf85b649146701cb18f6682e679be858ec91b /ponysay | |
parent | 3e686cd2e0f2edfd4e22b071b241af2ef49c557f (diff) | |
download | ponysay-2eb9342b864725d301a3dbc25423da6fcb174c13.tar.gz ponysay-2eb9342b864725d301a3dbc25423da6fcb174c13.tar.bz2 ponysay-2eb9342b864725d301a3dbc25423da6fcb174c13.zip |
support for best.pony
Diffstat (limited to 'ponysay')
-rwxr-xr-x | ponysay | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -47,6 +47,7 @@ class Ponysay(): args.help() return + if args.opts['-h'] is not None: args.help() elif args.opts['--quoters'] is not None: self.quoters() elif args.opts['--onelist'] is not None: self.onelist() @@ -54,8 +55,17 @@ class Ponysay(): elif args.opts['-l'] is not None: self.list() elif args.opts['-L'] is not None: self.linklist() elif args.opts['-B'] is not None: self.balloonlist() - elif args.opts['-q'] is not None: self.quote(args) - else: self.print_pony(args) + else: + if (args.opts['-f'] is None) or (args.opts['-q'] is None) or (len(args.opts['-q']) == 0): + for ponydir in ponydirs: + if os.path.isfile(ponydir + 'best.pony') or os.path.islink(ponydir + 'best.pony'): + pony = os.path.realpath(ponydir + 'best.pony') # Canonical path + if args.opts['-q'] is not None: args.opts['-q'] = [pony] + else: args.opts['-f'] = [pony] + break + + if args.opts['-q'] is not None: self.quote(args) + else: self.print_pony(args) ## @@ -480,11 +490,19 @@ class Ponysay(): def quote(self, args): pairs = self.__quotes() if len(args.opts['-q']) > 0: - ponyset = set(args.opts['-q']) + ponyset = {} + for pony in args.opts['-q']: + if (len(pony) > 5) and (pony[-5:] == '.pony'): + ponyname = pony[:-5] + if '/' in ponyname: + ponyname = ponyname[ponyname.rindex('/') + 1:] + ponyset[ponyname] = pony + else: + ponyset[pony] = pony alts = [] for pair in pairs: if pair[0] in ponyset: - alts.append(pair) + alts.append((ponyset[pair[0]], pair[1])) pairs = alts if not len(pairs) == 0: @@ -498,11 +516,11 @@ class Ponysay(): qfile.close() args.opts['-f'] = [pair[0]] elif len(args.opts['-q']) == 0: - sys.stderr.write('All the ponies are mute! Call the Princess!\n') + sys.stderr.write('Princess Celestia! All the ponies are mute!\n') exit(1) else: args.opts['-f'] = [args.opts['-q'][random.randrange(0, len(args.opts['-q']))]] - args.message = 'I got nuthin\' good to say :(' + args.message = 'Zecora! Help me, I am mute!' self.print_pony(args) |