source: python/aubio/bench/node.py @ f985cd6

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since f985cd6 was d45520a, checked in by Paul Brossier <piem@altern.org>, 19 years ago

do not sys.exit, add keywords to act_on_data
do not sys.exit, add keywords to act_on_data

  • Property mode set to 100644
File size: 2.3 KB
Line 
1from config import *
2import commands,sys
3import re
4
5def runcommand(cmd,debug=0):
6        if VERBOSE >= VERBOSE_CMD or debug: print cmd
7        if debug: return 
8        status, output = commands.getstatusoutput(cmd)
9        if status == 0 or VERBOSE >= VERBOSE_OUT:
10                output = output.split('\n')
11        if VERBOSE >= VERBOSE_OUT: 
12                for i in output: 
13                        if i: print i
14        if not status == 0: 
15                print 'error:',status,output
16                print 'command returning error was',cmd
17                #sys.exit(1)
18        return output
19
20def list_files(datapath,filter='f'):
21        cmd = '%s%s%s%s' % ('find ',datapath,' -type ',filter)
22        return runcommand(cmd)
23
24def list_wav_files(datapath,maxdepth=1):
25        return list_files(datapath, filter="f -name '*.wav' -maxdepth %d"%maxdepth)
26
27def list_dirs(datapath):
28        return list_files(datapath, filter="d")
29
30def mkdir(path):
31        cmd = '%s%s' % ('mkdir -p ',path)
32        return runcommand(cmd)
33
34def act_on_data (action,datapath,respath,suffix='.txt',filter='f',sub='\.wav$',**keywords):
35        """ execute action(datafile,resfile) on all files in datapath """
36        dirlist = list_files(datapath,filter=filter)
37        if dirlist == ['']: dirlist = []
38        respath_in_datapath = re.split(datapath, respath,maxsplit=1)[1:]
39        if(respath_in_datapath and suffix == ''): 
40                print 'error: respath in datapath and no suffix used'
41                #sys.exit(1)
42        for i in dirlist:
43                j = re.split(datapath, i,maxsplit=1)[1]
44                j = re.sub(sub,'',j)
45                #j = "%s%s%s"%(respath,j,suffix)
46                j = "%s%s"%(respath,j)
47                if sub != '':
48                        j = re.sub(sub,suffix,j)
49                else:
50                        j = "%s%s" % (j,suffix)
51                action(i,j,**keywords)
52
53def act_on_results (action,datapath,respath,filter='d'):
54        """ execute action(respath) an all subdirectories in respath """
55        dirlist = list_files(datapath,filter='d')
56        respath_in_datapath = re.split(datapath, respath,maxsplit=1)[1:]
57        if(respath_in_datapath and not filter == 'd' and suffix == ''): 
58                print 'warning: respath is in datapath'
59        for i in dirlist:
60                s = re.split(datapath, i ,maxsplit=1)[1]
61                action("%s%s%s"%(respath,'/',s))
Note: See TracBrowser for help on using the repository browser.