More pep8 goodness

This commit is contained in:
Matthew Jones
2015-02-04 14:43:46 -05:00
parent fbf0ebf4d9
commit 1d76c1cd06
15 changed files with 83 additions and 69 deletions

View File

@@ -62,8 +62,9 @@ class ModelAccessPermission(permissions.BasePermission):
def check_put_permissions(self, request, view, obj=None): def check_put_permissions(self, request, view, obj=None):
if not obj: if not obj:
return True # FIXME: For some reason this needs to return True # FIXME: For some reason this needs to return True
# because it is first called with obj=None? # because it is first called with obj=None?
return True
if getattr(view, 'is_variable_data', False): if getattr(view, 'is_variable_data', False):
return check_user_access(request.user, view.model, 'change', obj, return check_user_access(request.user, view.model, 'change', obj,
dict(variables=request.DATA)) dict(variables=request.DATA))
@@ -76,8 +77,10 @@ class ModelAccessPermission(permissions.BasePermission):
def check_delete_permissions(self, request, view, obj=None): def check_delete_permissions(self, request, view, obj=None):
if not obj: if not obj:
return True # FIXME: For some reason this needs to return True # FIXME: For some reason this needs to return True
# because it is first called with obj=None? # because it is first called with obj=None?
return True
return check_user_access(request.user, view.model, 'delete', obj) return check_user_access(request.user, view.model, 'delete', obj)
def check_permissions(self, request, view, obj=None): def check_permissions(self, request, view, obj=None):

View File

@@ -1592,7 +1592,7 @@ class ScheduleSerializer(BaseSerializer):
raise serializers.ValidationError('RRULE require in rrule') raise serializers.ValidationError('RRULE require in rrule')
if len(match_multiple_rrule) > 1: if len(match_multiple_rrule) > 1:
raise serializers.ValidationError('Multiple RRULE is not supported') raise serializers.ValidationError('Multiple RRULE is not supported')
if not 'interval' in rrule_value.lower(): if 'interval' not in rrule_value.lower():
raise serializers.ValidationError('INTERVAL required in rrule') raise serializers.ValidationError('INTERVAL required in rrule')
if 'tzid' in rrule_value.lower(): if 'tzid' in rrule_value.lower():
raise serializers.ValidationError('TZID is not supported') raise serializers.ValidationError('TZID is not supported')

View File

@@ -1,6 +1,8 @@
# Copyright (c) 2014 AnsibleWorks, Inc. # Copyright (c) 2014 AnsibleWorks, Inc.
# All Rights Reserved. # All Rights Reserved.
# noqa
from django.conf.urls import include, patterns, url as original_url from django.conf.urls import include, patterns, url as original_url
def url(regex, view, kwargs=None, name=None, prefix=''): def url(regex, view, kwargs=None, name=None, prefix=''):

View File

@@ -12,6 +12,7 @@ from awx.main.models import Project
class OptionEnforceError(Exception): class OptionEnforceError(Exception):
def __init__(self, value): def __init__(self, value):
self.value = value self.value = value
def __str__(self): def __str__(self):
return repr(self.value) return repr(self.value)
@@ -83,14 +84,19 @@ class BaseCommandInstance(BaseCommand):
def get_option_hostname(self): def get_option_hostname(self):
return self.option_hostname return self.option_hostname
def get_option_uuid(self): def get_option_uuid(self):
return self.option_uuid return self.option_uuid
def is_option_primary(self): def is_option_primary(self):
return self.option_primary return self.option_primary
def is_option_secondary(self): def is_option_secondary(self):
return self.option_secondary return self.option_secondary
def get_UUID(self): def get_UUID(self):
return self.UUID return self.UUID
# for the enforce_unique_find policy # for the enforce_unique_find policy
def get_unique_fields(self): def get_unique_fields(self):
return self.unique_fields return self.unique_fields

View File

