some work needed on UCS, otherwise complete

This commit is contained in:
Mattias Andrée 2012-08-22 00:48:18 +02:00
parent 5744c13146
commit 2227c0c5b7

48
ponysay
View file

@ -118,6 +118,49 @@ class Ponysay():
args.opts[flag][i] = map[args.opts[flag][i]] args.opts[flag][i] = map[args.opts[flag][i]]
'''
Apply USC:ise pony names according to UCS settings
'''
def __ucsise(self, ponies, links = None):
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[ascii] = ucs
if ucs_conf == 1:
for pony in ponies:
if pony in map:
ponies.append(map[pony])
else:
for j in range(0, len(ponies)):
if ponies[j] in map:
ponies[j] = map[ponies[j]]
''' '''
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
''' '''
@ -225,6 +268,7 @@ class Ponysay():
for pony in _ponies: for pony in _ponies:
if (len(pony) > 5) and (pony[-5:] == '.pony'): if (len(pony) > 5) and (pony[-5:] == '.pony'):
ponies.append(pony[:-5]) ponies.append(pony[:-5])
self.__ucsise(ponies)
ponies.sort() ponies.sort()
width = len(max(ponies, key = len)) + 2 # Get the longest ponyfilename lenght + 2 spaces width = len(max(ponies, key = len)) + 2 # Get the longest ponyfilename lenght + 2 spaces
@ -256,6 +300,8 @@ class Ponysay():
for pony in _ponies: for pony in _ponies:
if (len(pony) > 5) and (pony[-5:] == '.pony'): if (len(pony) > 5) and (pony[-5:] == '.pony'):
ponies.append(pony[:-5]) ponies.append(pony[:-5])
pseudolinkmap = []
self.__ucsise(ponies, pseudolinkmap) ##TODO
ponies.sort() ponies.sort()
pairs = [(pony, os.path.realpath(ponydir + pony + '.pony') if os.path.islink(ponydir + pony + '.pony') else '') for pony in ponies] pairs = [(pony, os.path.realpath(ponydir + pony + '.pony') if os.path.islink(ponydir + pony + '.pony') else '') for pony in ponies]
@ -320,6 +366,7 @@ class Ponysay():
ponies = [] ponies = []
for pony in self.__quoters(): for pony in self.__quoters():
ponies.append(pony) ponies.append(pony)
self.__ucsise(ponies)
ponies.sort() ponies.sort()
for pony in ponies: for pony in ponies:
if not pony == last: if not pony == last:
@ -339,6 +386,7 @@ class Ponysay():
for pony in _ponies: for pony in _ponies:
if (len(pony) > 5) and (pony[-5:] == '.pony'): if (len(pony) > 5) and (pony[-5:] == '.pony'):
ponies.append(pony[:-5]) ponies.append(pony[:-5])
self.__ucsise(ponies)
ponies.sort() ponies.sort()
for pony in ponies: for pony in ponies:
if not pony == last: if not pony == last: