mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 18:37:36 -02:30
Fix up flake8 for serializers
This commit is contained in:
@@ -4,11 +4,7 @@
|
|||||||
# Python
|
# Python
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import socket
|
|
||||||
import urlparse
|
|
||||||
import logging
|
import logging
|
||||||
import os.path
|
|
||||||
import datetime
|
|
||||||
from dateutil import rrule
|
from dateutil import rrule
|
||||||
|
|
||||||
# PyYAML
|
# PyYAML
|
||||||
@@ -22,9 +18,8 @@ from django.core.urlresolvers import reverse
|
|||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.db.models.fields import BLANK_CHOICE_DASH
|
from django.db.models.fields import BLANK_CHOICE_DASH
|
||||||
from django.utils.datastructures import SortedDict
|
from django.utils.datastructures import SortedDict
|
||||||
from django.utils.translation import ugettext_lazy as _
|
# from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils.encoding import smart_str
|
from django.utils.encoding import smart_str
|
||||||
from django.core.cache import cache
|
|
||||||
|
|
||||||
# Django REST Framework
|
# Django REST Framework
|
||||||
from rest_framework.compat import get_concrete_model
|
from rest_framework.compat import get_concrete_model
|
||||||
@@ -36,8 +31,8 @@ from polymorphic import PolymorphicModel
|
|||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.constants import SCHEDULEABLE_PROVIDERS
|
from awx.main.constants import SCHEDULEABLE_PROVIDERS
|
||||||
from awx.main.models import *
|
from awx.main.models import * # noqa
|
||||||
from awx.main.utils import update_scm_url, get_type_for_model, get_model_for_type
|
from awx.main.utils import get_type_for_model, get_model_for_type
|
||||||
|
|
||||||
logger = logging.getLogger('awx.api.serializers')
|
logger = logging.getLogger('awx.api.serializers')
|
||||||
|
|
||||||
@@ -828,19 +823,6 @@ class HostSerializer(BaseSerializerWithVariables):
|
|||||||
name = unicode(attrs.get(source, ''))
|
name = unicode(attrs.get(source, ''))
|
||||||
# Validate here only, update in main validate method.
|
# Validate here only, update in main validate method.
|
||||||
host, port = self._get_host_port_from_name(name)
|
host, port = self._get_host_port_from_name(name)
|
||||||
#for family in (socket.AF_INET, socket.AF_INET6):
|
|
||||||
# try:
|
|
||||||
# socket.inet_pton(family, name)
|
|
||||||
# return attrs
|
|
||||||
# except socket.error:
|
|
||||||
# pass
|
|
||||||
# Hostname should match the following regular expression and have at
|
|
||||||
# last one letter in the name (to catch invalid IPv4 addresses from
|
|
||||||
# above).
|
|
||||||
#valid_host_re = r'^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$'
|
|
||||||
#if re.match(valid_host_re, name) and re.match(r'^.*?[a-zA-Z].*?$', name):
|
|
||||||
# return attrs
|
|
||||||
#raise serializers.ValidationError('Invalid host name or IP')
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
@@ -1018,9 +1000,9 @@ class InventorySourceOptionsSerializer(BaseSerializer):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
def validate_source(self, attrs, source):
|
def validate_source(self, attrs, source):
|
||||||
src = attrs.get(source, '')
|
# TODO: Validate
|
||||||
obj = self.object
|
# src = attrs.get(source, '')
|
||||||
# FIXME
|
# obj = self.object
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def validate_source_script(self, attrs, source):
|
def validate_source_script(self, attrs, source):
|
||||||
@@ -1031,7 +1013,8 @@ class InventorySourceOptionsSerializer(BaseSerializer):
|
|||||||
try:
|
try:
|
||||||
if src.organization != self.object.inventory.organization:
|
if src.organization != self.object.inventory.organization:
|
||||||
raise serializers.ValidationError("source_script does not belong to the same organization as the inventory")
|
raise serializers.ValidationError("source_script does not belong to the same organization as the inventory")
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
# TODO: Log
|
||||||
raise serializers.ValidationError("source_script doesn't exist")
|
raise serializers.ValidationError("source_script doesn't exist")
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
@@ -1613,8 +1596,9 @@ class ScheduleSerializer(BaseSerializer):
|
|||||||
if int(count_val[1]) > 999:
|
if int(count_val[1]) > 999:
|
||||||
raise serializers.ValidationError("COUNT > 999 is unsupported")
|
raise serializers.ValidationError("COUNT > 999 is unsupported")
|
||||||
try:
|
try:
|
||||||
sched_rule = rrule.rrulestr(rrule_value)
|
rrule.rrulestr(rrule_value)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
# TODO: Log
|
||||||
raise serializers.ValidationError("rrule parsing failed validation")
|
raise serializers.ValidationError("rrule parsing failed validation")
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
@@ -1645,7 +1629,8 @@ class ActivityStreamSerializer(BaseSerializer):
|
|||||||
return {}
|
return {}
|
||||||
try:
|
try:
|
||||||
return json.loads(obj.changes)
|
return json.loads(obj.changes)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
# TODO: Log
|
||||||
logger.warn("Error deserializing activity stream json changes")
|
logger.warn("Error deserializing activity stream json changes")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user