History

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

Paul Brossier committed 20 years ago

Commit 1dae4eb1 parent af445db1 file · +24 −3Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/aubio/bench/node.py+24−3
@@ -77,11 +77,24 @@ def act_on_results (action,datapath,respath,filter='d'): · 76 unmodified lines
7777 s = re.split(datapath, i ,maxsplit=1)[1]
7878 action("%s%s%s"%(respath,'/',s))
7979
80+def act_on_files (action,listfiles,listres=None,suffix='.txt',filter='f',sub='\.wav$',**keywords):
81+ """ execute action(respath) an all subdirectories in respath """
82+ if listres and len(listfiles) <= len(listres):
83+ for i in listfiles:
84+ action(i,listres[i],**keywords)
85+ else:
86+ for i in listfiles:
87+ action(i,None,**keywords)
88+
8089 class bench:
8190 """ class to run benchmarks on directories """
8291 def __init__(self,datadir,resdir=None,checkres=False,checkanno=False):
8392 self.datadir = datadir
93+ # path to write results path to
8494 self.resdir = resdir
95+ # list of annotation files
96+ self.reslist = []
97+ # list used to gather results
8598 self.results = []
8699 print "Checking data directory", self.datadir
87100 self.checkdata()
@@ -89,8 +102,17 @@ class bench: · 1 unmodified line
89102 if checkres: self.checkres()
90103
91104 def checkdata(self):
105+ if os.path.isfile(self.datadir):
106+ self.dirlist = os.path.dirname(self.datadir)
107+ print "DBG: found a file"
108+ elif os.path.isdir(self.datadir):
109+ self.dirlist = list_dirs(self.datadir)
110+ print "DBG: found a dir"
111+ # allow dir* matching through find commands?
112+ else:
113+ print "ERR: path not understood"
114+ sys.exit(1)
92115 print "Listing directories in data directory",
93− self.dirlist = list_dirs(self.datadir)
94116 if self.dirlist:
95117 print " (%d elements)" % len(self.dirlist)
96118 else:
@@ -105,7 +127,6 @@ class bench: · 8 unmodified lines
105127 print " (0 elements)"
106128 print "ERR: no sound files were found in", self.datadir
107129 sys.exit(1)
108− #for each in self.sndlist: print each
109130
110131 def checkanno(self):
111132 print "Listing annotations in data directory",
@@ -131,7 +152,7 @@ class bench: · 19 unmodified lines
131152 """ run file_exec on every input file """
132153 self.orig, self.missed, self.merged, self.expc, \
133154 self.bad, self.doubled = 0, 0, 0, 0, 0, 0
134− act_on_data(self.file_exec,self.datadir,self.resdir, \
155+ act_on_files(self.file_exec,self.sndlist,self.reslist, \
135156 suffix='',filter=sndfile_filter)
136157
137158 def dir_eval(self):

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t