From 2fccbbd5a616186e10c30de6262263df1f1f0740 Mon Sep 17 00:00:00 2001 From: xudan Date: Fri, 14 Oct 2016 10:21:11 +0000 Subject: [dovetail_tool] Fix the python style scanned by flake8 JIRA: DOVETAIL-34 Change-Id: Ib9a6dd254f1d77b0cbbfa66e8e1e44df1ce14a4b Signed-off-by: xudan --- dovetail/utils/dovetail_utils.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'dovetail/utils/dovetail_utils.py') diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py index 4c671552..2e33b53a 100644 --- a/dovetail/utils/dovetail_utils.py +++ b/dovetail/utils/dovetail_utils.py @@ -11,12 +11,11 @@ import sys import subprocess +from collections import Mapping, Set, Sequence + -def exec_cmd(cmd, logger=None, - exit_on_error=True, - info=False, - error_msg="", - verbose=True): +def exec_cmd(cmd, logger=None, exit_on_error=True, info=False, + error_msg="", verbose=True): if not error_msg: error_msg = ("The command '%s' failed." % cmd) msg_exec = ("Executing command: '%s'" % cmd) @@ -55,12 +54,16 @@ def exec_cmd(cmd, logger=None, return returncode, output[0].strip() -#walkthrough the object, yield path and value -from collections import Mapping, Set, Sequence +# walkthrough the object, yield path and value # dual python 2/3 compatability, inspired by the "six" library string_types = (str, unicode) if str is bytes else (str, bytes) -iteritems = lambda mapping: getattr(mapping, 'iteritems', mapping.items)() +# iteritems = lambda mapping: getattr(mapping, 'iteritems', mapping.items)() + + +def iteritems(mapping): + return getattr(mapping, 'iteritems', mapping.items)() + def objwalk(obj, path=(), memo=None): if memo is None: @@ -68,7 +71,8 @@ def objwalk(obj, path=(), memo=None): iterator = None if isinstance(obj, Mapping): iterator = iteritems - elif isinstance(obj, (Sequence, Set)) and not isinstance(obj, string_types): + elif isinstance(obj, (Sequence, Set)) and not isinstance(obj, + string_types): iterator = enumerate if iterator: if id(obj) not in memo: @@ -80,8 +84,8 @@ def objwalk(obj, path=(), memo=None): else: yield path, obj -def get_obj_by_path(obj,dst_path): + +def get_obj_by_path(obj, dst_path): for path, obj in objwalk(obj): if path == dst_path: return obj - -- cgit 1.2.3-korg