Ensure that flake8 runs against all python files

This patch ensures that all python files (including the
Ansible modules) are included in the flake8 test.

This patch also fixes the current flake8 failures found in the
Ansible modules we're carrying.

Change-Id: I9ebef6ef7bbd2e424ad1be26d593471fd6fd3056
Closes-Bug: #1473002
This commit is contained in:
Jesse Pretorius 2015-07-09 11:38:51 +01:00
parent 94e399e351
commit f827d8d015
3 changed files with 9 additions and 9 deletions

View File

@ -95,7 +95,7 @@ def get_json_from_file(module, file_path):
json_obj = json.loads(infile.read(), json_obj = json.loads(infile.read(),
object_pairs_hook=collections.OrderedDict) object_pairs_hook=collections.OrderedDict)
return json_obj return json_obj
except Exception, e: except Exception as e:
module.fail_json( module.fail_json(
msg="Error reading from file %s: %s" % (file_path, str(e))) msg="Error reading from file %s: %s" % (file_path, str(e)))
@ -104,7 +104,7 @@ def dump_json_to_file(module, file_path, json_obj):
try: try:
with open(file_path, 'w') as outfile: with open(file_path, 'w') as outfile:
json.dump(json_obj, outfile, indent=4) json.dump(json_obj, outfile, indent=4)
except Exception, e: except Exception as e:
module.fail_json( module.fail_json(
msg="Error writing to file %s: %s" % (file_path, str(e))) msg="Error writing to file %s: %s" % (file_path, str(e)))
@ -121,9 +121,9 @@ def str_to_json(module, json_str):
try: try:
return json.loads(json_str, return json.loads(json_str,
object_pairs_hook=collections.OrderedDict) object_pairs_hook=collections.OrderedDict)
except: except Exception:
return ast.literal_eval(json_str) return ast.literal_eval(json_str)
except: except Exception:
module.fail_json(msg="JSON format expected for: %s " % (json_str)) module.fail_json(msg="JSON format expected for: %s " % (json_str))

View File

@ -15,15 +15,15 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os
import base64 import base64
import os
import stat import stat
import sys import sys
import memcache import memcache
try: try:
from Crypto import Random
from Crypto.Cipher import AES from Crypto.Cipher import AES
from Crypto import Random
ENCRYPT_IMPORT = True ENCRYPT_IMPORT = True
except ImportError: except ImportError:
@ -204,7 +204,7 @@ class AESCipher(object):
:param string: ``str`` :param string: ``str``
""" """
ordinal_range = ord(string[len(string)-1:]) ordinal_range = ord(string[len(string) - 1:])
return string[:-ordinal_range] return string[:-ordinal_range]
@ -512,7 +512,7 @@ class Memcached(object):
split_d_value = {} split_d_value = {}
count = 0 count = 0
for i in range(0, len(d_value), step): for i in range(0, len(d_value), step):
split_d_value['%s.%s' % (key_name, count)] = d_value[i:i+step] split_d_value['%s.%s' % (key_name, count)] = d_value[i:i + step]
count += 1 count += 1
value = self.mc.set_multi( value = self.mc.set_multi(

View File

@ -36,7 +36,7 @@ fi
# Ignores the following rules due to how ansible modules work in general # Ignores the following rules due to how ansible modules work in general
# F403 'from ansible.module_utils.basic import *' used; unable to detect undefined names # F403 'from ansible.module_utils.basic import *' used; unable to detect undefined names
# H303 No wildcard (*) import. # H303 No wildcard (*) import.
flake8 --ignore=F403,H303 $(grep -rln -e '^#!/usr/bin/env python' -e '^#!/bin/python' * ) flake8 --ignore=F403,H303 $(grep -rln -e '^#!/usr/bin/env python' -e '^#!/bin/python' -e '^#!/usr/bin/python' * )
# Create keys if they don't already exist. # Create keys if they don't already exist.