[Scons-users] Conditional process

Sven Lars Tobias Stål smp428 at alumni.ku.dk
Sun Jan 25 09:48:08 EST 2015


Dear all, 

I’m using SCons to build work flows of Madagascar programs (http://www.ahay.org). I’m new to SCons, so sorry for asking basic questions. I’m grateful for any advice.

I’d like to build files differently based on a variable.

I could easily make a Python script, using os or subprocess to achieve the wanted result, but I’d like to use SCons and implement this process in a larger flow. The loop goes through all file names, check a variable from a list, SN, if it’s 2 it adds the following file and skips i+1. If the variable is 4, it adds the there following files and jump to the file after. 

i = 0
while i < len(fL):
	shutil.copy2('t'+ fL[i]+'.rsf', iN + fL[i]+'.rsf') #Select trace header files
	shutil.copy2('t'+ fL[i]+'.rsf@', iN + fL[i]+'.rsf@')
	sL.append(iN + fL[i] + '.rsf')
	if SN[i] == 2:
		os.popen('sfadd < '+ fL[i] + '.rsf ' + fL[i+1] + \
		'.rsf scale=1,1 > ' + iN + fL[i] + '.rsf').read()
		i += 2 #Jump to next file
	elif SN[i] == 4:
		os.popen('sfadd < '+ fL[i] + '.rsf ' + fL[i+1] + '.rsf ' + fL[i+2] + \
		'.rsf ' + fL[i+3] + '.rsf scale=1,1,1,1 > ' + iN + fL[i] + '.rsf').read() 
		i += 4 #Jump to next file
	else:
		print('Unspecified stack %s' % fL[i]) #Or error

Alternatively, how can I call a python script from SCons so that the input is defined (all files in fL list) but the output depends on the conditional result from the script. 

Regards
Tobbe



More information about the Scons-users mailing list