Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -15,17 +15,24 @@ def runcommand(cmd,debug=0): · 14 unmodified lines | |||
| 15 | print 'error:',status,output | 15 | print 'error:',status,output |
| 16 | print 'command returning error was',cmd | 16 | print 'command returning error was',cmd |
| 17 | #sys.exit(1) | 17 | #sys.exit(1) |
| 18 | if output == '' or output == ['']: return | ||
| 18 | return output | 19 | return output |
| 19 | 20 | ||
| 20 | def list_files(datapath,filter='f'): | 21 | def list_files(datapath,filter='f', maxdepth = -1): |
| 21 | cmd = '%s%s%s%s' % ('find ',datapath,' -type ',filter) | 22 | if maxdepth >= 0: maxstring = " -maxdepth %d " % maxdepth |
| 23 | else: maxstring = "" | ||
| 24 | cmd = '%s' * 5 % ('find ',datapath,maxstring,' -type ',filter) | ||
| 22 | return runcommand(cmd) | 25 | return runcommand(cmd) |
| 23 | 26 | ||
| 24 | def list_wav_files(datapath,maxdepth=1): | 27 | def list_wav_files(datapath,maxdepth = -1): |
| 25 | return list_files(datapath, filter="f -name '*.wav' -maxdepth %d"%maxdepth) | 28 | return list_files(datapath, filter="f -name '*.wav'",maxdepth = maxdepth) |
| 26 | 29 | ||
| 27 | def list_snd_files(datapath,maxdepth=1): | 30 | def list_snd_files(datapath,maxdepth = -1): |
| 28 | return list_files(datapath, filter="f -name '*.wav' -o -name '*.aif' -maxdepth %d"%maxdepth) | 31 | return list_files(datapath, filter="f -name '*.wav' -o -name '*.aif'", |
| 32 | maxdepth = maxdepth) | ||
| 33 | |||
| 34 | def list_res_files(datapath,maxdepth = -1): | ||
| 35 | return list_files(datapath, filter="f -name '*.txt'", maxdepth = maxdepth) | ||
| 29 | 36 | ||
| 30 | def list_dirs(datapath): | 37 | def list_dirs(datapath): |
| 31 | return list_files(datapath, filter="d") | 38 | return list_files(datapath, filter="d") |
| @@ -62,3 +69,35 @@ def act_on_results (action,datapath,respath,filter='d'): · 30 unmodified lines | |||
| 62 | for i in dirlist: | 69 | for i in dirlist: |
| 63 | s = re.split(datapath, i ,maxsplit=1)[1] | 70 | s = re.split(datapath, i ,maxsplit=1)[1] |
| 64 | action("%s%s%s"%(respath,'/',s)) | 71 | action("%s%s%s"%(respath,'/',s)) |
| 72 | |||
| 73 | class task: | ||
| 74 | |||
| 75 | def __init__(self,datadir,resdir): | ||
| 76 | self.datadir = datadir | ||
| 77 | self.resdir = resdir | ||
| 78 | print "Checking data directory", self.datadir | ||
| 79 | self.checkdata() | ||
| 80 | self.checkres() | ||
| 81 | |||
| 82 | def checkdata(self): | ||
| 83 | print "Listing directories in data directory", | ||
| 84 | self.dirlist = list_dirs(self.datadir) | ||
| 85 | print " (%d elements)" % len(self.dirlist) | ||
| 86 | #for each in self.dirlist: print each | ||
| 87 | print "Listing sound files in data directory", | ||
| 88 | self.sndlist = list_snd_files(self.datadir) | ||
| 89 | print " (%d elements)" % len(self.sndlist) | ||
| 90 | #for each in self.sndlist: print each | ||
| 91 | print "Listing annotations in data directory", | ||
| 92 | self.reslist = list_res_files(self.datadir) | ||
| 93 | print " (%d elements)" % len(self.reslist) | ||
| 94 | #for each in self.reslist: print each | ||
| 95 | if not self.reslist or len(self.reslist) < len (self.sndlist): | ||
| 96 | print "ERR: not enough annotations" | ||
| 97 | return -1 | ||
| 98 | else: | ||
| 99 | print "Found enough annotations" | ||
| 100 | |||
| 101 | def checkres(self): | ||
| 102 | print "Creating results directory" | ||
| 103 | act_on_results(mkdir,self.datadir,self.resdir,filter='d') | ||