Message ID | 8a2d08b846334a5eb097c2f32348d0c04a6789fb.1249257056.git.mgoldish@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Sun, Aug 2, 2009 at 8:58 PM, Michael Goldish<mgoldish@redhat.com> wrote: > - Fix indentation of a few lines. > - Limit lines to 80 characters. > - Use list comprehension in config.filter(). > - Replace '== None' with 'is None'. Good, applied! > Signed-off-by: Michael Goldish <mgoldish@redhat.com> > --- > Â client/tests/kvm/kvm_config.py | Â 34 ++++++++++++++++++---------------- > Â 1 files changed, 18 insertions(+), 16 deletions(-) > > 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 @@ class config: > Â Â Â Â @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 @@ class config: > Â Â Â Â @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 @@ class config: > Â Â Â Â @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 @@ class config: > Â Â Â Â Â Â Â Â 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 @@ class config: > Â Â Â Â Â Â Â Â Â Â 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 @@ class config: > Â Â Â Â Â Â Â Â Â Â Â Â # 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 > -- > 1.5.4.1 > > _______________________________________________ > Autotest mailing list > Autotest@test.kernel.org > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest >
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 @@ class config: @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 @@ class config: @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 @@ class config: @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 @@ class config: 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 @@ class config: 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 @@ class config: # 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
- 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> --- client/tests/kvm/kvm_config.py | 34 ++++++++++++++++++---------------- 1 files changed, 18 insertions(+), 16 deletions(-)