mirror of
https://github.com/erkin/ponysay.git
synced 2025-01-31 18:36:43 +01:00
accepts ucs in -f and -q
This commit is contained in:
parent
adbf4659be
commit
f76bef8fac
2 changed files with 74 additions and 15 deletions
5
configure
vendored
5
configure
vendored
|
@ -17,7 +17,7 @@ oldInstalledDirs='lib/ponysay share/ponies share/ttyponies bin/ponysaylist.pl'
|
||||||
oldCompiledFiles='truncater ponysaytruncater ponysay.py.install'
|
oldCompiledFiles='truncater ponysaytruncater ponysay.py.install'
|
||||||
oldCompiledDirs=''
|
oldCompiledDirs=''
|
||||||
|
|
||||||
installedFiles='bin/ponysay bin/ponythink doc/ponysay.pdf share/info/ponysay.info.gz share/info/ponythink.info.gz'
|
installedFiles='bin/ponysay bin/ponythink doc/ponysay.pdf share/info/ponysay.info.gz share/info/ponythink.info.gz share/ponysay/ucsmap'
|
||||||
installedDirs='share/ponysay lib/ponysay'
|
installedDirs='share/ponysay lib/ponysay'
|
||||||
compiledFiles='ponysay.info ponysay.info.gz ponysay.install ponysay.install~'
|
compiledFiles='ponysay.info ponysay.info.gz ponysay.install ponysay.install~'
|
||||||
compiledDirs='quotes'
|
compiledDirs='quotes'
|
||||||
|
@ -231,6 +231,9 @@ function makeMakefile()
|
||||||
echo -en '\t' ; echo 'install "ponysay.install" "$(INSTALLDIR)/bin/ponysay"'
|
echo -en '\t' ; echo 'install "ponysay.install" "$(INSTALLDIR)/bin/ponysay"'
|
||||||
echo -en '\t' ; echo 'ln -sf "ponysay" "$(INSTALLDIR)/bin/ponythink"'
|
echo -en '\t' ; echo 'ln -sf "ponysay" "$(INSTALLDIR)/bin/ponythink"'
|
||||||
echo
|
echo
|
||||||
|
echo -en '\t' ; echo 'mkdir -p "$(INSTALLDIR)/share/ponysay/"'
|
||||||
|
echo -en '\t' ; echo 'install "share/ucsmap" "$(INSTALLDIR)/share/ponysay/ucsmap"'
|
||||||
|
echo
|
||||||
echo -en '\t' ; echo 'mkdir -p "$(INSTALLDIR)/share/licenses/ponysay/"'
|
echo -en '\t' ; echo 'mkdir -p "$(INSTALLDIR)/share/licenses/ponysay/"'
|
||||||
for file in $licenseFiles; do
|
for file in $licenseFiles; do
|
||||||
echo -en '\t'
|
echo -en '\t'
|
||||||
|
|
78
ponysay
78
ponysay
|
@ -56,6 +56,20 @@ class Ponysay():
|
||||||
elif args.opts['-L'] is not None: self.linklist()
|
elif args.opts['-L'] is not None: self.linklist()
|
||||||
elif args.opts['-B'] is not None: self.balloonlist()
|
elif args.opts['-B'] is not None: self.balloonlist()
|
||||||
else:
|
else:
|
||||||
|
self.__bestpony(args)
|
||||||
|
self.__ucsremap(args)
|
||||||
|
if args.opts['-q'] is not None: self.quote(args)
|
||||||
|
else: self.print_pony(args)
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
## Auxiliary methods
|
||||||
|
##
|
||||||
|
|
||||||
|
'''
|
||||||
|
Use best.pony if nothing else is set
|
||||||
|
'''
|
||||||
|
def __bestpony(self, args):
|
||||||
if (args.opts['-f'] is None) or (args.opts['-q'] is None) or (len(args.opts['-q']) == 0):
|
if (args.opts['-f'] is None) or (args.opts['-q'] is None) or (len(args.opts['-q']) == 0):
|
||||||
for ponydir in ponydirs:
|
for ponydir in ponydirs:
|
||||||
if os.path.isfile(ponydir + 'best.pony') or os.path.islink(ponydir + 'best.pony'):
|
if os.path.isfile(ponydir + 'best.pony') or os.path.islink(ponydir + 'best.pony'):
|
||||||
|
@ -64,13 +78,45 @@ class Ponysay():
|
||||||
else: args.opts['-f'] = [pony]
|
else: args.opts['-f'] = [pony]
|
||||||
break
|
break
|
||||||
|
|
||||||
if args.opts['-q'] is not None: self.quote(args)
|
|
||||||
else: self.print_pony(args)
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
Apply pony name remapping to args according to UCS settings
|
||||||
|
'''
|
||||||
|
def __ucsremap(self, args):
|
||||||
|
env_ucs = os.environ['PONYSAY_UCS_ME'] if 'PONYSAY_UCS_ME' in os.environ else ''
|
||||||
|
ucs_conf = 0
|
||||||
|
if env_ucs in ('yes', 'y', '1'): ucs_conf = 1
|
||||||
|
elif env_ucs in ('harder', 'h', '2'): ucs_conf = 2
|
||||||
|
|
||||||
|
if ucs_conf == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
maplines = []
|
||||||
|
for sharedir in sharedirs:
|
||||||
|
if os.path.isfile(sharedir + 'ucsmap'):
|
||||||
|
mapfile = None
|
||||||
|
try:
|
||||||
|
mapfile = open(sharedir + 'ucsmap', 'r')
|
||||||
|
maplines += [line.replace('\n', '') for line in mapfile.readlines()]
|
||||||
|
finally:
|
||||||
|
if mapfile is not None:
|
||||||
|
mapfile.close()
|
||||||
|
|
||||||
|
map = {}
|
||||||
|
stripset = ' \t' # must be string, wtf! and way doesn't python's doc say so
|
||||||
|
for line in maplines:
|
||||||
|
if (len(line) > 0) and not (line[0] == '#'):
|
||||||
|
s = line.index('→')
|
||||||
|
ucs = line[:s] .strip(stripset)
|
||||||
|
ascii = line[s + 1:].strip(stripset)
|
||||||
|
map[ucs] = ascii
|
||||||
|
|
||||||
|
for flag in ('-f', '-q'):
|
||||||
|
if args.opts[flag] is not None:
|
||||||
|
for i in range(0, len(args.opts[flag])):
|
||||||
|
if args.opts[flag][i] in map:
|
||||||
|
args.opts[flag][i] = map[args.opts[flag][i]]
|
||||||
|
|
||||||
##
|
|
||||||
## Auxiliary methods
|
|
||||||
##
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Returns one file with full path, names is filter for names, also accepts filepaths
|
Returns one file with full path, names is filter for names, also accepts filepaths
|
||||||
|
@ -1402,13 +1448,13 @@ class ColourStack():
|
||||||
'''
|
'''
|
||||||
The user's home directory
|
The user's home directory
|
||||||
'''
|
'''
|
||||||
HOME = os.environ['HOME']
|
HOME = os.environ['HOME'] if 'HOME' in os.environ else os.path.expanduser('~')
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Whether the program is execute in Linux VT (TTY)
|
Whether the program is execute in Linux VT (TTY)
|
||||||
'''
|
'''
|
||||||
linuxvt = os.environ['TERM'] == 'linux'
|
linuxvt = ('TERM' in os.environ) and (os.environ['TERM'] == 'linux')
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
@ -1434,13 +1480,23 @@ Whether stderr is piped
|
||||||
pipelineerr = not sys.stderr.isatty()
|
pipelineerr = not sys.stderr.isatty()
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
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)
|
The directories where pony files are stored, ttyponies/ are used if the terminal is Linux VT (also known as TTY)
|
||||||
'''
|
'''
|
||||||
ponydirs = []
|
ponydirs = []
|
||||||
_kms = Ponysay.isUsingKMS()
|
_kms = Ponysay.isUsingKMS()
|
||||||
if linuxvt and not _kms: _ponydirs = [HOME + '/.local/share/ponysay/ttyponies/', INSTALLDIR + '/share/ponysay/ttyponies/']
|
if linuxvt and not _kms: _ponydirs = [d + 'ttyponies/' for d in sharedirs]
|
||||||
else: _ponydirs = [HOME + '/.local/share/ponysay/ponies/', INSTALLDIR + '/share/ponysay/ponies/' ]
|
else: _ponydirs = [d + 'ponies/' for d in sharedirs]
|
||||||
for ponydir in _ponydirs:
|
for ponydir in _ponydirs:
|
||||||
if os.path.isdir(ponydir):
|
if os.path.isdir(ponydir):
|
||||||
ponydirs.append(ponydir)
|
ponydirs.append(ponydir)
|
||||||
|
@ -1450,7 +1506,7 @@ for ponydir in _ponydirs:
|
||||||
The directories where quotes files are stored
|
The directories where quotes files are stored
|
||||||
'''
|
'''
|
||||||
quotedirs = []
|
quotedirs = []
|
||||||
_quotedirs = [HOME + '/.local/share/ponysay/quotes/', INSTALLDIR + '/share/ponysay/quotes/']
|
_quotedirs = [d + 'quotes/' for d in sharedirs]
|
||||||
for quotedir in _quotedirs:
|
for quotedir in _quotedirs:
|
||||||
if os.path.isdir(quotedir):
|
if os.path.isdir(quotedir):
|
||||||
quotedirs.append(quotedir)
|
quotedirs.append(quotedir)
|
||||||
|
@ -1460,7 +1516,7 @@ for quotedir in _quotedirs:
|
||||||
The directories where balloon style files are stored
|
The directories where balloon style files are stored
|
||||||
'''
|
'''
|
||||||
balloondirs = []
|
balloondirs = []
|
||||||
_balloondirs = [HOME + '/.local/share/ponysay/balloons/', INSTALLDIR + '/share/ponysay/balloons/']
|
_balloondirs = [d + 'balloons/' for d in sharedirs]
|
||||||
for balloondir in _balloondirs:
|
for balloondir in _balloondirs:
|
||||||
if os.path.isdir(balloondir):
|
if os.path.isdir(balloondir):
|
||||||
balloondirs.append(balloondir)
|
balloondirs.append(balloondir)
|
||||||
|
|
Loading…
Reference in a new issue