#!/usr/bin/python2
#
# Playwavs.py
# Play all of the .wav files in the current directory, or the
# directory passed in as the first argument.
# G. Forrest Cook
# April 23, 2002
#
# Could use control-c handling.

import sys
import os
import signal

def handler (signum, frame):
    print "got signal"
    sys.exit (0)

signal.signal (signal.SIGINT, handler)

play_cmd = "/usr/bin/play"

#
# Count the command line arguments, without much validity checking.
#
if len(sys.argv) > 2:
    print 'usage: %s [directory]' % sys.argv[0]
    sys.exit (1)

if len(sys.argv) == 2:
    dirname = sys.argv[1]
else: dirname = "."

print "Playing wav files in", dirname

dirlist = os.listdir (dirname)
dirlist.sort()

for entry in dirlist:
    if (entry[-4:] == '.wav' and not os.path.isdir (dirname+entry)):
        print "Playing: ", entry
	os.system (play_cmd + " " + entry)

sys.exit (0)
