use six.moves to work around urllib / urllib2 / urlparse to urllib 2to3 cleanup
[htsworkflow.git] / encode_submission / encode_find.py
index 7589f5487aef5ef85a6c4ec65072aa3d025ef5bc..dd02f31befe84f3d5df1f1cb4d2c3704a25c0030 100644 (file)
@@ -2,6 +2,7 @@
 """
 Gather information about our submissions into a single RDF store
 """
+from __future__ import print_function
 
 from datetime import datetime
 import hashlib
@@ -17,8 +18,7 @@ import re
 # redland rdf lib
 import RDF
 import sys
-import urllib
-import urlparse
+from six.moves import urllib
 
 if not 'DJANGO_SETTINGS_MODULE' in os.environ:
     os.environ['DJANGO_SETTINGS_MODULE'] = 'htsworkflow.settings'
@@ -130,7 +130,7 @@ def main(cmdline=None):
 
     if opts.print_rdf:
         serializer = get_serializer(name=opts.rdf_parser_name)
-        print serializer.serialize_model_to_string(model)
+        print(serializer.serialize_model_to_string(model))
 
 
 def make_parser():
@@ -261,11 +261,11 @@ def report_submissions_with_no_library(model):
     for row in results:
         subid = row['subid']
         name = row['name']
-        print "# {0}".format(name)
-        print "<{0}>".format(subid.uri)
-        print "  encodeSubmit:library_urn "\
-              "<http://jumpgate.caltech.edu/library/> ."
-        print ""
+        print("# {0}".format(name))
+        print("<{0}>".format(subid.uri))
+        print("  encodeSubmit:library_urn "\
+              "<http://jumpgate.caltech.edu/library/> .")
+        print("")
 
 def find_submissions_with_no_library(model):
     missing_lib_query_text = """
@@ -482,7 +482,7 @@ def reload_libraries(model, library_list):
         load_library_detail(model, library_urn)
 
 def user_library_id_to_library_urn(library_id):
-    split_url = urlparse.urlsplit(library_id)
+    split_url = urllib.parse.urlsplit(library_id)
     if len(split_url.scheme) == 0:
         return LIBRARY_NS[library_id]
     else:
@@ -566,7 +566,7 @@ def load_library_detail(model, libraryUrn):
         try:
             body = get_url_as_text(str(libraryUrn.uri), 'GET')
             rdfaParser.parse_string_into_model(model, body, libraryUrn.uri)
-        except httplib2.HttpLib2ErrorWithResponse, e:
+        except httplib2.HttpLib2ErrorWithResponse as e:
             LOGGER.error(str(e))
     elif len(results) == 1:
         pass  # Assuming that a loaded dataset has one record
@@ -644,7 +644,7 @@ def login(cookie=None):
     response, content = http.request(LOGIN_URL,
                                      'POST',
                                      headers=headers,
-                                     body=urllib.urlencode(credentials))
+                                     body=urllib.parse.urlencode(credentials))
     LOGGER.debug("Login to {0}, status {1}".format(LOGIN_URL,
                                                     response['status']))