From f827d8d0159afd475a6b717d5e618d30b102ace1 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Thu, 9 Jul 2015 11:38:51 +0100 Subject: [PATCH] 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 --- playbooks/library/copy_updates | 8 ++++---- playbooks/library/memcached | 8 ++++---- scripts/gate-check-lint.sh | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/playbooks/library/copy_updates b/playbooks/library/copy_updates index ff4ae5ffa2..9637f7a51b 100644 --- a/playbooks/library/copy_updates +++ b/playbooks/library/copy_updates @@ -95,7 +95,7 @@ def get_json_from_file(module, file_path): json_obj = json.loads(infile.read(), object_pairs_hook=collections.OrderedDict) return json_obj - except Exception, e: + except Exception as e: module.fail_json( 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: with open(file_path, 'w') as outfile: json.dump(json_obj, outfile, indent=4) - except Exception, e: + except Exception as e: module.fail_json( msg="Error writing to file %s: %s" % (file_path, str(e))) @@ -121,9 +121,9 @@ def str_to_json(module, json_str): try: return json.loads(json_str, object_pairs_hook=collections.OrderedDict) - except: + except Exception: return ast.literal_eval(json_str) - except: + except Exception: module.fail_json(msg="JSON format expected for: %s " % (json_str)) diff --git a/playbooks/library/memcached b/playbooks/library/memcached index 680202e4bd..cf945288df 100644 --- a/playbooks/library/memcached +++ b/playbooks/library/memcached @@ -15,15 +15,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import base64 +import os import stat import sys import memcache try: - from Crypto import Random from Crypto.Cipher import AES + from Crypto import Random ENCRYPT_IMPORT = True except ImportError: @@ -204,7 +204,7 @@ class AESCipher(object): :param string: ``str`` """ - ordinal_range = ord(string[len(string)-1:]) + ordinal_range = ord(string[len(string) - 1:]) return string[:-ordinal_range] @@ -512,7 +512,7 @@ class Memcached(object): split_d_value = {} count = 0 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 value = self.mc.set_multi( diff --git a/scripts/gate-check-lint.sh b/scripts/gate-check-lint.sh index d8c18ae9f9..62568e958d 100755 --- a/scripts/gate-check-lint.sh +++ b/scripts/gate-check-lint.sh @@ -36,7 +36,7 @@ fi # 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 # 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.