do not sys.exit, add keywords to act_on_data
authorPaul Brossier <piem@altern.org>
Sun, 6 Nov 2005 11:29:14 +0000 (11:29 +0000)
committerPaul Brossier <piem@altern.org>
Sun, 6 Nov 2005 11:29:14 +0000 (11:29 +0000)
do not sys.exit, add keywords to act_on_data

python/aubio/bench/config.py
python/aubio/bench/node.py

index edc580b83b3f62ca8d92cee752e413ea3b5d9a4d..9077764b0bfb6709c4046a966a8c11c602a26ff0 100644 (file)
@@ -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
index cc18bc092c7c4f0033c90a426dfa53d800c78389..ca337b0ac5cfb2ec374f983f1fe940576c0943fb 100644 (file)
@@ -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 """