Explorar el Código

HUE-8737 [core] Futurize apps/sqoop for Python 3.5

Ying Chen hace 6 años
padre
commit
0e79b17b45

+ 1 - 0
apps/spark/src/spark/job_server_api.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from builtins import object
 import logging
 import json
 import posixpath

+ 7 - 6
apps/sqoop/src/sqoop/api/__init__.py

@@ -15,12 +15,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from autocomplete import autocomplete
-from link import get_links, create_link, update_link,\
+from __future__ import absolute_import
+from sqoop.api.autocomplete import autocomplete
+from sqoop.api.link import get_links, create_link, update_link,\
                        link, links, link_clone, link_delete
-from connector import get_connectors, connectors, connector
-from driver import driver
-from job import get_jobs, create_job, update_job,\
+from sqoop.api.connector import get_connectors, connectors, connector
+from sqoop.api.driver import driver
+from sqoop.api.job import get_jobs, create_job, update_job,\
                 job, jobs, job_clone, job_delete,\
                 job_start, job_stop, job_status
-from submission import get_submissions, submissions
+from sqoop.api.submission import get_submissions, submissions

+ 5 - 4
apps/sqoop/src/sqoop/api/connector.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import absolute_import
 import json
 import logging
 import socket
@@ -22,12 +23,12 @@ import socket
 from django.utils.translation import ugettext as _
 
 from sqoop import client, conf
-from decorators import get_connector_or_exception
+from sqoop.api.decorators import get_connector_or_exception
 from desktop.lib.django_util import JsonResponse
 from desktop.lib.exceptions import StructuredException
 from desktop.lib.rest.http_client import RestException
-from exception import handle_rest_exception
-from utils import list_to_dict
+from sqoop.api.exception import handle_rest_exception
+from sqoop.api.utils import list_to_dict
 from django.views.decorators.cache import never_cache
 
 __all__ = ['get_connectors', 'connectors', 'connector']
@@ -45,7 +46,7 @@ def get_connectors(request):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     response['connectors'] = list_to_dict(c.get_connectors())
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not get connectors.')))
   return JsonResponse(response)
 

+ 6 - 5
apps/sqoop/src/sqoop/api/decorators.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import absolute_import
 import json
 import logging
 
@@ -24,7 +25,7 @@ from django.utils.functional import wraps
 from desktop.lib.django_util import render
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.rest.http_client import RestException
-from exception import handle_rest_exception
+from sqoop.api.exception import handle_rest_exception
 from sqoop import client, conf
 
 
@@ -39,7 +40,7 @@ def get_connector_or_exception(exception_class=PopupException):
       try:
         c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
         connector = c.get_connector(int(connector_id))
-      except RestException, e:
+      except RestException as e:
         handle_rest_exception(e, _('Could not get connector.'))
       return view_func(request, connector=connector, *args, **kwargs)
     return wraps(view_func)(decorate)
@@ -52,7 +53,7 @@ def get_link_or_exception(exception_class=PopupException):
       try:
         c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
         link = c.get_link(int(link_id))
-      except RestException, e:
+      except RestException as e:
         handle_rest_exception(e, _('Could not get link.'))
       return view_func(request, link=link, *args, **kwargs)
     return wraps(view_func)(decorate)
@@ -65,7 +66,7 @@ def get_job_or_exception(exception_class=PopupException):
       try:
         c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
         job = c.get_job(int(job_id))
-      except RestException, e:
+      except RestException as e:
         handle_rest_exception(e, _('Could not get job.'))
       return view_func(request, job=job, *args, **kwargs)
     return wraps(view_func)(decorate)
@@ -78,7 +79,7 @@ def get_submission_or_exception(exception_class=PopupException):
       try:
         c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
         submission = c.get_submission(int(submission_id))
-      except RestException, e:
+      except RestException as e:
         handle_rest_exception(e, _('Could not get submission.'))
       return view_func(request, submission=submission, *args, **kwargs)
     return wraps(view_func)(decorate)

