[GRASS-SVN] r51692 - in grass-addons/grass7/raster/r.modis:
libmodis r.modis.download
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu May 24 05:22:42 EDT 2012
Author: lucadelu
Date: 2012-05-24 02:22:42 -0700 (Thu, 24 May 2012)
New Revision: 51692
Modified:
grass-addons/grass7/raster/r.modis/libmodis/downmodis.py
grass-addons/grass7/raster/r.modis/r.modis.download/r.modis.download.py
Log:
fix problems during connection
Modified: grass-addons/grass7/raster/r.modis/libmodis/downmodis.py
===================================================================
--- grass-addons/grass7/raster/r.modis/libmodis/downmodis.py 2012-05-24 09:18:09 UTC (rev 51691)
+++ grass-addons/grass7/raster/r.modis/libmodis/downmodis.py 2012-05-24 09:22:42 UTC (rev 51692)
@@ -106,10 +106,12 @@
LOGGING_FORMAT='%(asctime)s - %(levelname)s - %(message)s'
logging.basicConfig(filename=LOG_FILENAME, level=logging.DEBUG, \
format=LOGGING_FORMAT)
+ self.nconnection = 0
- def connectFTP(self):
+ def connectFTP(self, ncon = 20):
""" Set connection to ftp server, move to path where data are stored
and create a list of directory for all days"""
+ self.nconnection += 1
try:
# connect to ftp server
self.ftp = FTP(self.url)
@@ -125,9 +127,10 @@
self.dirData = [elem.split()[-1] for elem in self.dirData if elem.startswith("d")]
if self.debug==True:
logging.debug("Open connection %s" % self.url)
- except EOFError:
- logging.error('Error in connection')
- self.connectFTP()
+ except (EOFError, ftplib.error_perm), e:
+ logging.error('Error in connection: %s' % e)
+ if self.nconnection <= ncon:
+ self.connectFTP()
def closeFTP(self):
""" Close ftp connection """
Modified: grass-addons/grass7/raster/r.modis/r.modis.download/r.modis.download.py
===================================================================
--- grass-addons/grass7/raster/r.modis/r.modis.download/r.modis.download.py 2012-05-24 09:18:09 UTC (rev 51691)
+++ grass-addons/grass7/raster/r.modis/r.modis.download/r.modis.download.py 2012-05-24 09:22:42 UTC (rev 51692)
@@ -204,26 +204,29 @@
tiles = options['tiles']
# set the debug
if flags['d']:
- debug_opt = True
+ debug_opt = True
else:
- debug_opt = False
+ debug_opt = False
for produ in products:
- prod = product(produ).returned()
- #start modis class
+ prod = product(produ).returned()
+ #start modis class
- modisOgg = downModis(url = prod['url'], user = user,password = passwd,
+ modisOgg = downModis(url = prod['url'], user = user,password = passwd,
destinationFolder = fold, tiles = tiles, path = prod['folder'],
today = firstday, enddate = finalday, delta = delta, debug = debug_opt)
- # connect to ftp
- modisOgg.connectFTP()
- # download tha tiles
- grass.message(_("Downloading MODIS product ..."))
- modisOgg.downloadsAllDay()
- if flags['g']:
- grass.message(modisOgg.filelist.name)
- else:
- grass.message(_("All data are downloaded, continue with "\
- + "r.modis.import with the option 'files=%s' and mrtpath=/path/to/mrt/" % modisOgg.filelist.name))
+ # connect to ftp
+ modisOgg.connectFTP()
+ if modisOgg.nconnection <= 20:
+ # download tha tiles
+ grass.message(_("Downloading MODIS product ..."))
+ modisOgg.downloadsAllDay()
+ if flags['g']:
+ grass.message(modisOgg.filelist.name)
+ else:
+ grass.message(_("All data are downloaded, continue with "\
+ + "r.modis.import with the option 'files=%s' and mrtpath=/path/to/mrt/" % modisOgg.filelist.name))
+ else:
+ grass.fatal(_("Error during connection"))
if __name__ == "__main__":
options, flags = grass.parser()
More information about the grass-commit
mailing list