00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 from SCons.Script import Builder, Action, COMMAND_LINE_TARGETS
00040 from SCons.Errors import UserError
00041 from getpass import getpass
00042
00043
00044
00045
00046
00047
00048 def ftp_gen(source, target, env, for_signature):
00049 if not env.get('user'):
00050 raise UserError("FTP: need to specify 'user'")
00051 if not env.get('host'):
00052 raise UserError("FTP: need to specify 'host'")
00053
00054 cmd = ['$FTPCMD']
00055
00056 if env.get('IPV'):
00057 ipv = env['IPV']
00058 if env['IPV'] in [4,6]:
00059 cmd.append('-%(ipv)s' %vars() )
00060
00061 if env.get('NETRC'):
00062 cmd.append('-N %s' %(env.get('NETRC')) )
00063
00064
00065 if env.get('user') == 'anonymous':
00066 cmd.extend( [ "-a ${host}:${str(path) + '/'}${TARGET.file} ${TARGET}" ] )
00067 else:
00068 cmd.extend( [ "-a ${user}@${host}:${str(path) + '/'}${TARGET.file} ${TARGET}" ] )
00069
00070 return " ".join(cmd)
00071
00072
00073
00074
00075
00076
00077
00078 def wget_gen( source, target, env, for_signature ):
00079
00080 user = env.get('user')
00081 password = env.get('password')
00082 url = env.get('url')
00083 path = env.get('path')
00084
00085 if url is None:
00086 raise UserError("WGET: need to specify 'url'")
00087
00088 wgetcmd = ["cd ${TARGET.dir.abspath} && $WGETCMD"]
00089 wgetstr = ["cd ${TARGET.dir.abspath} && $WGETCMD"]
00090
00091 if isinstance( path, (list,tuple) ):
00092 if len(path) is 1:
00093 path = path*len(target)
00094 elif len(path) != len(target):
00095 raise UserError( "WGET: length of list 'path' and the number of targets must be the same" )
00096 else:
00097 path = [path]*len(target)
00098
00099 if user is not None:
00100 wgetcmd.append( '--user=$user' )
00101 wgetstr.append( '--user=$user' )
00102 if password is not None:
00103
00104 if password.upper() in ["$ASK", "${ASK}"] and not ( for_signature or env.GetOption('no_exec') ):
00105 print "Password for user '%(user)s' at url '%(url)s':" %vars()
00106 password = getpass()
00107
00108 wgetcmd.append( '--password=%(password)s' %vars() )
00109 wgetstr.append( '--password=******' )
00110
00111 for u,p,t in zip([url]*len(target), path, target):
00112
00113 wgetcmd.append( '/'.join( [u,p,t.name] ) )
00114 wgetstr.append( '/'.join( [u,p,t.name] ) )
00115
00116
00117 return Action( " ".join(wgetcmd)," ".join(wgetstr) )
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 def fetch_emitter( target, source, env ):
00129 env.Alias( 'fetch', target)
00130
00131 do_clean = 'fetch' in COMMAND_LINE_TARGETS
00132
00133 for tgt in target:
00134
00135 if (str(tgt) in COMMAND_LINE_TARGETS) or do_clean:
00136 pass
00137 else:
00138 env.NoClean( tgt )
00139
00140 return target, source
00141
00142
00143
00144
00145
00146 def generate(env):
00147 b = Builder(generator=ftp_gen, emitter=fetch_emitter)
00148 env['BUILDERS']['FTP'] = b
00149 env['FTPCMD'] = 'ftp'
00150
00151 wg = Builder( generator=wget_gen, emitter=fetch_emitter )
00152 env['BUILDERS']['WGET'] = wg
00153 env['WGETCMD'] = 'wget'
00154
00155
00156
00157
00158
00159 def exists( env ):
00160 return 1
00161
00162