+ 3 - 2
apps/sqoop/src/sqoop/api/driver.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import absolute_import
 import json
 import logging
 import socket
@@ -25,7 +26,7 @@ from sqoop import client, conf
 from desktop.lib.django_util import JsonResponse
 from desktop.lib.exceptions import StructuredException
 from desktop.lib.rest.http_client import RestException
-from exception import handle_rest_exception
+from sqoop.api.exception import handle_rest_exception
 from django.views.decorators.cache import never_cache
 
 __all__ = ['driver']
@@ -44,7 +45,7 @@ def driver(request):
     try:
       c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
       response['driver'] = c.get_driver().to_dict()
-    except RestException, e:
+    except RestException as e:
       response.update(handle_rest_exception(e, _('Could not get driver.')))
     return JsonResponse(response)
   else:

+ 1 - 0
apps/sqoop/src/sqoop/api/exception.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from builtins import str
 import logging
 import socket
 

+ 19 - 18
apps/sqoop/src/sqoop/api/job.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import absolute_import
 import json
 import logging
 
@@ -24,12 +25,12 @@ from django.views.decorators.cache import never_cache
 
 from sqoop import client, conf
 from sqoop.client.exception import SqoopException
-from decorators import get_job_or_exception
+from sqoop.api.decorators import get_job_or_exception
 from desktop.lib.django_util import JsonResponse
 from desktop.lib.exceptions import StructuredException
 from desktop.lib.rest.http_client import RestException
-from exception import handle_rest_exception
-from utils import list_to_dict
+from sqoop.api.exception import handle_rest_exception
+from sqoop.api.utils import list_to_dict
 
 
 __all__ = ['get_jobs', 'create_job', 'update_job', 'job', 'jobs', 'job_clone', 'job_delete', 'job_start', 'job_stop', 'job_status']
@@ -48,7 +49,7 @@ def get_jobs(request):
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     jobs = c.get_jobs()
     response['jobs'] = list_to_dict(jobs)
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not get jobs.')))
   return JsonResponse(response)
 
@@ -72,9 +73,9 @@ def create_job(request):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     response['job'] = c.create_job(job).to_dict()
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not create job.')))
-  except SqoopException, e:
+  except SqoopException as e:
     response['status'] = 100
     response['errors'] = e.to_dict()
   return JsonResponse(response)
@@ -98,9 +99,9 @@ def update_job(request, job):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     response['job'] = c.update_job(job).to_dict()
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not update job.')))
-  except SqoopException, e:
+  except SqoopException as e:
     response['status'] = 100
     response['errors'] = e.to_dict()
   return JsonResponse(response)
@@ -147,9 +148,9 @@ def job_clone(request, job):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     response['job'] = c.create_job(job).to_dict()
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not clone job.')))
-  except SqoopException, e:
+  except SqoopException as e:
     response['status'] = 100
     response['errors'] = e.to_dict()
   return JsonResponse(response)
@@ -169,9 +170,9 @@ def job_delete(request, job):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     c.delete_job(job)
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not delete job.')))
-  except SqoopException, e:
+  except SqoopException as e:
     response['status'] = 100
     response['errors'] = e.to_dict()
   return JsonResponse(response)
@@ -191,9 +192,9 @@ def job_start(request, job):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     response['submission'] = c.start_job(job).to_dict()
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not start job.')))
-  except SqoopException, e:
+  except SqoopException as e:
     response['status'] = 100
     response['errors'] = [e.to_dict()]
   return JsonResponse(response)
@@ -213,9 +214,9 @@ def job_stop(request, job):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     response['submission'] = c.stop_job(job).to_dict()
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not stop job.')))
-  except SqoopException, e:
+  except SqoopException as e:
     response['status'] = 100
     response['errors'] = e.to_dict()
   return JsonResponse(response)
@@ -235,9 +236,9 @@ def job_status(request, job):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     response['submission'] = c.get_job_status(job).to_dict()
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not get job status.')))
-  except SqoopException, e:
+  except SqoopException as e:
     response['status'] = 100
     response['errors'] = e.to_dict()
   return JsonResponse(response)

