Procházet zdrojové kódy

[fs] Small pylint code refactoring

Romain před 5 roky
rodič
revize
60b304321b

+ 1 - 1
apps/useradmin/src/useradmin/models.py

@@ -168,7 +168,7 @@ def group_has_permission(group, perm):
 def group_permissions(group):
   return HuePermission.objects.filter(grouppermission__group=group).all()
 
-# Create a user profile for the given user
+
 def create_profile_for_user(user):
   p = UserProfile()
   p.user = user

+ 9 - 3
desktop/core/src/desktop/lib/fsmanager.py

@@ -42,14 +42,18 @@ SUPPORTED_FS = ['hdfs', 's3a', 'adl', 'abfs', 'gs']
 CLIENT_CACHE = None
 _DEFAULT_USER = DEFAULT_USER.get()
 
+
 # FIXME: Should we check hue principal for the default user?
-def _get_cache_key(fs, identifier, user=_DEFAULT_USER): # FIXME: Caching via username has issues when users get deleted. Need to switch to userid, but bigger change
+# FIXME: Caching via username has issues when users get deleted. Need to switch to userid, but bigger change
+def _get_cache_key(fs, identifier, user=_DEFAULT_USER):
   return fs + ':' + identifier + ':' + user
 
+
 def clear_cache():
   global CLIENT_CACHE
   CLIENT_CACHE = None
 
+
 def has_access(fs=None, user=None):
   if fs == 'hdfs':
     return True
@@ -106,10 +110,12 @@ def _get_client_cached(fs, name, user):
   global CLIENT_CACHE
   if CLIENT_CACHE is None:
     CLIENT_CACHE = {}
-  cache_key = _get_cache_key(fs, name, user) if conf_idbroker.is_idbroker_enabled(fs) else _get_cache_key(fs, name) # We don't want to cache by username when IDBroker not enabled
+  # We don't want to cache by username when IDBroker not enabled
+  cache_key = _get_cache_key(fs, name, user) if conf_idbroker.is_idbroker_enabled(fs) else _get_cache_key(fs, name)
   client = CLIENT_CACHE.get(cache_key)
 
-  if client and (client.expiration is None or client.expiration > int(current_ms_from_utc())): # expiration from IDBroker returns java timestamp in MS
+  # Expiration from IDBroker returns java timestamp in MS
+  if client and (client.expiration is None or client.expiration > int(current_ms_from_utc())):
     return client
   else:
     client = _make_client(fs, name, user)

+ 24 - 13
desktop/core/src/desktop/middleware.py

@@ -232,18 +232,22 @@ class AppSpecificMiddleware(object):
     for middleware_path in mw_classes:
       # This code brutally lifted from django.core.handlers
       try:
-          dot = middleware_path.rindex('.')
+        dot = middleware_path.rindex('.')
       except ValueError:
-          raise exceptions.ImproperlyConfigured(_('%(module)s isn\'t a middleware module.') % {'module': middleware_path})
+        raise exceptions.ImproperlyConfigured(_('%(module)s isn\'t a middleware module.') % {'module': middleware_path})
       mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:]
       try:
-          mod = __import__(mw_module, {}, {}, [''])
+        mod = __import__(mw_module, {}, {}, [''])
       except ImportError as e:
-          raise exceptions.ImproperlyConfigured(_('Error importing middleware %(module)s: "%(error)s".') % {'module': mw_module, 'error': e})
+        raise exceptions.ImproperlyConfigured(
+          _('Error importing middleware %(module)s: "%(error)s".') % {'module': mw_module, 'error': e}
+        )
       try:
-          mw_class = getattr(mod, mw_classname)
+        mw_class = getattr(mod, mw_classname)
       except AttributeError:
-          raise exceptions.ImproperlyConfigured(_('Middleware module "%(module)s" does not define a "%(class)s" class.') % {'module': mw_module, 'class':mw_classname})
+        raise exceptions.ImproperlyConfigured(
+          _('Middleware module "%(module)s" does not define a "%(class)s" class.') % {'module': mw_module, 'class':mw_classname}
+        )
 
       try:
         mw_instance = mw_class()
@@ -357,7 +361,13 @@ class LoginAndPermissionMiddleware(object):
       return response
     else:
       if request.GET.get('is_embeddable'):
