Commit 88834cdab5abaa127c3943c0f31fa51a09c6e6b2

Authored by Olivier Hagolle
1 parent aee04c81
Exists in master

bug fixes for list option and for proxy option

Showing 2 changed files with 49 additions and 33 deletions   Show diff stats
download_landsat_scene.py
... ... @@ -19,8 +19,8 @@ def connect_earthexplorer_proxy(usgs,proxy):
19 19 proxy_info = {
20 20 'user' : proxy['account'],
21 21 'pass' : proxy['passwd'],
22   - 'host' : 'proxy.myproxy.int',
23   - 'port' : 8050
  22 + 'host' : proxy['address'],
  23 + 'port' : proxy['port'],
24 24 }
25 25 # contruction d'un "opener" qui utilise une connexion proxy avec autorisation
26 26 proxy_support = urllib2.ProxyHandler({"http" : "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proxy_info,
... ... @@ -109,7 +109,7 @@ if len(sys.argv) == 1:
109 109 print " Aide : ", prog, " --help"
110 110 print " ou : ", prog, " -h"
111 111 print "example (scene): python %s -o scene -a 2013 -d 360 -f 365 -s 199030 -u usgs.txt"%sys.argv[0]
112   - print "example (liste): python %s -o date -l /home/hagolle/DOCS/TAKE5/liste_landsat8_site.txt -u usgs.txt"%sys.argv[0]
  112 + print "example (liste): python %s -o liste -l /home/hagolle/DOCS/TAKE5/liste_landsat8_site.txt -u usgs.txt"%sys.argv[0]
113 113 sys.exit(-1)
114 114 else:
115 115 usage = "usage: %prog [options] "
... ... @@ -147,39 +147,51 @@ else:
147 147 rep='/tmp/LANDSAT'
148 148 if not os.path.exists(rep):
149 149 os.mkdir(rep)
150   -
151   -############Telechargement des produits par scene
152   -if options.option=='scene':
153   - produit='LC8'
154   - station='LGN'
155   - path=options.scene[0:3]
156   - row=options.scene[3:6]
  150 + if options.option==liste:
  151 + if not os.path.exists(rep+'/LISTE'):
  152 + os.mkdir(rep+'/LISTE')
  153 +
  154 +# read password files
  155 +try:
  156 + f=file(options.usgs)
  157 + (account,passwd)=f.readline().split(' ')
  158 + print account,passwd
  159 + if passwd.endswith('\n'):
  160 + passwd=passwd[:-1]
  161 + usgs={'account':account,'passwd':passwd}
  162 + print usgs
  163 + f.close()
  164 +except :
  165 + print "error with usgs password file"
  166 + sys.exit(-2)
157 167  
158   - # read password files
  168 +if options.proxy != None :
159 169 try:
160   - f=file(options.usgs)
  170 + f=file(options.proxy)
161 171 (account,passwd)=f.readline().split(' ')
162   - print account,passwd
163 172 if passwd.endswith('\n'):
164 173 passwd=passwd[:-1]
165   - usgs={'account':account,'passwd':passwd}
166   - print usgs
  174 + proxy={'account':account,'passwd':passwd}
  175 + address=f.readline()
  176 + if address.endswith('\n'):
  177 + address=address[:-1]
  178 + port=f.readline()
  179 + if port.endswith('\n'):
  180 + port=port[:-1]
  181 + proxy={'port':port}
167 182 f.close()
168 183 except :
169   - print "error with usgs password file"
170   - sys.exit(-2)
  184 + print "error with proxy password file"
  185 + sys.exit(-3)
  186 +
  187 +############Telechargement des produits par scene
  188 +if options.option=='scene':
  189 + produit='LC8'
  190 + station='LGN'
  191 + path=options.scene[0:3]
  192 + row=options.scene[3:6]
  193 +
171 194  
172   - if options.proxy != None :
173   - try:
174   - f=file(options.proxy)
175   - (account,passwd)=f.readline().split(' ')
176   - if passwd.endswith('\n'):
177   - passwd=passwd[:-1]
178   - proxy={'account':account,'passwd':passwd}
179   - f.close()
180   - except :
181   - print "error with proxy password file"
182   - sys.exit(-3)
183 195  
184 196 rep_scene="%s/SCENES/%s_%s/GZ"%(rep,path,row)
185 197 print rep_scene
... ... @@ -220,12 +232,15 @@ if options.option=='liste':
220 232 if nom_prod.startswith('LC8'):repert='4923'
221 233 if nom_prod.startswith('LE7'):repert='3373'
222 234  
223   - if not os.path.exists(rep+'/'+site):
  235 + if not os.path.exists(rep+'/SITES/'+site):
224 236 os.mkdir(rep+'/SITES/'+site)
225 237 url="http://earthexplorer.usgs.gov/download/%s/%s/STANDARD/EE"%(repert,nom_prod)
226 238 try:
227   - connect_earthexplorer_no_proxy()
228   - #connect_earthexplorer_proxy()
229   - downloadChunks(url,rep+'/'+site,nom_prod+'.tgz')
  239 + if options.proxy!=None :
  240 + connect_earthexplorer_proxy(proxy,usgs)
  241 + else:
  242 + connect_earthexplorer_no_proxy(usgs)
  243 +
  244 + downloadChunks(url,rep+'/SITES/'+site,nom_prod+'.tgz')
230 245 except TypeError:
231 246 print 'produit %s non trouve'%nom_prod
... ...
proxy.txt
1 1 Me Secret
2   -http://aaa.bb.cc
  2 +proxy-http1.cnes.fr
  3 +8050
... ...