From: Paul Brossier Date: Sun, 6 Nov 2005 11:29:14 +0000 (+0000) Subject: do not sys.exit, add keywords to act_on_data X-Git-Tag: bzr2git~816 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d45520a32d3074e270fc31b497e23834fce833ab;p=aubio.git do not sys.exit, add keywords to act_on_data do not sys.exit, add keywords to act_on_data --- diff --git a/python/aubio/bench/config.py b/python/aubio/bench/config.py index edc580b8..9077764b 100644 --- a/python/aubio/bench/config.py +++ b/python/aubio/bench/config.py @@ -13,7 +13,8 @@ try: execfile(filename) filefound = 1 except IOError: - print "no user configuration file found in", filename + #print "no user configuration file found in", filename + pass if filefound == 0: import sys diff --git a/python/aubio/bench/node.py b/python/aubio/bench/node.py index cc18bc09..ca337b0a 100644 --- a/python/aubio/bench/node.py +++ b/python/aubio/bench/node.py @@ -14,28 +14,41 @@ def runcommand(cmd,debug=0): if not status == 0: print 'error:',status,output print 'command returning error was',cmd - sys.exit(1) + #sys.exit(1) return output def list_files(datapath,filter='f'): cmd = '%s%s%s%s' % ('find ',datapath,' -type ',filter) return runcommand(cmd) +def list_wav_files(datapath,maxdepth=1): + return list_files(datapath, filter="f -name '*.wav' -maxdepth %d"%maxdepth) + +def list_dirs(datapath): + return list_files(datapath, filter="d") + def mkdir(path): cmd = '%s%s' % ('mkdir -p ',path) return runcommand(cmd) -def act_on_data (action,datapath,respath,suffix='.txt',filter='f'): +def act_on_data (action,datapath,respath,suffix='.txt',filter='f',sub='\.wav$',**keywords): """ execute action(datafile,resfile) on all files in datapath """ dirlist = list_files(datapath,filter=filter) + if dirlist == ['']: dirlist = [] respath_in_datapath = re.split(datapath, respath,maxsplit=1)[1:] if(respath_in_datapath and suffix == ''): print 'error: respath in datapath and no suffix used' - sys.exit(1) + #sys.exit(1) for i in dirlist: - s = re.split(datapath, i,maxsplit=1)[1] - j = "%s%s%s%s"%(respath,'/',s,suffix) - action(i,j) + j = re.split(datapath, i,maxsplit=1)[1] + j = re.sub(sub,'',j) + #j = "%s%s%s"%(respath,j,suffix) + j = "%s%s"%(respath,j) + if sub != '': + j = re.sub(sub,suffix,j) + else: + j = "%s%s" % (j,suffix) + action(i,j,**keywords) def act_on_results (action,datapath,respath,filter='d'): """ execute action(respath) an all subdirectories in respath """