diff options
Diffstat (limited to 'ponysay')
-rwxr-xr-x | ponysay | 98 |
1 files changed, 55 insertions, 43 deletions
@@ -2,17 +2,25 @@ # -*- coding: utf-8 -*- ''' -ponysay.py - Ponysay, a cowsay reimplementation for ponies -Copyright (C) 2012 Erkin Batu Altunbaş +ponysay.py - Ponysay, cowsay reimplementation for ponies +Copyright (C) 2012 Erkin Batu Altunbaş et al. -Authors: Erkin Batu Altunbaş: Project leader, helped write the first implementation +This program is free software. It comes without any warranty, to +the extent permitted by applicable law. You can redistribute it +and/or modify it under the terms of the Do What The Fuck You Want +To Public License, Version 2, as published by Sam Hocevar. See +http://sam.zoy.org/wtfpl/COPYING for more details. + + +Authors of ponysay.py: + + Erkin Batu Altunbaş: Project leader, helped write the first implementation Mattias "maandree" Andrée: Major contributor of both implementions Elis "etu" Axelsson: Major contributor of current implemention and patcher of the first implementation Sven-Hendrik "svenstaro" Haase: Major contributor of the first implementation Jan Alexander "heftig" Steffens: Major contributor of the first implementation Kyah "L-four" Rindlisbacher: Patched the first implementation -License: WTFPL ''' import os @@ -25,14 +33,7 @@ from subprocess import Popen, PIPE ''' The version of ponysay ''' -VERSION = '2.3' - - -''' -The directory where ponysay is installed, this is modified when building with make -''' -INSTALLDIR = '/usr' - +VERSION = 'dev' # this line should not be edited, it is fixed by the build system ''' @@ -106,11 +107,11 @@ class Ponysay(): return maplines = [] - for sharedir in sharedirs: - if os.path.isfile(sharedir + 'ucsmap'): + for ucsmap in ucsmaps: + if os.path.isfile(ucsmap): mapfile = None try: - mapfile = open(sharedir + 'ucsmap', 'r') + mapfile = open(ucsmap, 'r') maplines += [line.replace('\n', '') for line in mapfile.readlines()] finally: if mapfile is not None: @@ -149,11 +150,11 @@ class Ponysay(): return maplines = [] - for sharedir in sharedirs: - if os.path.isfile(sharedir + 'ucsmap'): + for ucsmap in ucsmaps: + if os.path.isfile(ucsmap): mapfile = None try: - mapfile = open(sharedir + 'ucsmap', 'r') + mapfile = open(ucsmap, 'r') maplines += [line.replace('\n', '') for line in mapfile.readlines()] finally: if mapfile is not None: @@ -864,8 +865,8 @@ class ArgParser(): elif dashed: self.files.append(arg) elif arg == '++': tmpdashed = True elif arg == '--': dashed = True - elif (len(arg) > 1) and ((arg[0] == '-') or (arg[0] == '+')): - if (len(arg) > 2) and ((arg[:2] == '--') or (arg[:2] == '++')): + elif (len(arg) > 1) and (arg[0] in ('-', '+')): + if (len(arg) > 2) and (arg[:2] in ('--', '++')): if dontget > 0: dontget -= 1 elif (arg in self.optmap) and (self.optmap[arg][1] == ARGUMENTLESS): @@ -1628,55 +1629,66 @@ usekms = Ponysay.isUsingKMS() ''' -Root share/ directories -''' -sharedirs = [] -_sharedirs = [HOME + '/.local/share/ponysay/', INSTALLDIR + '/share/ponysay/'] -for sharedir in _sharedirs: - if os.path.isdir(sharedir): - sharedirs.append(sharedir) - - -''' The directories where pony files are stored, ttyponies/ are used if the terminal is Linux VT (also known as TTY) and not with KMS ''' +appendset = set() ponydirs = [] -if linuxvt and not usekms: _ponydirs = [d + 'ttyponies/' for d in sharedirs] -else: _ponydirs = [d + 'ponies/' for d in sharedirs] +if linuxvt and not usekms: _ponydirs = [HOME + '/.local/share/ponysay/ttyponies/', '/usr/share/ponysay/ttyponies/'] +else: _ponydirs = [HOME + '/.local/share/ponysay/ponies/', '/usr/share/ponysay/ponies/'] for ponydir in _ponydirs: - if os.path.isdir(ponydir): + if os.path.isdir(ponydir) and (ponydir not in appendset): ponydirs.append(ponydir) + appendset.add(ponydir) ''' The directories where pony files are stored, extrattyponies/ are used if the terminal is Linux VT (also known as TTY) and not with KMS ''' +appendsetset = set() extraponydirs = [] -if linuxvt and not usekms: _extraponydirs = [d + 'extrattyponies/' for d in sharedirs] -else: _extraponydirs = [d + 'extraponies/' for d in sharedirs] +if linuxvt and not usekms: _extraponydirs = [HOME + '/.local/share/ponysay/extrattyponies/', '/usr/share/ponysay/extrattyponies/'] +else: _extraponydirs = [HOME + '/.local/share/ponysay/extraponies/', '/usr/share/ponysay/extraponies/'] for extraponydir in _extraponydirs: - if os.path.isdir(extraponydir): + if os.path.isdir(extraponydir) and (extraponydir not in appendset): extraponydirs.append(extraponydir) + appendset.add(extraponydir) ''' The directories where quotes files are stored ''' +appendset = set() quotedirs = [] -_quotedirs = [d + 'quotes/' for d in sharedirs] +_quotedirs = [HOME + '/.local/share/ponysay/quotes/', '/usr/share/ponysay/quotes/'] for quotedir in _quotedirs: - if os.path.isdir(quotedir): + if os.path.isdir(quotedir) and (quotedir not in appendset): quotedirs.append(quotedir) + appendset.add(quotedir) ''' The directories where balloon style files are stored ''' +appendset = set() balloondirs = [] -_balloondirs = [d + 'balloons/' for d in sharedirs] +_balloondirs = [HOME + '/.local/share/ponysay/balloons/', '/usr/share/ponysay/balloons/'] for balloondir in _balloondirs: - if os.path.isdir(balloondir): + if os.path.isdir(balloondir) and (balloondir not in appendset): balloondirs.append(balloondir) + appendset.add(balloondir) + + +''' +ucsmap files +''' +appendset = set() +ucsmaps = [] +_ucsmaps = [HOME + '/.local/share/ponysay/ucsmap', '/usr/share/ponysay/ucsmap'] +for ucsmap in _ucsmaps: + if os.path.isdir(ucsmap) and (ucsmap not in appendset): + ucsmaps.append(ucsmap) + appendset.add(ucsmap) + usage_saythink = '\033[34;1m(ponysay | ponythink)\033[21;39m' @@ -1713,10 +1725,10 @@ opts.add_argumentless(['++onelist']) opts.add_argumentless(['-h', '--help'], help = 'Print this help message.') opts.add_argumentless(['-v', '--version'], help = 'Print the version of the program.') opts.add_argumentless(['-l', '--list'], help = 'List pony names.') -opts.add_argumentless(['-L', '--altlist'], help = 'List pony names with alternatives.') +opts.add_argumentless(['-L', '--symlist', '--altlist'], help = 'List pony names with alternatives.') opts.add_argumentless(['+l', '++list'], help = 'List non-MLP:FiM pony names.') -opts.add_argumentless(['+L', '++altlist'], help = 'List non-MLP:FiM pony names with alternatives.') -opts.add_argumentless(['-B', '--balloonlist'], help = 'List balloon styles.') +opts.add_argumentless(['+L', '++symlist', '++altlist'], help = 'List non-MLP:FiM pony names with alternatives.') +opts.add_argumentless(['-B', '--bubblelist', '--balloonlist'], help = 'List balloon styles.') opts.add_argumentless(['-c', '--compact'], help = 'Compress messages.') opts.add_argumented( ['-W', '--wrap'], arg = 'COLUMN', help = 'Specify the column when the message should be wrapped.') opts.add_argumented( ['-b', '--bubble', '--balloon'], arg = 'STYLE', help = 'Select a balloon style.') |