-        return JsonResponse({'url': "%s?%s=%s" % (settings.LOGIN_URL, REDIRECT_FIELD_NAME, urlquote('/hue' + request.get_full_path().replace('is_embeddable=true', '').replace('&&','&')))}) # Remove embeddable so redirect from & to login works. Login page is not embeddable
+        return JsonResponse({
+          'url': "%s?%s=%s" % (
+              settings.LOGIN_URL,
+              REDIRECT_FIELD_NAME,
+              urlquote('/hue' + request.get_full_path().replace('is_embeddable=true', '').replace('&&', '&'))
+          )
+        }) # Remove embeddable so redirect from & to login works. Login page is not embeddable
       else:
         return HttpResponseRedirect("%s?%s=%s" % (settings.LOGIN_URL, REDIRECT_FIELD_NAME, urlquote(request.get_full_path())))
 
@@ -412,7 +422,7 @@ class AuditLoggingMiddleware(object):
   def _get_client_ip(self, request):
     x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
     if x_forwarded_for:
-        x_forwarded_for = x_forwarded_for.split(',')[0]
+      x_forwarded_for = x_forwarded_for.split(',')[0]
     return request.META.get('HTTP_CLIENT_IP') or x_forwarded_for or request.META.get('REMOTE_ADDR')
 
   def _get_username(self, request):
@@ -522,7 +532,7 @@ class HtmlValidationMiddleware(object):
 
   def _filter_warnings(self, err_list):
     """A hacky way to filter out things that we don't care about."""
-    res = [ ]
+    res = []
     for err in err_list:
       for ignore in self._to_ignore:
         if ignore.search(err):
@@ -660,10 +670,10 @@ class SpnegoMiddleware(object):
           if result != 1:
             return
 
-          gssstring=''
-          r=kerberos.authGSSServerStep(context,authstr)
+          gssstring = ''
+          r = kerberos.authGSSServerStep(context, authstr)
           if r == 1:
-            gssstring=kerberos.authGSSServerResponse(context)
+            gssstring = kerberos.authGSSServerResponse(context)
             request.META['GSS-String'] = 'Negotiate %s' % gssstring
           else:
             kerberos.authGSSServerClean(context)
@@ -681,7 +691,8 @@ class SpnegoMiddleware(object):
             principal = self.clean_principal(username)
             if principal.intersection(principals):
               # This may contain chain of reverse proxies, e.g. knox proxy, hue load balancer
-              # Compare hostname on both HTTP_X_FORWARDED_HOST & KNOX_PROXYHOSTS. Both of these can be configured to use either hostname or IPs and we have to normalize to one or the other
+              # Compare hostname on both HTTP_X_FORWARDED_HOST & KNOX_PROXYHOSTS.
+              # Both of these can be configured to use either hostname or IPs and we have to normalize to one or the other
               req_hosts = self.clean_host(request.META['HTTP_X_FORWARDED_HOST'])
               knox_proxy = self.clean_host(KNOX.KNOX_PROXYHOSTS.get())
               if req_hosts.intersection(knox_proxy):

+ 4 - 4
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -29,12 +29,12 @@
 
 <%namespace name="actionbar" file="actionbar.mako" />
 
-%if not is_embeddable:
+% if not is_embeddable:
 ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
 
 <link rel="stylesheet" href="${ static('notebook/css/notebook.css') }">
 <link rel="stylesheet" href="${ static('notebook/css/notebook-layout.css') }">
-%endif
+% endif
 
 <link rel="stylesheet" href="${ static('indexer/css/importer.css') }" type="text/css">
 
@@ -80,11 +80,11 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
   </div>
 </div>
 
-%if not is_embeddable:
+% if not is_embeddable:
 <a title="${_('Toggle Assist')}" class="pointer show-assist" data-bind="visible: !$root.isLeftPanelVisible() && $root.assistAvailable(), click: function() { $root.isLeftPanelVisible(true); }">
   <i class="fa fa-chevron-right"></i>
 </a>
-%endif
+% endif
 
 <div class="main-content">
   <div class="vertical-full container-fluid" data-bind="style: { 'padding-left' : $root.isLeftPanelVisible() ? '0' : '20px' }">