@@ -122,7 +122,7 @@ class MemGroup(MemObject):
logger.debug('Adding child group %s to parent %s', group.name, self.name) logger.debug('Adding child group %s to parent %s', group.name, self.name)
if group not in self.children: if group not in self.children:
self.children.append(group) self.children.append(group)
if not self in group.parents: if self not in group.parents:
group.parents.append(self) group.parents.append(self)
def add_host(self, host): def add_host(self, host):
@@ -202,7 +202,7 @@ class BaseLoader(object):
logger.debug('Filtering host %s', host_name) logger.debug('Filtering host %s', host_name)
return None return None
host = None host = None
if not host_name in self.all_group.all_hosts: if host_name not in self.all_group.all_hosts:
host = MemHost(host_name, self.source_dir, port) host = MemHost(host_name, self.source_dir, port)
self.all_group.all_hosts[host_name] = host self.all_group.all_hosts[host_name] = host
return self.all_group.all_hosts[host_name] return self.all_group.all_hosts[host_name]
@@ -258,7 +258,7 @@ class BaseLoader(object):
if self.group_filter_re and not self.group_filter_re.match(name): if self.group_filter_re and not self.group_filter_re.match(name):
logger.debug('Filtering group %s', name) logger.debug('Filtering group %s', name)
return None return None
if not name in self.all_group.all_groups: if name not in self.all_group.all_groups:
group = MemGroup(name, self.source_dir) group = MemGroup(name, self.source_dir)
if not child: if not child:
all_group.add_child_group(group) all_group.add_child_group(group)
@@ -557,10 +557,12 @@ class Command(NoArgsCommand):
self.logger = logging.getLogger('awx.main.commands.inventory_import') self.logger = logging.getLogger('awx.main.commands.inventory_import')
self.logger.setLevel(log_levels.get(self.verbosity, 0)) self.logger.setLevel(log_levels.get(self.verbosity, 0))
handler = logging.StreamHandler() handler = logging.StreamHandler()
class Formatter(logging.Formatter): class Formatter(logging.Formatter):
def format(self, record): def format(self, record):
record.relativeSeconds = record.relativeCreated / 1000.0 record.relativeSeconds = record.relativeCreated / 1000.0
return logging.Formatter.format(self, record) return logging.Formatter.format(self, record)
formatter = Formatter('%(relativeSeconds)9.3f %(levelname)-8s %(message)s') formatter = Formatter('%(relativeSeconds)9.3f %(levelname)-8s %(message)s')
handler.setFormatter(formatter) handler.setFormatter(formatter)
self.logger.addHandler(handler) self.logger.addHandler(handler)
@@ -593,7 +595,7 @@ class Command(NoArgsCommand):
inventory=self.inventory, inventory=self.inventory,
active=True) active=True)
except InventorySource.DoesNotExist: except InventorySource.DoesNotExist:
raise CommandError('Inventory source with id=%s not found' % \ raise CommandError('Inventory source with id=%s not found' %
inventory_source_id) inventory_source_id)
self.inventory_update = None self.inventory_update = None
# Otherwise, create a new inventory source to capture this invocation # Otherwise, create a new inventory source to capture this invocation

View File

