mirror of
https://github.com/erkin/ponysay.git
synced 2025-03-03 16:01:27 +01:00
documenting the code
This commit is contained in:
parent
59247bf6e9
commit
0cd697f946
1 changed files with 15 additions and 5 deletions
20
ponysay.py
20
ponysay.py
|
@ -502,20 +502,26 @@ class Ponysay():
|
||||||
Prints a list of all balloons
|
Prints a list of all balloons
|
||||||
'''
|
'''
|
||||||
def balloonlist(self):
|
def balloonlist(self):
|
||||||
|
## Get the size of the terminal
|
||||||
termsize = self.__gettermsize()
|
termsize = self.__gettermsize()
|
||||||
balloonset = set()
|
|
||||||
|
|
||||||
|
## Get all balloons
|
||||||
|
balloonset = set()
|
||||||
for balloondir in balloondirs:
|
for balloondir in balloondirs:
|
||||||
for balloon in os.listdir(balloondir):
|
for balloon in os.listdir(balloondir):
|
||||||
|
## Use .think if running ponythink, otherwise .say
|
||||||
if isthink and (len(balloon) > 6) and (balloon[-6:] == '.think'):
|
if isthink and (len(balloon) > 6) and (balloon[-6:] == '.think'):
|
||||||
balloon = balloon[:-6]
|
balloon = balloon[:-6]
|
||||||
elif (not isthink) and (len(balloon) > 4) and (balloon[-4:] == '.say'):
|
elif (not isthink) and (len(balloon) > 4) and (balloon[-4:] == '.say'):
|
||||||
balloon = balloon[:-4]
|
balloon = balloon[:-4]
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
## Add the balloon if there is none with the same name
|
||||||
if balloon not in balloonset:
|
if balloon not in balloonset:
|
||||||
balloonset.add(balloon)
|
balloonset.add(balloon)
|
||||||
|
|
||||||
|
## Print all balloos, columnised
|
||||||
self.__columnise([(balloon, balloon) for balloon in list(balloonset)])
|
self.__columnise([(balloon, balloon) for balloon in list(balloonset)])
|
||||||
|
|
||||||
|
|
||||||
|
@ -523,29 +529,33 @@ class Ponysay():
|
||||||
Returns one file with full path, names is filter for style names, also accepts filepaths
|
Returns one file with full path, names is filter for style names, also accepts filepaths
|
||||||
'''
|
'''
|
||||||
def __getballoonpath(self, names):
|
def __getballoonpath(self, names):
|
||||||
|
## Stop if their is no choosen balloon
|
||||||
if names is None:
|
if names is None:
|
||||||
return None
|
return None
|
||||||
balloons = {}
|
|
||||||
|
|
||||||
|
## Get all balloons
|
||||||
|
balloons = {}
|
||||||
for balloondir in balloondirs:
|
for balloondir in balloondirs:
|
||||||
for balloon in os.listdir(balloondir):
|
for balloon in os.listdir(balloondir):
|
||||||
balloonfile = balloon
|
balloonfile = balloon
|
||||||
|
## Use .think if running ponythink, otherwise .say
|
||||||
if isthink and (len(balloon) > 6) and (balloon[-6:] == '.think'):
|
if isthink and (len(balloon) > 6) and (balloon[-6:] == '.think'):
|
||||||
balloon = balloon[:-6]
|
balloon = balloon[:-6]
|
||||||
elif (not isthink) and (len(balloon) > 4) and (balloon[-4:] == '.say'):
|
elif (not isthink) and (len(balloon) > 4) and (balloon[-4:] == '.say'):
|
||||||
balloon = balloon[:-4]
|
balloon = balloon[:-4]
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
## Add the balloon if there is none with the same name
|
||||||
if balloon not in balloons:
|
if balloon not in balloons:
|
||||||
balloons[balloon] = balloondir + balloonfile
|
balloons[balloon] = balloondir + balloonfile
|
||||||
|
|
||||||
|
## Support for explicit balloon file names
|
||||||
for name in names:
|
for name in names:
|
||||||
if os.path.exists(name):
|
if os.path.exists(name):
|
||||||
balloons[name] = name
|
balloons[name] = name
|
||||||
|
|
||||||
if names == None:
|
## Select a random balloon of the choosen ones
|
||||||
names = list(balloons.keys())
|
|
||||||
|
|
||||||
balloon = names[random.randrange(0, len(names))]
|
balloon = names[random.randrange(0, len(names))]
|
||||||
if balloon not in balloons:
|
if balloon not in balloons:
|
||||||
sys.stderr.write('That balloon style %s does not exist\n' % (balloon));
|
sys.stderr.write('That balloon style %s does not exist\n' % (balloon));
|
||||||
|
|
Loading…
Add table
Reference in a new issue