VirtualBox

Ignore:
Timestamp:
Oct 24, 2022 12:09:44 AM (2 years ago)
Author:
vboxsync
Message:

ValKit/analysis: Adding better filtering and some documentation (--help) for the analyze tool. Some improvements for --option[:=]value parsing too.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/analysis/reader.py

    r97266 r97267  
    4646import datetime;
    4747import os;
     48import re;
    4849import sys;
    4950import traceback;
     
    135136        return Value(oParentTest, self.sName, self.sUnit, self.sTimestamp, self.lValue);
    136137
     138    def matchFilters(self, sPrefix, aoFilters):
     139        """
     140        Checks for any substring match between aoFilters (str or re.Pattern)
     141        and the value name prefixed by sPrefix.
     142
     143        Returns True if any of the filters matches.
     144        Returns False if none of the filters matches.
     145        """
     146        sFullName = sPrefix + self.sName;
     147        for oFilter in aoFilters:
     148            if oFilter.search(sFullName) is not None if isinstance(oFilter, re.Pattern) else sFullName.find(oFilter) >= 0:
     149                return True;
     150        return False;
     151
    137152
    138153    @staticmethod
     
    306321        return self.getFullNameWorker(cSkipUpper)[0];
    307322
    308     def matchFilters(self, asFilters):
    309         """
    310         Checks if the all of the specified filter strings are substrings
    311         of the full test name.  Returns True / False.
    312         """
    313         sName = self.getFullName();
    314         for sFilter in asFilters:
    315             if sName.find(sFilter) < 0:
    316                 return False;
    317         return True;
     323    def matchFilters(self, aoFilters):
     324        """
     325        Checks for any substring match between aoFilters (str or re.Pattern)
     326        and the full test name.
     327
     328        Returns True if any of the filters matches.
     329        Returns False if none of the filters matches.
     330        """
     331        sFullName = self.getFullName();
     332        for oFilter in aoFilters:
     333            if oFilter.search(sFullName) is not None if isinstance(oFilter, re.Pattern) else sFullName.find(oFilter) >= 0:
     334                return True;
     335        return False;
    318336
    319337    # manipulation
    320338
    321     def filterTestsWorker(self, asFilters):
     339    def filterTestsWorker(self, asFilters, fReturnOnMatch):
    322340        # depth first
    323341        i = 0;
    324342        while i < len(self.aoChildren):
    325             if self.aoChildren[i].filterTestsWorker(asFilters):
     343            if self.aoChildren[i].filterTestsWorker(asFilters, fReturnOnMatch):
    326344                i += 1;
    327345            else:
     
    332350        if self.aoChildren:
    333351            return True;
    334         return self.matchFilters(asFilters);
     352        if self.matchFilters(asFilters):
     353            return fReturnOnMatch;
     354        return not fReturnOnMatch;
    335355
    336356    def filterTests(self, asFilters):
     357        """ Keep tests matching asFilters. """
    337358        if asFilters:
    338             self.filterTestsWorker(asFilters)
     359            self.filterTestsWorker(asFilters, True);
    339360        return self;
     361
     362    def filterOutTests(self, asFilters):
     363        """ Removes tests matching asFilters. """
     364        if asFilters:
     365            self.filterTestsWorker(asFilters, False);
     366        return self;
     367
     368    def filterValuesWorker(self, asFilters, fKeepWhen):
     369        # Process children recursively.
     370        for oChild in self.aoChildren:
     371            oChild.filterValuesWorker(asFilters, fKeepWhen);
     372
     373        # Filter our values.
     374        iValue = len(self.aoValues);
     375        if iValue > 0:
     376            sFullname = self.getFullName() + ': ';
     377            while iValue > 0:
     378                iValue -= 1;
     379                if self.aoValues[iValue].matchFilters(sFullname, asFilters) != fKeepWhen:
     380                    del self.aoValues[iValue];
     381        return None;
     382
     383    def filterValues(self, asFilters):
     384        """ Keep values matching asFilters. """
     385        if asFilters:
     386            self.filterValuesWorker(asFilters, True);
     387        return self;
     388
     389    def filterOutValues(self, asFilters):
     390        """ Removes values matching asFilters. """
     391        if asFilters:
     392            self.filterValuesWorker(asFilters, False);
     393        return self;
     394
     395    def filterOutEmptyLeafTests(self):
     396        """
     397        Removes any child tests that has neither values nor sub-tests.
     398        Returns True if leaf, False if not.
     399        """
     400        iChild = len(self.aoChildren);
     401        while iChild > 0:
     402            iChild -= 1;
     403            if self.aoChildren[iChild].filterOutEmptyLeafTests():
     404                del self.aoChildren[iChild];
     405        return not self.aoChildren and not self.aoValues;
    340406
    341407    @staticmethod
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette