shithub: aubio

Download patch

ref: 1dae4ebe294cb8fea0b5042be7c0291bf16084f7
parent: af445db9b2ca0a315b5f9659e018397735499d18
author: Paul Brossier <piem@altern.org>
date: Thu Dec 22 11:50:37 EST 2005

new act_on_files, avoids using find too much; add some error checking
new act_on_files, avoids using find too much; add some error checking


--- a/python/aubio/bench/node.py
+++ b/python/aubio/bench/node.py
@@ -77,11 +77,24 @@
                 s = re.split(datapath, i ,maxsplit=1)[1]
                 action("%s%s%s"%(respath,'/',s))
 
+def act_on_files (action,listfiles,listres=None,suffix='.txt',filter='f',sub='\.wav$',**keywords):
+        """ execute action(respath) an all subdirectories in respath """
+        if listres and len(listfiles) <= len(listres): 
+		for i in listfiles:
+			action(i,listres[i],**keywords)
+        else:
+		for i in listfiles:
+                	action(i,None,**keywords)
+
 class bench:
 	""" class to run benchmarks on directories """
 	def __init__(self,datadir,resdir=None,checkres=False,checkanno=False):
 		self.datadir = datadir
+		# path to write results path to
 		self.resdir = resdir
+		# list of annotation files
+		self.reslist = []
+		# list used to gather results
 		self.results = []
 		print "Checking data directory", self.datadir
 		self.checkdata()
@@ -89,8 +102,17 @@
 		if checkres: self.checkres()
 	
 	def checkdata(self):
+		if os.path.isfile(self.datadir):
+			self.dirlist = os.path.dirname(self.datadir)
+			print "DBG: found a file"
+		elif os.path.isdir(self.datadir):
+			self.dirlist = list_dirs(self.datadir)
+			print "DBG: found a dir"
+		# allow dir* matching through find commands?
+		else:
+			print "ERR: path not understood"
+			sys.exit(1)
 		print "Listing directories in data directory",
-		self.dirlist = list_dirs(self.datadir)
 		if self.dirlist:
 			print " (%d elements)" % len(self.dirlist)
 		else:
@@ -105,7 +127,6 @@
 			print " (0 elements)"
 			print "ERR: no sound files were found in", self.datadir
 			sys.exit(1)
-		#for each in self.sndlist: print each
 	
 	def checkanno(self):
 		print "Listing annotations in data directory",
@@ -131,7 +152,7 @@
 		""" run file_exec on every input file """
 		self.orig, self.missed, self.merged, self.expc, \
 			self.bad, self.doubled = 0, 0, 0, 0, 0, 0
-		act_on_data(self.file_exec,self.datadir,self.resdir, \
+		act_on_files(self.file_exec,self.sndlist,self.reslist, \
 			suffix='',filter=sndfile_filter)
 	
 	def dir_eval(self):