X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tagger.py;h=870da42f00ec3a7e613d219c60fc6eaa52fce789;hb=0faf2ad20af3b0dda45cbbb74b1f19a6bf8b524d;hp=bda52afdac2e6388fcc7bcd924c0df058c067609;hpb=d1028f9bf3b801a24c130e75de6b035cd03851d0;p=cmccabe-bin diff --git a/tagger.py b/tagger.py index bda52af..870da42 100755 --- a/tagger.py +++ b/tagger.py @@ -65,13 +65,23 @@ def find_companion_script(target): print "ERROR: can't find id3v2_wrapper.sh: " + str(e) sys.exit(1) +# Verifies that a given program is installed. +def verify_program_installed(prog): + try: + proc = subprocess.Popen(prog, stdout=subprocess.PIPE) + line = proc.stdout.readline() + return True + except Exception, e: + print "failed to execute " + str(prog) + return False + # Regular expressions for parsing file names-- # which is, after all, what this program is all about music_file_re = re.compile(".*\.mp3$") music_file_name_re = re.compile(".*/" + "(?P[^/]*)/" + - "(?P[0123456789][0123456789]) - " + + "(?P[0123456789][0123456789]*) - " + "(?P[^/]*)" + "\.[a-zA-Z0123456789]*$") @@ -252,6 +262,11 @@ class MusicFile(object): break # CODE +## Make sure that id3v2 is installed +if not verify_program_installed(["id3v2", "--version"]): + print "You must install the id3v2 program to run this script." + sys.exit(1) + ## Find id3v2_wrapper.sh id3v2_wrapper = find_companion_script('id3v2_wrapper.sh')