Merge pull request #487 from AlanCoding/E722

flake8: comply with new E722 rule
This commit is contained in:
Alan Rominger 2017-10-23 14:58:27 -04:00 committed by GitHub
commit 73ece87e68
17 changed files with 30 additions and 30 deletions

View File

@ -3775,7 +3775,7 @@ class ActivityStreamSerializer(BaseSerializer):
def get_object_association(self, obj):
try:
return obj.object_relationship_type.split(".")[-1].split("_")[1]
except:
except Exception:
pass
return ""

View File

@ -359,7 +359,7 @@ class ApiV1ConfigView(APIView):
try:
settings.LICENSE = {}
return Response(status=status.HTTP_204_NO_CONTENT)
except:
except Exception:
# FIX: Log
return Response({"error": _("Failed to remove license (%s)") % has_error}, status=status.HTTP_400_BAD_REQUEST)
@ -3200,7 +3200,7 @@ class WorkflowJobTemplateNodeDetail(WorkflowsEnforcementMixin, RetrieveUpdateDes
try:
obj = self.get_object()
data.update(obj.char_prompts)
except:
except Exception:
pass
return super(WorkflowJobTemplateNodeDetail, self).update_raw_data(data)

View File

@ -83,7 +83,7 @@ class URLField(CharField):
else:
netloc = '{}@{}' % (url_parts.username, netloc)
value = urlparse.urlunsplit([url_parts.scheme, netloc, url_parts.path, url_parts.query, url_parts.fragment])
except:
except Exception:
raise # If something fails here, just fall through and let the validators check it.
super(URLField, self).run_validators(value)

View File

@ -159,14 +159,14 @@ class SettingsRegistry(object):
if category_slug == 'user' and for_user:
try:
field_instance.default = original_field_instance.to_representation(getattr(self.settings, setting))
except:
except Exception:
logger.warning('Unable to retrieve default value for user setting "%s".', setting, exc_info=True)
elif not field_instance.read_only or field_instance.default is empty or field_instance.defined_in_file:
try:
field_instance.default = original_field_instance.to_representation(self.settings._awx_conf_settings._get_default(setting))
except AttributeError:
pass
except:
except Exception:
logger.warning('Unable to retrieve default value for setting "%s".', setting, exc_info=True)
# `PENDO_TRACKING_STATE` is disabled for the open source awx license

View File

@ -366,7 +366,7 @@ class SettingsWrapper(UserSettingsHolder):
return internal_value
else:
return field.run_validation(value)
except:
except Exception:
logger.warning(
'The current value "%r" for setting "%s" is invalid.',
value, name, exc_info=True)

View File

@ -16,7 +16,7 @@ class argv_placeholder(object):
def __del__(self):
try:
argv_ready(sys.argv)
except:
except Exception:
pass

View File

@ -105,7 +105,7 @@ def _load_default_license_from_file():
license_data = json.load(open(license_file))
logger.debug('Read license data from "%s".', license_file)
return license_data
except:
except Exception:
logger.warning('Could not read license from "%s".', license_file, exc_info=True)
return {}

View File

@ -122,7 +122,7 @@ def run_pexpect(args, cwd, env, logfile,
if cancelled_callback:
try:
canceled = cancelled_callback()
except:
except Exception:
logger.exception('Could not check cancel callback - canceling immediately')
if isinstance(extra_update_fields, dict):
extra_update_fields['job_explanation'] = "System error during job execution, check system logs"

View File

@ -168,7 +168,7 @@ class AnsibleInventoryLoader(object):
data = json.loads(stdout)
if not isinstance(data, dict):
raise TypeError('Returned JSON must be a dictionary, got %s instead' % str(type(data)))
except:
except Exception:
logger.error('Failed to load JSON from: %s', stdout)
raise
return data

View File

@ -105,7 +105,7 @@ class Schedule(CommonModel):
if not isinstance(extra_data, dict):
try:
extra_data = json.loads(self.extra_data)
except:
except Exception:
raise ValidationError(_("Expected JSON"))
if extra_data and 'days' in extra_data:

View File

@ -810,7 +810,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
def result_stdout_size(self):
try:
return os.stat(self.result_stdout_file).st_size
except:
except Exception:
return len(self.result_stdout)
def _result_stdout_raw_limited(self, start_line=0, end_line=None, redact_sensitive=True, escape_ascii=False):
@ -1072,7 +1072,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
update_fields.append('job_explanation')
instance.save(update_fields=update_fields)
self.websocket_emit_status("canceled")
except: # FIXME: Log this exception!
except Exception: # FIXME: Log this exception!
if settings.DEBUG:
raise

View File

@ -23,7 +23,7 @@ import yaml
import fcntl
try:
import psutil
except:
except Exception:
psutil = None
# Celery
@ -104,7 +104,7 @@ def celery_startup(conf=None, **kwargs):
from awx.main.signals import disable_activity_stream
with disable_activity_stream():
sch.save()
except:
except Exception:
logger.exception("Failed to rebuild schedule {}.".format(sch))
@ -113,7 +113,7 @@ def task_set_logger_pre_run(*args, **kwargs):
try:
cache.close()
configure_external_logger(settings, is_startup=False)
except:
except Exception:
# General exception because LogErrorsTask not used with celery signals
logger.exception('Encountered error on initial log configuration.')
@ -126,7 +126,7 @@ def inform_cluster_of_shutdown(*args, **kwargs):
this_inst.save(update_fields=['capacity', 'modified'])
logger.warning('Normal shutdown signal for instance {}, '
'removed self from capacity pool.'.format(this_inst.hostname))
except:
except Exception:
# General exception because LogErrorsTask not used with celery signals
logger.exception('Encountered problem with normal shutdown signal.')
@ -321,7 +321,7 @@ def _send_notification_templates(instance, status_str):
raise ValueError(_("status_str must be either succeeded or failed"))
try:
notification_templates = instance.get_notification_templates()
except:
except Exception:
logger.warn("No notification template defined for emitting notification")
notification_templates = None
if notification_templates:
@ -443,7 +443,7 @@ def delete_inventory(self, inventory_id, user_id):
else:
try:
user = User.objects.get(id=user_id)
except:
except Exception:
user = None
with ignore_inventory_computed_fields(), ignore_inventory_group_removal(), impersonate(user):
try:
@ -877,7 +877,7 @@ class BaseTask(LogErrorsTask):
**extra_update_fields)
try:
self.final_run_hook(instance, status, **kwargs)
except:
except Exception:
logger.exception('%s Final run hook errored.', instance.log_format)
instance.websocket_emit_status(status)
if status != 'successful' and not hasattr(settings, 'CELERY_UNIT_TEST'):

View File

@ -437,7 +437,7 @@ def group_factory(inventory):
def g(name):
try:
return Group.objects.get(name=name, inventory=inventory)
except:
except Exception:
return Group.objects.create(inventory=inventory, name=name)
return g
@ -478,7 +478,7 @@ def inventory_source_factory(inventory_factory):
source = 'file'
try:
return inventory.inventory_sources.get(name=name)
except:
except Exception:
return inventory.inventory_sources.create(name=name, source=source)
return invsrc

View File

@ -160,7 +160,7 @@ def get_ansible_version():
stdout=subprocess.PIPE)
result = proc.communicate()[0]
return result.split('\n')[0].replace('ansible', '').strip()
except:
except Exception:
return 'unknown'
@ -174,7 +174,7 @@ def get_ssh_version():
stderr=subprocess.PIPE)
result = proc.communicate()[1]
return result.split(" ")[0].split("_")[1]
except:
except Exception:
return 'unknown'
@ -186,7 +186,7 @@ def get_awx_version():
try:
import pkg_resources
return pkg_resources.require('awx')[0].version
except:
except Exception:
return __version__

View File

@ -152,7 +152,7 @@ class BaseHandler(logging.Handler):
return self._format_and_send_record(record)
except (KeyboardInterrupt, SystemExit):
raise
except:
except Exception:
self.handleError(record)
def _get_host(self, scheme='', hostname_only=False):

View File

@ -41,7 +41,7 @@ from ansible import constants as C
try:
from ansible.cache.base import BaseCacheModule
except:
except Exception:
from ansible.plugins.cache.base import BaseCacheModule

View File

@ -158,7 +158,7 @@ class CustomPdb(Rdb):
try:
socket.gethostbyname('docker.for.mac.localhost')
host = 'docker.for.mac.localhost'
except:
except Exception:
host = os.popen('ip route').read().split(' ')[2]
sock, port = Rdb.get_avail_port(self, *args, **kwargs)
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(
@ -217,7 +217,7 @@ def telnet(port):
try:
s.connect(('0.0.0.0', port))
except:
except Exception:
print 'unable to connect'
return
print 'connected to 0.0.0.0:%d' % port