aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2012-08-18 16:55:57 +0200
committerMattias Andrée <maandree@operamail.com>2012-08-18 16:55:57 +0200
commitfd099535cfa5f33ae6c1a55bd8a9dc590931a7b3 (patch)
tree71f23664ab2664cee889430beaa4c10dea28035c
parentf9663c7b1bb21922efb775136e6c75dda9ba83ce (diff)
downloadponysay-fd099535cfa5f33ae6c1a55bd8a9dc590931a7b3.tar.gz
ponysay-fd099535cfa5f33ae6c1a55bd8a9dc590931a7b3.tar.bz2
ponysay-fd099535cfa5f33ae6c1a55bd8a9dc590931a7b3.zip
are there any ponies
-rwxr-xr-xponysay.py26
-rwxr-xr-xponysay.sh28
2 files changed, 19 insertions, 35 deletions
diff --git a/ponysay.py b/ponysay.py
index f8b7723..a04e54d 100755
--- a/ponysay.py
+++ b/ponysay.py
@@ -28,20 +28,27 @@ INSTALLDIR = '/usr'
'''
+The user's home directory
+'''
+HOME = os.environ['HOME']
+
+
+'''
The directories where pony files are stored, ttyponies/ are used if the terminal is Linux VT (also known as TTY)
'''
ponydirs = []
-if os.environ['TERM'] == 'linux': _ponydirs = [INSTALLDIR + '/share/ponysay/ttyponies/', os.environ['HOME'] + '/.local/share/ponysay/ttyponies/']
-else: _ponydirs = [INSTALLDIR + '/share/ponysay/ponies/', os.environ['HOME'] + '/.local/share/ponysay/ponies/' ]
+if os.environ['TERM'] == 'linux': _ponydirs = [INSTALLDIR + '/share/ponysay/ttyponies/', HOME + '/.local/share/ponysay/ttyponies/']
+else: _ponydirs = [INSTALLDIR + '/share/ponysay/ponies/', HOME + '/.local/share/ponysay/ponies/' ]
for ponydir in _ponydirs:
if os.path.isdir(ponydir):
ponydirs.append(ponydir)
+
'''
The directories where quotes files are stored
'''
quotedirs = []
-_quotedirs = [INSTALLDIR + '/share/ponysay/quotes/', os.environ['HOME'] + '/.local/share/ponysay/quotes/']
+_quotedirs = [INSTALLDIR + '/share/ponysay/quotes/', HOME + '/.local/share/ponysay/quotes/']
for quotedir in _quotedirs:
if os.path.isdir(quotedir):
quotedirs.append(quotedir)
@@ -251,20 +258,25 @@ class ponysay():
def print_pony(self, args):
+ ponycount = 0
+ for ponydir in ponydirs:
+ ponycount = len(os.listdir(ponydir))
+ if ponycount == 0:
+ sys.stderr.write('All the ponies are missing! Call the Princess!')
+ exit(1);
+
if args.message == None:
- msg = sys.stdin.read().strip()
+ msg = sys.stdin.read()
else:
msg = args.message
-
if args.pony == None:
ponies = [] # Make array with direct paths to all ponies
for ponydir in ponydirs:
for ponyfile in os.listdir(ponydir):
ponies.append(ponydir + ponyfile)
- pony = ponies[random.randrange(0, len(ponies) - 1)] # Select random pony
-
+ pony = ponies[random.randrange(0, len(ponies) - 1)] # Select random pony
else:
for ponydir in ponydirs:
if os.path.isfile(ponydir + args.pony[0]):
diff --git a/ponysay.sh b/ponysay.sh
index 482dabc..99dbec2 100755
--- a/ponysay.sh
+++ b/ponysay.sh
@@ -60,40 +60,12 @@ fi
-# Marks ponies in lists that have quotes
-qoutelist() {
- bash -c "$("$qlistcmd" $("$quotecmd" --list))"
-}
-
# Pony quotes
ponyquotes() {
[ "$TERM" = "-linux-" ] && TERM="linux"
"$0" ${wrap:+-W$wrap} $("$quotecmd" $@)
}
-# Usage help print function
-usage() {
- version
- cat <<EOF
-
-Usage:
-${0##*/} [options] [message]
-
-If [message] is not provided, reads the message from STDIN.
-
-Options:
- -v Show version and exit.
- -h Show this help and exit.
- -l List pony files.
- -L List pony files with synonyms inside brackets.
- -q Use the pony quote feature.
- -f[name] Select a pony (either a file name or a pony name.)
- -W[column] The screen column where the message should be wrapped.
-
-See man ponysay(6) for more information.
-EOF
-}
-
# Function for printing the ponies and the message
say() {
# Ponies use UTF-8 drawing characters. Prevent a Perl warning.