@@ -228,12 +228,12 @@ def download_file(url, target=None, wd=None):
228228 Returns the name that the file is saved with.
229229
230230 """
231- print "Downloading %s" % url
231+ print ( "Downloading %s" % url )
232232 if not target :
233233 target = os .path .basename (url )
234234 if wd :
235235 target = os .path .join (wd , target )
236- print "Saving to %s" % target
236+ print ( "Saving to %s" % target )
237237 open (target , 'wb' ).write (urllib2 .urlopen (url ).read ())
238238 return target
239239
@@ -254,35 +254,35 @@ def unpack_zip_archive(filen, wd=None):
254254
255255 """
256256 if not zipfile .is_zipfile (filen ):
257- print "%s: not ZIP formatted file"
257+ print ( "%s: not ZIP formatted file" )
258258 return [filen ]
259259 file_list = []
260260 z = zipfile .ZipFile (filen )
261261 for name in z .namelist ():
262262 if reduce (lambda x , y : x or name .startswith (y ), IGNORE_PATHS , False ):
263- print "Ignoring %s" % name
263+ print ( "Ignoring %s" % name )
264264 continue
265265 if wd :
266266 target = os .path .join (wd , name )
267267 else :
268268 target = name
269269 if name .endswith ('/' ):
270270 # Make directory
271- print "Creating dir %s" % target
271+ print ( "Creating dir %s" % target )
272272 try :
273273 os .makedirs (target )
274274 except OSError :
275275 pass
276276 else :
277277 # Extract file
278- print "Extracting %s" % name
278+ print ( "Extracting %s" % name )
279279 try :
280280 os .makedirs (os .path .dirname (target ))
281281 except OSError :
282282 pass
283283 open (target , 'wb' ).write (z .read (name ))
284284 file_list .append (target )
285- print "Removing %s" % filen
285+ print ( "Removing %s" % filen )
286286 os .remove (filen )
287287 return file_list
288288
@@ -305,23 +305,23 @@ def unpack_tar_archive(filen, wd=None):
305305 """
306306 file_list = []
307307 if not tarfile .is_tarfile (filen ):
308- print "%s: not TAR file"
308+ print ( "%s: not TAR file" )
309309 return [filen ]
310310 t = tarfile .open (filen )
311311 for name in t .getnames ():
312312 # Check for unwanted files
313313 if reduce (lambda x , y : x or name .startswith (y ), IGNORE_PATHS , False ):
314- print "Ignoring %s" % name
314+ print ( "Ignoring %s" % name )
315315 continue
316316 # Extract file
317- print "Extracting %s" % name
317+ print ( "Extracting %s" % name )
318318 t .extract (name , wd )
319319 if wd :
320320 target = os .path .join (wd , name )
321321 else :
322322 target = name
323323 file_list .append (target )
324- print "Removing %s" % filen
324+ print ( "Removing %s" % filen )
325325 os .remove (filen )
326326 return file_list
327327
@@ -339,9 +339,9 @@ def unpack_archive(filen, wd=None):
339339 current working directory.
340340
341341 """
342- print "Unpack %s" % filen
342+ print ( "Unpack %s" % filen )
343343 ext = os .path .splitext (filen )[1 ]
344- print "Extension: %s" % ext
344+ print ( "Extension: %s" % ext )
345345 if ext == ".zip" :
346346 return unpack_zip_archive (filen , wd = wd )
347347 elif ext == ".tgz" :
@@ -382,7 +382,7 @@ def identify_type(filen):
382382 try :
383383 return MOTHUR_FILE_TYPES [ext ]
384384 except KeyError :
385- print "WARNING: unknown file type for " + filen + ", skipping"
385+ print ( "WARNING: unknown file type for " + filen + ", skipping" )
386386 return None
387387
388388
@@ -415,26 +415,26 @@ def fetch_from_mothur_website(data_tables, target_dir, datasets):
415415 """
416416 # Make working dir
417417 wd = tempfile .mkdtemp (suffix = ".mothur" , dir = os .getcwd ())
418- print "Working dir %s" % wd
418+ print ( "Working dir %s" % wd )
419419 # Iterate over all requested reference data URLs
420420 for dataset in datasets :
421- print "Handling dataset '%s'" % dataset
421+ print ( "Handling dataset '%s'" % dataset )
422422 for name in MOTHUR_REFERENCE_DATA [dataset ]:
423423 for f in fetch_files (MOTHUR_REFERENCE_DATA [dataset ][name ], wd = wd ):
424424 type_ = identify_type (f )
425425 entry_name = "%s (%s)" % (os .path .splitext (os .path .basename (f ))[0 ], name )
426- print "%s\t \' %s'\t .../%s" % (type_ , entry_name , os .path .basename (f ))
426+ print ( "%s\t \' %s'\t .../%s" % (type_ , entry_name , os .path .basename (f ) ))
427427 if type_ is not None :
428428 # Move to target dir
429429 ref_data_file = os .path .basename (f )
430430 f1 = os .path .join (target_dir , ref_data_file )
431- print "Moving %s to %s" % (f , f1 )
431+ print ( "Moving %s to %s" % (f , f1 ) )
432432 os .rename (f , f1 )
433433 # Add entry to data table
434434 table_name = "mothur_%s" % type_
435435 add_data_table_entry (data_tables , table_name , dict (name = entry_name , value = ref_data_file ))
436436 # Remove working dir
437- print "Removing %s" % wd
437+ print ( "Removing %s" % wd )
438438 shutil .rmtree (wd )
439439
440440
@@ -450,7 +450,7 @@ def files_from_filesystem_paths(paths):
450450 files = []
451451 for path in paths :
452452 path = os .path .abspath (path )
453- print "Examining '%s'..." % path
453+ print ( "Examining '%s'..." % path )
454454 if os .path .isfile (path ):
455455 # Store full path for file
456456 files .append (path )
@@ -459,7 +459,7 @@ def files_from_filesystem_paths(paths):
459459 for f in os .listdir (path ):
460460 files .extend (files_from_filesystem_paths ((os .path .join (path , f ), )))
461461 else :
462- print "Not a file or directory, ignored"
462+ print ( "Not a file or directory, ignored" )
463463 return files
464464
465465
@@ -489,14 +489,14 @@ def import_from_server(data_tables, target_dir, paths, description, link_to_data
489489 for f in files :
490490 type_ = identify_type (f )
491491 if type_ is None :
492- print "%s: unrecognised type, skipped" % f
492+ print ( "%s: unrecognised type, skipped" % f )
493493 continue
494494 ref_data_file = os .path .basename (f )
495495 target_file = os .path .join (target_dir , ref_data_file )
496496 entry_name = "%s" % os .path .splitext (ref_data_file )[0 ]
497497 if description :
498498 entry_name += " (%s)" % description
499- print "%s\t \' %s'\t .../%s" % (type_ , entry_name , ref_data_file )
499+ print ( "%s\t \' %s'\t .../%s" % (type_ , entry_name , ref_data_file ) )
500500 # Link to or copy the data
501501 if link_to_data :
502502 os .symlink (f , target_file )
@@ -508,7 +508,7 @@ def import_from_server(data_tables, target_dir, paths, description, link_to_data
508508
509509
510510if __name__ == "__main__" :
511- print "Starting..."
511+ print ( "Starting..." )
512512
513513 # Read command line
514514 parser = optparse .OptionParser ()
@@ -518,8 +518,8 @@ def import_from_server(data_tables, target_dir, paths, description, link_to_data
518518 parser .add_option ('--description' , action = 'store' , dest = 'description' , default = '' )
519519 parser .add_option ('--link' , action = 'store_true' , dest = 'link_to_data' )
520520 options , args = parser .parse_args ()
521- print "options: %s" % options
522- print "args : %s" % args
521+ print ( "options: %s" % options )
522+ print ( "args : %s" % args )
523523
524524 # Check for JSON file
525525 if len (args ) != 1 :
@@ -532,7 +532,7 @@ def import_from_server(data_tables, target_dir, paths, description, link_to_data
532532 params , target_dir = read_input_json (jsonfile )
533533
534534 # Make the target directory
535- print "Making %s" % target_dir
535+ print ( "Making %s" % target_dir )
536536 os .mkdir (target_dir )
537537
538538 # Set up data tables dictionary
@@ -554,7 +554,7 @@ def import_from_server(data_tables, target_dir, paths, description, link_to_data
554554 paths = options .paths .replace ('__cn__' , '\n ' ).replace ('__cr__' , '\r ' ).split ()
555555 import_from_server (data_tables , target_dir , paths , description , link_to_data = options .link_to_data )
556556 # Write output JSON
557- print "Outputting JSON"
558- print str (json .dumps (data_tables ))
559- open (jsonfile , 'wb ' ).write (json .dumps (data_tables ))
560- print "Done."
557+ print ( "Outputting JSON" )
558+ print (json .dumps (data_tables ))
559+ open (jsonfile , 'w ' ).write (json .dumps (data_tables , sort_keys = True ))
560+ print ( "Done." )
0 commit comments