@@ -49,6 +49,7 @@ class CallbackReceiver(object):
except Exception, e: except Exception, e:
pass pass
return _handler return _handler
def check_pre_handle(data): def check_pre_handle(data):
event = data.get('event', '') event = data.get('event', '')
if event == 'playbook_on_play_start': if event == 'playbook_on_play_start':
@@ -111,7 +112,8 @@ class CallbackReceiver(object):
job_parent_events = last_parent_events.get(message['job_id'], {}) job_parent_events = last_parent_events.get(message['job_id'], {})
if message['event'] in ('playbook_on_play_start', 'playbook_on_stats', 'playbook_on_vars_prompt'): if message['event'] in ('playbook_on_play_start', 'playbook_on_stats', 'playbook_on_vars_prompt'):
parent = job_parent_events.get('playbook_on_start', None) parent = job_parent_events.get('playbook_on_start', None)
elif message['event'] in ('playbook_on_notify', 'playbook_on_setup', elif message['event'] in ('playbook_on_notify',
'playbook_on_setup',
'playbook_on_task_start', 'playbook_on_task_start',
'playbook_on_no_hosts_matched', 'playbook_on_no_hosts_matched',
'playbook_on_no_hosts_remaining', 'playbook_on_no_hosts_remaining',

View File

@@ -197,8 +197,7 @@ def rebuild_graph(message):
# Check running tasks and make sure they are active in celery # Check running tasks and make sure they are active in celery
print_log("Active celery tasks: " + str(active_tasks)) print_log("Active celery tasks: " + str(active_tasks))
for task in list(running_tasks): for task in list(running_tasks):
if (task.celery_task_id not in active_tasks and if (task.celery_task_id not in active_tasks and not hasattr(settings, 'IGNORE_CELERY_INSPECTOR')):
not hasattr(settings, 'IGNORE_CELERY_INSPECTOR')):
# NOTE: Pull status again and make sure it didn't finish in # NOTE: Pull status again and make sure it didn't finish in
# the meantime? # the meantime?
task.status = 'failed' task.status = 'failed'

View File

@@ -357,8 +357,7 @@ class Credential(PasswordFieldsModel, CommonModelNameNotUnique):
qs = qs.exclude(pk=model_class_pk) qs = qs.exclude(pk=model_class_pk)
if qs.exists(): if qs.exists():
key = NON_FIELD_ERRORS key = NON_FIELD_ERRORS
errors.setdefault(key, []).append( \ errors.setdefault(key, []).append(self.unique_error_message(model_class, unique_check))
self.unique_error_message(model_class, unique_check))
if errors: if errors:
raise ValidationError(errors) raise ValidationError(errors)

View File

@@ -229,6 +229,7 @@ class Inventory(CommonModel):
# deepest level within the tree. # deepest level within the tree.
root_group_pks = set(self.root_groups.values_list('pk', flat=True)) root_group_pks = set(self.root_groups.values_list('pk', flat=True))
group_depths = {} # pk: max_depth group_depths = {} # pk: max_depth
def update_group_depths(group_pk, current_depth=0): def update_group_depths(group_pk, current_depth=0):
max_depth = group_depths.get(group_pk, -1) max_depth = group_depths.get(group_pk, -1)
if current_depth > max_depth: if current_depth > max_depth:
@@ -541,6 +542,7 @@ class Group(CommonModelNameNotUnique):
from awx.main.tasks import update_inventory_computed_fields, bulk_inventory_element_delete from awx.main.tasks import update_inventory_computed_fields, bulk_inventory_element_delete
from awx.main.utils import ignore_inventory_computed_fields from awx.main.utils import ignore_inventory_computed_fields
from awx.main.signals import disable_activity_stream from awx.main.signals import disable_activity_stream
def mark_actual(): def mark_actual():
all_group_hosts = Group.hosts.through.objects.select_related("host", "group").filter(group__inventory=self.inventory) all_group_hosts = Group.hosts.through.objects.select_related("host", "group").filter(group__inventory=self.inventory)
group_hosts = {'groups': {}, 'hosts': {}} group_hosts = {'groups': {}, 'hosts': {}}

View File

@@ -446,7 +446,7 @@ class Job(UnifiedJob, JobOptions):
dependencies.append(self.project.create_project_update(launch_type='dependency')) dependencies.append(self.project.create_project_update(launch_type='dependency'))
if inventory_sources.count(): # and not has_setup_failures? Probably handled as an error scenario in the task runner if inventory_sources.count(): # and not has_setup_failures? Probably handled as an error scenario in the task runner
for source in inventory_sources: for source in inventory_sources:
if not source in inventory_sources_found and source.needs_update_on_launch: if source not in inventory_sources_found and source.needs_update_on_launch:
dependencies.append(source.create_inventory_update(launch_type='dependency')) dependencies.append(source.create_inventory_update(launch_type='dependency'))
return dependencies return dependencies
@@ -495,8 +495,7 @@ class JobHostSummary(CreatedModifiedModel):
null=True, null=True,
default=None, default=None,
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
editable=False, editable=False)
)
host_name = models.CharField( host_name = models.CharField(
max_length=1024, max_length=1024,

View File

@@ -14,4 +14,4 @@
# W391 - Blank line at end of file # W391 - Blank line at end of file
# W293 - Blank line contains whitespace # W293 - Blank line contains whitespace
ignore=E201,E203,E221,E225,E231,E241,E251,E261,E265,E302,E303,E501,W291,W391,W293 ignore=E201,E203,E221,E225,E231,E241,E251,E261,E265,E302,E303,E501,W291,W391,W293
exclude=awx/lib/site-packages,awx/ui exclude=awx/lib/site-packages,awx/ui,awx/api/urls.py,awx/main/migrations