@@ -343,41 +343,79 @@ def upload(files, verbose):
343343 "user" : mgrast_auth ['login' ],
344344 "email" : mgrast_auth ['email' ]
345345 })
346- for i , f in enumerate ( files ):
347- # get format
348- if f . endswith ( ".gz" ):
349- fformat = "gzip"
350- fname = os . path . basename ( f [: - 3 ])
351- elif f . endswith ( ".bz2" ):
352- fformat = "bzip2"
353- fname = os . path . basename ( f [: - 4 ])
354- else :
355- fformat = "upload"
356- fname = os . path . basename ( f )
357- # POST to shock
358- data = {
359- "file_name" : fname ,
360- "attributes_str" : attr
361- }
362- if verbose :
363- if len ( files ) > 1 :
364- print ( "Uploading file %d of %d (%s) to MG-RAST Shock" % ( i + 1 , len ( files ), f ))
365- else :
366- print ( "Uploading file %s to MG-RAST Shock" % ( f ))
367- result = post_file ( SHOCK_URL + "/node" , fformat , f , data = data , auth = mgrast_auth [ 'token' ], debug = verbose )
368- if verbose :
369- print ( json . dumps ( result [ 'data' ]))
370- if len ( files ) > 1 :
371- print ( "Setting info for file %d of %d (%s) in MG-RAST inbox" % ( i + 1 , len ( files ), f ) )
346+
347+ results = {
348+ 'submitted' : [] ,
349+ 'failed' : [] ,
350+ 'files' : files
351+ }
352+
353+ # Settings for nr tries
354+ max = 3
355+ current = 0
356+ sleep = 60
357+
358+ while len ( results [ 'files' ]) and current < max :
359+
360+ # increase counter
361+ current += 1
362+
363+ for i , f in enumerate ( results [ ' files' ]) :
364+ # get format
365+ print ( i , f )
366+ if f . endswith ( ".gz" ):
367+ fformat = "gzip"
368+ fname = os . path . basename ( f [: - 3 ])
369+ elif f . endswith ( ".bz2" ):
370+ fformat = "bzip2"
371+ fname = os . path . basename ( f [: - 4 ] )
372372 else :
373- print ("Setting info for file %s in MG-RAST inbox" % (f ))
374- # compute file info
375- info = obj_from_url (API_URL + "/inbox/info/" + result ['data' ]['id' ], auth = mgrast_auth ['token' ], debug = verbose )
376- if verbose :
377- print (json .dumps (info ))
378- else :
379- print (info ['status' ])
380- fids .append (result ['data' ]['id' ])
373+ fformat = "upload"
374+ fname = os .path .basename (f )
375+ # POST to shock
376+ data = {
377+ "file_name" : fname ,
378+ "attributes_str" : attr
379+ }
380+ if verbose :
381+ if len (files ) > 1 :
382+ print ("Uploading file %d of %d (%s) to MG-RAST Shock" % (i + 1 , len (files ), f ))
383+ else :
384+ print ("Uploading file %s to MG-RAST Shock" % (f ) )
385+ if True : # change to debug
386+ print ("Submitting %s to %s " % (f ,SHOCK_URL ))
387+ result = post_file (SHOCK_URL + "/node" , fformat , f , data = data , auth = mgrast_auth ['token' ], debug = verbose )
388+
389+ if result :
390+ if verbose :
391+ print (json .dumps (result ['data' ]))
392+ if len (files ) > 1 :
393+ print ("Setting info for file %d of %d (%s) in MG-RAST inbox" % (i + 1 , len (files ), f ))
394+ else :
395+ print ("Setting info for file %s in MG-RAST inbox" % (f ))
396+ # compute file info
397+ info = obj_from_url (API_URL + "/inbox/info/" + result ['data' ]['id' ], auth = mgrast_auth ['token' ], debug = verbose )
398+ if verbose :
399+ print (json .dumps (info ))
400+ else :
401+ print (info ['status' ])
402+ fids .append (result ['data' ]['id' ])
403+ results ['submitted' ].append (f )
404+ else :
405+ print (f )
406+ sys .stderr .write ("ERROR: can not submit %s\n " % (f ) )
407+ results ['failed' ].append (f )
408+
409+ if verbose :
410+ print ( results )
411+ print ( "Processed %d\t Failed %d" % (len (results ['files' ]), len (results ['failed' ]) ) )
412+ # switch list, process failed again
413+ results ['files' ] = results ['failed' ]
414+ results ['failed' ] = []
415+
416+ # wait
417+ time .sleep ( current * sleep )
418+
381419 return fids
382420
383421def archive_upload (afile , verbose ):
0 commit comments