[Scons-users] Conditional process

Bill Deegan bill at baddogconsulting.com
Sun Jan 25 14:30:11 EST 2015


So some file generated by the first flow has the information to know what
should happen after that?

Sounds like a builder should depend on "geometry.asc" and the scanner or
the emitter can add the required files to the list of sources and targets?

You may also want to look at the wiki as there are some examples of "source
generators" which may more closely match what you are trying to do.
-Bill

On Sun, Jan 25, 2015 at 9:01 AM, William Blevins <wblevins001 at gmail.com>
wrote:

> That's a bit different than the use case I was imagining.  I'm not sure my
> original comment is helpful anymore if you cannot statically determine the
> branching.  I'm honestly not sure how I would handle this case.
>
> Off the top of my head, it might make more sense to use geometry.asc,
> which I assume to be a file generated by an earlier process step and
> containing your conditional parameter, as an input to a custom builder that
> calls flow for the correct program.  This way geometry.asc legitimately
> controls execution order and conditional evaluation.
>
> Maybe this will give you an idea?  Consider reading the User's Guide.
> SCons has a rather rich feature set, so understanding the API better may
> give you some additional insight.
>
> V/R,
> William
>
>
> On Sun, Jan 25, 2015 at 11:48 AM, Sven Lars Tobias Stål <
> smp428 at alumni.ku.dk> wrote:
>
>>  Thank you William,
>> sorry for not giving the larger picture. I’ll take a deeper look into
>> aliases, this could be the way to go!
>>
>>  I use SCons to process geophysic data. The data should be processed by
>> a number of programs from the Madagascar package (rsf). I’m using functions
>> defined by the rsf module to process data and export results. Usually, the
>> programs are run in serial and SCons keeps track of dependencies and keep
>> the processing time down as it checks what data that needs to be
>> reconstructed. (As I believe a more typical application of Scons would be).
>>
>>  However, in this (rare) case a data value must be able to control the
>> process flow, and the value can’t be predicted. Until now I’ve split the
>> flow by running first one SCons flow, then a conditional python script (see
>> below), using the os module to call the programs and create output files,
>> then using the result to a second SConstruct script. This is rather
>> annoying and moreover not proper reproducibility, if someone would like to
>> repeat the process to test my findings.
>>
>>  The total flow should look something like this. (I’m not sure this
>> sketchy syntax makes it any clearer):
>>
>>  from rsf.proj import * #Get Fetch, Flow and Result functions
>>
>>  Fetch('inputData')
>> Flow(outdata,indata,'Program 1')
>> Flow(outdata,indata,’Program 2 | Program 3')
>>
>>  Fetch(‘geometry.asc’) #Read the parameter that defines how many files
>> to stack
>> if value = 2
>> Flow(outdata, every 2’nd file, ‘Program 1 parameter a’) #Stack two files
>> and jump to next
>> if value = 4
>> Flow(outdata, every 4’th file, ‘Program 1 parameter b’) #Stack four files
>> and jump to next
>>
>>  Flow(outdata,in data from conditional loop,'Program 1’) #Flow
>> continues...
>> Result(,data,’plotting program')
>> End()
>>
>>  Best regards
>> Tobbe
>>
>>
>>  On 25 Jan 2015, at 16:54 , William Blevins <wblevins001 at gmail.com>
>> wrote:
>>
>>  Tobbe,
>>
>>  I'm not sure why you would want/need to do this, so there may be a
>> better way to achieve your "end goal" if we knew the "why" question.
>>
>>  Consider creating aliases for target creation sets, and simply call
>> "scons <target_alias>" on the command line.  Keep in mind that SCons will
>> also build all the necessary dependencies, so SCons may build other targets
>> if necessary.
>>
>>  Alias information: http://www.scons.org/doc/HTML/scons-user/ch25.html
>>
>>  V/R,
>> William
>>
>> On Sun, Jan 25, 2015 at 9:48 AM, Sven Lars Tobias Stål <
>> smp428 at alumni.ku.dk> wrote:
>>
>>> 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
>>>
>>> _______________________________________________
>>> Scons-users mailing list
>>> Scons-users at scons.org
>>> https://pairlist4.pair.net/mailman/listinfo/scons-users
>>>
>>
>>  _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org
>> https://pairlist4.pair.net/mailman/listinfo/scons-users
>>
>>
>>
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org
>> https://pairlist4.pair.net/mailman/listinfo/scons-users
>>
>>
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20150125/7f34b20d/attachment-0001.html>


More information about the Scons-users mailing list