+ 13 - 12
apps/sqoop/src/sqoop/api/link.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import absolute_import
 import json
 import logging
 import socket
@@ -24,12 +25,12 @@ from django.utils.translation import ugettext as _
 
 from sqoop import client, conf
 from sqoop.client.exception import SqoopException
-from decorators import get_link_or_exception
+from sqoop.api.decorators import get_link_or_exception
 from desktop.lib.django_util import JsonResponse
 from desktop.lib.exceptions import StructuredException
 from desktop.lib.rest.http_client import RestException
-from exception import handle_rest_exception
-from utils import list_to_dict
+from sqoop.api.exception import handle_rest_exception
+from sqoop.api.utils import list_to_dict
 from django.views.decorators.cache import never_cache
 
 __all__ = ['get_links', 'create_link', 'update_link', 'link', 'links', 'link_clone', 'link_delete']
@@ -47,7 +48,7 @@ def get_links(request):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     response['links'] = list_to_dict(c.get_links())
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not get links.')))
   return JsonResponse(response)
 
@@ -68,9 +69,9 @@ def create_link(request):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     response['link'] = c.create_link(link).to_dict()
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not create link.')))
-  except SqoopException, e:
+  except SqoopException as e:
     response['status'] = 100
     response['errors'] = e.to_dict()
   return JsonResponse(response)
@@ -91,9 +92,9 @@ def update_link(request, link):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     response['link'] = c.update_link(link).to_dict()
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not update link.')))
-  except SqoopException, e:
+  except SqoopException as e:
     response['status'] = 100
     response['errors'] = e.to_dict()
   return JsonResponse(response)
@@ -140,9 +141,9 @@ def link_clone(request, link):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     response['link'] = c.create_link(link).to_dict()
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not clone link.')))
-  except SqoopException, e:
+  except SqoopException as e:
     response['status'] = 100
     response['errors'] = e.to_dict()
   return JsonResponse(response)
@@ -161,9 +162,9 @@ def link_delete(request, link):
   try:
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     c.delete_link(link)
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not delete link.')))
-  except SqoopException, e:
+  except SqoopException as e:
     response['status'] = 100
     response['errors'] = e.to_dict()
   return JsonResponse(response)

+ 1 - 0
apps/sqoop/src/sqoop/api/pagination.py

@@ -16,6 +16,7 @@
 # limitations under the License.
 
 
+from builtins import object
 class ContinuationToken(object):
   def __init__(self, page, page_size, **kwargs):
     """ Page starting at 1 """

+ 5 - 4
apps/sqoop/src/sqoop/api/submission.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import absolute_import
 import json
 import logging
 import socket
@@ -22,12 +23,12 @@ import socket
 from django.utils.translation import ugettext as _
 
 from sqoop import client, conf
-from decorators import get_submission_or_exception
+from sqoop.api.decorators import get_submission_or_exception
 from desktop.lib.django_util import JsonResponse
 from desktop.lib.exceptions import StructuredException
 from desktop.lib.rest.http_client import RestException
-from exception import handle_rest_exception
-from utils import list_to_dict
+from sqoop.api.exception import handle_rest_exception
+from sqoop.api.utils import list_to_dict
 from django.views.decorators.cache import never_cache
 
 __all__ = ['get_submissions', 'submissions']
@@ -47,7 +48,7 @@ def get_submissions(request):
     c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get())
     submissions = c.get_submissions()
     response['submissions'] = list_to_dict(submissions)
-  except RestException, e:
+  except RestException as e:
     response.update(handle_rest_exception(e, _('Could not get submissions.')))
   return JsonResponse(response)
 

+ 7 - 6
apps/sqoop/src/sqoop/client/__init__.py

@@ -1,3 +1,4 @@
+from __future__ import absolute_import
 # Licensed to Cloudera, Inc. under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -14,9 +15,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from base import SqoopClient
