Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -77,11 +77,24 @@ def act_on_results (action,datapath,respath,filter='d'): · 76 unmodified lines | ||
| 77 | 77 | s = re.split(datapath, i ,maxsplit=1)[1] |
| 78 | 78 | action("%s%s%s"%(respath,'/',s)) |
| 79 | 79 | |
| 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 | + | |
| 80 | 89 | class bench: |
| 81 | 90 | """ class to run benchmarks on directories """ |
| 82 | 91 | def __init__(self,datadir,resdir=None,checkres=False,checkanno=False): |
| 83 | 92 | self.datadir = datadir |
| 93 | + # path to write results path to | |
| 84 | 94 | self.resdir = resdir |
| 95 | + # list of annotation files | |
| 96 | + self.reslist = [] | |
| 97 | + # list used to gather results | |
| 85 | 98 | self.results = [] |
| 86 | 99 | print "Checking data directory", self.datadir |
| 87 | 100 | self.checkdata() |
| @@ -89,8 +102,17 @@ class bench: · 1 unmodified line | ||
| 89 | 102 | if checkres: self.checkres() |
| 90 | 103 | |
| 91 | 104 | 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) | |
| 92 | 115 | print "Listing directories in data directory", |
| 93 | − self.dirlist = list_dirs(self.datadir) | |
| 94 | 116 | if self.dirlist: |
| 95 | 117 | print " (%d elements)" % len(self.dirlist) |
| 96 | 118 | else: |
| @@ -105,7 +127,6 @@ class bench: · 8 unmodified lines | ||
| 105 | 127 | print " (0 elements)" |
| 106 | 128 | print "ERR: no sound files were found in", self.datadir |
| 107 | 129 | sys.exit(1) |
| 108 | − #for each in self.sndlist: print each | |
| 109 | 130 | |
| 110 | 131 | def checkanno(self): |
| 111 | 132 | print "Listing annotations in data directory", |
| @@ -131,7 +152,7 @@ class bench: · 19 unmodified lines | ||
| 131 | 152 | """ run file_exec on every input file """ |
| 132 | 153 | self.orig, self.missed, self.merged, self.expc, \ |
| 133 | 154 | 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, \ | |
| 135 | 156 | suffix='',filter=sndfile_filter) |
| 136 | 157 | |
| 137 | 158 | def dir_eval(self): |