00001 """
00002 SLIM version of FLow
00003 """
00004 from subprocess import Popen, PIPE
00005 from os import environ
00006 from os.path import join
00007
00008
00009
00010 def get_par_act( target, source, env ):
00011
00012 par = env['par']
00013 src = source[0].path
00014 type = env.get('type',eval)
00015 get_command = "sfget parform=n %(par)s < %(src)s" %vars()
00016 print get_command
00017 p0 = Popen( get_command, shell=True, stdout=PIPE )
00018 err = p0.wait()
00019 val = p0.stdout.readline()
00020 value = type( val )
00021 print target[0], value
00022 target[0].write( value )
00023 return
00024
00025 def get_par_method( self,source, par, *p,**kw ):
00026 target=self.Value( par )
00027 return self._GetPar( target, source, par=par, *p, **kw )
00028
00029
00030
00031
00032
00033 in_suffix = lambda s: hasattr(s, 'suffix') and s.suffix in ['.rsf','.xsf']
00034 def rush_gen( source, target, env, for_signature ):
00035
00036 rush_action = env[ 'rush_action' ]
00037
00038 if isinstance(rush_action, str):
00039
00040 if [s for s in source if in_suffix( s ) ] and env.get( "stdin", 1 ):
00041 rush_action = "< ${SOURCE} " + rush_action
00042 if target and env.get( "stdout", 1 ):
00043 rush_action = rush_action + " > ${TARGET}"
00044
00045 rush_action = rush_action.split(";")
00046
00047 return rush_action
00048
00049 def rush_emitter( target, source, env):
00050 if target:
00051 datapath = env.get( 'DATAPATH', '.' )
00052 for tgt in target:
00053 if hasattr(tgt,'get_suffix') and tgt.get_suffix() in ['.rsf','.xsf']:
00054 target.append( join( datapath, tgt.name + "@" ) )
00055
00056
00057
00058 return target, source
00059
00060 def rush_method( self, target, source, rush_action, *p,**kw ):
00061 return self._Rush( target, source, rush_action=rush_action, *p, **kw )
00062
00063
00064 def gen_suffix(env, sources):
00065 result = ".rsf"
00066 for source in sources:
00067 if in_suffix( source ) :
00068 result = source.suffix
00069 break
00070
00071 return result
00072
00073
00074 def generate(env):
00075
00076 sfbin = join( environ['RSFROOT'],"bin" )
00077
00078 env.PrependENVPath( 'PATH', sfbin )
00079
00080 GetParBuilder = env.Builder( action=get_par_act,
00081 src_suffix=".rsf",
00082 )
00083
00084 RushBuilder= env.Builder( generator=rush_gen,
00085 suffix=gen_suffix,
00086 src_suffix=".rsf",
00087 emitter=rush_emitter,
00088 )
00089
00090 env["BUILDERS"]['_Rush'] = RushBuilder
00091 env["BUILDERS"]['_GetPar'] = GetParBuilder
00092
00093 env.AddMethod( rush_method, 'Rush')
00094 env.AddMethod( get_par_method,'GetPar')
00095
00096
00097 def exists(env):
00098 return 1