-from link import Link
-from connector import Connector
-from driver import Driver
-from job import Job
-from submission import Submission
+from sqoop.client.base import SqoopClient
+from sqoop.client.link import Link
+from sqoop.client.connector import Connector
+from sqoop.client.driver import Driver
+from sqoop.client.job import Job
+from sqoop.client.submission import Submission

+ 1 - 0
apps/sqoop/src/sqoop/client/base.py

@@ -14,6 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from builtins import object
 import logging
 import time
 import json

+ 2 - 0
apps/sqoop/src/sqoop/client/config.py

@@ -14,6 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from past.builtins import basestring
+from builtins import object
 import logging
 
 from desktop.lib.python_util import force_dict_to_strings

+ 3 - 1
apps/sqoop/src/sqoop/client/connector.py

@@ -14,11 +14,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import absolute_import
+from builtins import object
 import logging
 
 from desktop.lib.python_util import force_dict_to_strings
 
-from config import Config
+from sqoop.client.config import Config
 
 
 class Connector(object):

+ 3 - 1
apps/sqoop/src/sqoop/client/driver.py

@@ -14,11 +14,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import absolute_import
+from builtins import object
 import logging
 
 from desktop.lib.python_util import force_dict_to_strings
 
-from config import Config
+from sqoop.client.config import Config
 
 
 class Driver(object):

+ 2 - 1
apps/sqoop/src/sqoop/client/exception.py

@@ -1,3 +1,4 @@
+from __future__ import absolute_import
 # Licensed to Cloudera, Inc. under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -18,7 +19,7 @@ import logging
 
 from desktop.lib.python_util import force_dict_to_strings
 
-from config import Config
+from sqoop.client.config import Config
 
 
 class SqoopException(Exception):

+ 4 - 2
apps/sqoop/src/sqoop/client/job.py

@@ -1,3 +1,4 @@
+from __future__ import absolute_import
 # Licensed to Cloudera, Inc. under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -14,12 +15,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from builtins import object
 import logging
 
 from desktop.lib.python_util import force_dict_to_strings
 
-from exception import SqoopException
-from config import Config
+from sqoop.client.exception import SqoopException
+from sqoop.client.config import Config
 
 
 class Job(object):

+ 4 - 2
apps/sqoop/src/sqoop/client/link.py

@@ -1,3 +1,4 @@
+from __future__ import absolute_import
 # Licensed to Cloudera, Inc. under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -14,12 +15,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from builtins import object
 import logging
 
 from desktop.lib.python_util import force_dict_to_strings
 
-from exception import SqoopException
-from config import Config
+from sqoop.client.exception import SqoopException
+from sqoop.client.config import Config
 
 
 class Link(object):

+ 4 - 2
apps/sqoop/src/sqoop/client/submission.py

@@ -1,3 +1,4 @@
+from __future__ import absolute_import
 # Licensed to Cloudera, Inc. under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -14,12 +15,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from builtins import object
 import logging
 
 from desktop.lib.python_util import force_dict_to_strings
 
-from exception import SqoopException
-from config import Config
+from sqoop.client.exception import SqoopException
+from sqoop.client.config import Config
 
 
 class Submission(object):

+ 1 - 1
apps/sqoop/src/sqoop/sqoop_properties.py

@@ -56,7 +56,7 @@ def _parse_site(site_path):
   try:
     with open(site_path, 'r') as f:
       data = f.read()
-  except IOError, err:
+  except IOError as err:
     if err.errno != errno.ENOENT:
       LOG.error('Cannot read from "%s": %s' % (site_path, err))
       return

+ 3 - 2
apps/sqoop/src/sqoop/test_base.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from builtins import object
 import atexit
 import logging
 import os
@@ -159,13 +160,13 @@ class SqoopServerProvider(object):
           LOG.info('Check Sqoop status...')
           try:
             version = client.get_version()
-          except RestException, e:
+          except RestException as e:
             LOG.exception('Exception fetching the Sqoop server version')
 
             # Don't loop if we had an authentication error.
             if e.code == 401:
               raise
-          except Exception, e:
+          except Exception as e:
             LOG.info('Sqoop server not started yet: %s' % e)
           else:
             if version: