KVM test: minor style changes to kvm_config.py
- Fix indentation of a few lines.
- Limit lines to 80 characters.
- Use list comprehension in config.filter().
- Replace '== None' with 'is None'.
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3516 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/tests/kvm/kvm_config.py b/client/tests/kvm/kvm_config.py
index 7e8b1db..e478a55 100755
--- a/client/tests/kvm/kvm_config.py
+++ b/client/tests/kvm/kvm_config.py
@@ -83,8 +83,8 @@
@param filter: A regular expression that defines the filter.
@param dict: Dictionary that will be inspected.
"""
- filter = re.compile("(\\.|^)" + filter + "(\\.|$)")
- return filter.search(dict["name"]) != None
+ filter = re.compile(r"(\.|^)" + filter + r"(\.|$)")
+ return bool(filter.search(dict["name"]))
def filter(self, filter, list=None):
@@ -94,13 +94,9 @@
@param filter: A regular expression that will be used as a filter.
@param list: A list of dictionaries that will be filtered.
"""
- if list == None:
+ if list is None:
list = self.list
- filtered_list = []
- for dict in list:
- if self.match(filter, dict):
- filtered_list.append(dict)
- return filtered_list
+ return [dict for dict in list if self.match(filter, dict)]
# Currently unused, will be removed if it remains unused
@@ -111,7 +107,7 @@
@param filter: A regular expression that will filter the list.
@param list: List which we want to know the indexes that match a filter.
"""
- if list == None:
+ if list is None:
list = self.list
block_list = []
prev_match = False
@@ -248,17 +244,22 @@
temp_list.append(new_dict)
if subvariants:
- # If we're parsing 'subvariants', we need to modify the list first
- self.__modify_list_subvariants(temp_list, name, dep_list, add_to_shortname)
+ # If we're parsing 'subvariants', first modify the list
+ self.__modify_list_subvariants(temp_list, name, dep_list,
+ add_to_shortname)
temp_list = self.parse(file, temp_list,
restricted=True, prev_indent=indent)
else:
- # If we're parsing 'variants', we need to parse first and then modify the list
+ # If we're parsing 'variants', parse before modifying the list
if self.debug:
- self.__debug_print(indented_line, "Entering variant '%s' (variant inherits %d dicts)" % (name, len(list)))
+ self.__debug_print(indented_line,
+ "Entering variant '%s' "
+ "(variant inherits %d dicts)" %
+ (name, len(list)))
temp_list = self.parse(file, temp_list,
restricted=False, prev_indent=indent)
- self.__modify_list_variants(temp_list, name, dep_list, add_to_shortname)
+ self.__modify_list_variants(temp_list, name, dep_list,
+ add_to_shortname)
new_list += temp_list
@@ -401,7 +402,7 @@
continue
if self.debug and not restricted:
self.__debug_print(indented_line,
- "Entering file %s" % words[1])
+ "Entering file %s" % words[1])
if self.filename:
filename = os.path.join(os.path.dirname(self.filename),
words[1])
@@ -440,7 +441,8 @@
# Everything inside an exception should be parsed in
# restricted mode
new_list += self.parse(file, list[index:index+1],
- restricted=True, prev_indent=indent)
+ restricted=True,
+ prev_indent=indent)
else:
new_list += list[index:index+1]
list = new_list