Showing the changes to python (2 of 2 files). Show all
Unified · Split
| @@ -13,7 +13,8 @@ try: · 12 unmodified lines | |||
| 13 | execfile(filename) | 13 | execfile(filename) |
| 14 | filefound = 1 | 14 | filefound = 1 |
| 15 | except IOError: | 15 | except IOError: |
| 16 | print "no user configuration file found in", filename | 16 | #print "no user configuration file found in", filename |
| 17 | pass | ||
| 17 | 18 | ||
| 18 | if filefound == 0: | 19 | if filefound == 0: |
| 19 | import sys | 20 | import sys |
| @@ -14,28 +14,41 @@ def runcommand(cmd,debug=0): · 13 unmodified lines | |||
| 14 | if not status == 0: | 14 | if not status == 0: |
| 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 | return output | 18 | return output |
| 19 | 19 | ||
| 20 | def list_files(datapath,filter='f'): | 20 | def list_files(datapath,filter='f'): |
| 21 | cmd = '%s%s%s%s' % ('find ',datapath,' -type ',filter) | 21 | cmd = '%s%s%s%s' % ('find ',datapath,' -type ',filter) |
| 22 | return runcommand(cmd) | 22 | return runcommand(cmd) |
| 23 | 23 | ||
| 24 | def list_wav_files(datapath,maxdepth=1): | ||
| 25 | return list_files(datapath, filter="f -name '*.wav' -maxdepth %d"%maxdepth) | ||
| 26 | |||
| 27 | def list_dirs(datapath): | ||
| 28 | return list_files(datapath, filter="d") | ||
| 29 | |||
| 24 | def mkdir(path): | 30 | def mkdir(path): |
| 25 | cmd = '%s%s' % ('mkdir -p ',path) | 31 | cmd = '%s%s' % ('mkdir -p ',path) |
| 26 | return runcommand(cmd) | 32 | return runcommand(cmd) |
| 27 | 33 | ||
| 28 | def act_on_data (action,datapath,respath,suffix='.txt',filter='f'): | 34 | def act_on_data (action,datapath,respath,suffix='.txt',filter='f',sub='\.wav$',**keywords): |
| 29 | """ execute action(datafile,resfile) on all files in datapath """ | 35 | """ execute action(datafile,resfile) on all files in datapath """ |
| 30 | dirlist = list_files(datapath,filter=filter) | 36 | dirlist = list_files(datapath,filter=filter) |
| 37 | if dirlist == ['']: dirlist = [] | ||
| 31 | respath_in_datapath = re.split(datapath, respath,maxsplit=1)[1:] | 38 | respath_in_datapath = re.split(datapath, respath,maxsplit=1)[1:] |
| 32 | if(respath_in_datapath and suffix == ''): | 39 | if(respath_in_datapath and suffix == ''): |
| 33 | print 'error: respath in datapath and no suffix used' | 40 | print 'error: respath in datapath and no suffix used' |
| 34 | sys.exit(1) | 41 | #sys.exit(1) |
| 35 | for i in dirlist: | 42 | for i in dirlist: |
| 36 | s = re.split(datapath, i,maxsplit=1)[1] | 43 | j = re.split(datapath, i,maxsplit=1)[1] |
| 37 | j = "%s%s%s%s"%(respath,'/',s,suffix) | 44 | j = re.sub(sub,'',j) |
| 38 | action(i,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) | ||
| 39 | 52 | ||
| 40 | def act_on_results (action,datapath,respath,filter='d'): | 53 | def act_on_results (action,datapath,respath,filter='d'): |
| 41 | """ execute action(respath) an all subdirectories in respath """ | 54 | """ execute action(respath) an all subdirectories in respath """ |