dbrtools/dbr/dbrfilter.py
author MattD <mattd@symbian.org>
Sun, 13 Jun 2010 15:29:20 +0100
branchDBRToolsDev
changeset 283 398d483e91bb
parent 245 fd0a8d235c70
permissions -rw-r--r--
Changed help so that summaries come from components. Added smoketest method to try to reduce regressions (when I write some tests). A few minor cleanups.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
242
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
     1
# Copyright (c) 2010 Symbian Foundation Ltd
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
     2
# This component and the accompanying materials are made available
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
     3
# under the terms of the License "Eclipse Public License v1.0"
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
     4
# which accompanies this distribution, and is available
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
     5
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
     6
#
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
     7
# Initial Contributors:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
     8
# Symbian Foundation Ltd - initial contribution.
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
     9
#
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    10
# Contributors:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    11
# mattd <mattd@symbian.org>
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    12
#
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    13
# Description:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    14
# DBRFilter - DBR Filtering classes  
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    15
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    16
import dbrresults
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    17
import dbrutils
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    18
import re
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    19
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    20
from optparse import OptionParser
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    21
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    22
def CreateFilter(args):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    23
#  print args
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    24
  
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    25
  parser = OptionParser()
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    26
  parser.add_option('-i', '--iregex', dest='iregex', action='append')
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    27
  parser.add_option('-x', '--xregex', dest='xregex', action='append')
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    28
  parser.add_option('-@', '--ifile', dest='ifile', action='append')
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    29
  parser.add_option('-!', '--xfile', dest='xfile', action='append')
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    30
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    31
#  if(os.path.isfile(arg)):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    32
#    return DBRFileFilterInclude(args)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    33
#  return DBRRegexFileFilterExclude(args)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    34
  (options, args) = parser.parse_args(args)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    35
#  print options
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    36
  filter = DBRComplexFilter()
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    37
  if options.iregex:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    38
    for include in options.iregex:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    39
      filter.addInclude(DBRRegexFileFilter(include))
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    40
  if options.ifile:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    41
    for include in options.ifile:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    42
      filter.addInclude(DBRFileFilter(include))
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    43
  if options.xregex:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    44
    for exclude in options.xregex:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    45
     filter.addExclude(DBRRegexFileFilter(exclude))
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    46
  if options.xfile:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    47
    for exclude in options.xfile:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    48
      filter.addExclude(DBRFileFilter(exclude))
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    49
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    50
  return filter     
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    51
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    52
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    53
class DBRFilter:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    54
  info = ''
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    55
  def __init__(self):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    56
    self.info = 'Null Filter'
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    57
  def filter(self, results):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    58
    return results
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    59
  def include(self, results):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    60
    return set()
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    61
  def exclude(self, results):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    62
    return results
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    63
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    64
  
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    65
class DBRFileFilter (DBRFilter):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    66
  filename = ''
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    67
  def __init__(self, filename):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    68
    DBRFilter.__init__(self)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    69
    self.filename = filename
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    70
    self.files = dbrutils.readfilenamesfromfile(self.filename)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    71
#    for file in sorted(self.files):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    72
#      print file
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    73
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    74
  def include(self, results):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    75
    return dbrresults.DBRResults(results.added & self.files, results.removed & self.files, results.touched & self.files, results.changed & self.files, results.unknown & self.files)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    76
  def exclude(self, results):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    77
    return dbrresults.DBRResults(results.added - self.files, results.removed - self.files, results.touched - self.files, results.changed - self.files, results.unknown - self.files)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    78
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    79
class DBRFileFilterInclude (DBRFileFilter):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    80
  def __init__(self, filename):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    81
    DBRFileFilter.__init__(self, filename)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    82
  def filter(self, results):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    83
    return self.include(results)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    84
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    85
class DBRFileFilterExclude (DBRFileFilter):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    86
  def __init__(self, filename):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    87
    DBRFileFilter.__init__(self, filename)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    88
  def filter(self, results):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    89
    return self.exclude(results)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    90
        
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    91
class DBRRegexFileFilter (DBRFilter):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    92
  regex = ''
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    93
  def __init__(self, regex):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    94
    DBRFilter.__init__(self)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    95
    #This can throw a compiler error. It would be nicer to have this display help.
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    96
    try: 
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    97
      self.regex = re.compile(regex, re.IGNORECASE) # doing case-insensitive regexes at the moment
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    98
    except re.error:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
    99
      print 'WARNING: Bad Regular Expression:%s', regex
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   100
      self.regex = re.compile('')
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   101
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   102
  #might be able to do this nicer using 'itertools'
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   103
  def inc(self, files):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   104
    results = set()
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   105
    for candidate in files:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   106
      if self.regex.search(candidate):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   107
        results.add(candidate)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   108
    return results
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   109
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   110
  def exc(self, files):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   111
    results = set()
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   112
    for candidate in files:
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   113
      if not self.regex.search(candidate):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   114
        results.add(candidate)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   115
    return results
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   116
    
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   117
  def include(self, results):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   118
    return dbrresults.DBRResults(self.inc(results.added), self.inc(results.removed), self.inc(results.touched), self.inc(results.changed), self.inc(results.unknown))
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   119
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   120
  def exclude(self, results):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   121
    return dbrresults.DBRResults(self.exc(results.added), self.exc(results.removed), self.exc(results.touched), self.exc(results.changed), self.exc(results.unknown))
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   122
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   123
class DBRRegexFileFilterInclude (DBRRegexFileFilter):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   124
  def __init__(self, regex):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   125
    DBRRegexFileFilter.__init__(self, regex)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   126
  def filter(self, results):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   127
    return self.include(results)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   128
      
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   129
class DBRRegexFileFilterExclude (DBRRegexFileFilter):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   130
  def __init__(self, regex):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   131
    DBRRegexFileFilter.__init__(self, regex)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   132
  def filter(self, results):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   133
    return self.exclude(results)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   134
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   135
class DBRComplexFilter (DBRFilter):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   136
  exc = set()
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   137
  inc = set()
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   138
  def __init__(self):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   139
    DBRFilter.__init__(self)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   140
    self.exc = set()
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   141
    self.inc = set()
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   142
  
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   143
  def addInclude(self, filter):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   144
    self.inc.add(filter)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   145
  
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   146
  def addExclude(self, filter):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   147
    self.exc.add(filter)
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   148
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   149
  def include(self, results):
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   150
    if self.inc:
245
fd0a8d235c70 DBRTools - Filtering Logic fix for doing both include and exclude. This should be a bit better.
MattD <mattd@symbian.org>
parents: 242
diff changeset
   151
      res = dbrresults.DBRResults(set(),set(),set(),set(),set())
242
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   152
      for filter in self.inc:  
245
fd0a8d235c70 DBRTools - Filtering Logic fix for doing both include and exclude. This should be a bit better.
MattD <mattd@symbian.org>
parents: 242
diff changeset
   153
        res |= filter.include(results)
283
398d483e91bb Changed help so that summaries come from components. Added smoketest method to try to reduce regressions (when I write some tests). A few minor cleanups.
MattD <mattd@symbian.org>
parents: 245
diff changeset
   154
        print 'including...'
398d483e91bb Changed help so that summaries come from components. Added smoketest method to try to reduce regressions (when I write some tests). A few minor cleanups.
MattD <mattd@symbian.org>
parents: 245
diff changeset
   155
      return res
398d483e91bb Changed help so that summaries come from components. Added smoketest method to try to reduce regressions (when I write some tests). A few minor cleanups.
MattD <mattd@symbian.org>
parents: 245
diff changeset
   156
    return results
242
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   157
    
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   158
  def exclude(self, results):
245
fd0a8d235c70 DBRTools - Filtering Logic fix for doing both include and exclude. This should be a bit better.
MattD <mattd@symbian.org>
parents: 242
diff changeset
   159
    res = dbrresults.DBRResults(set(),set(),set(),set(),set())
283
398d483e91bb Changed help so that summaries come from components. Added smoketest method to try to reduce regressions (when I write some tests). A few minor cleanups.
MattD <mattd@symbian.org>
parents: 245
diff changeset
   160
    for filter in self.exc:
398d483e91bb Changed help so that summaries come from components. Added smoketest method to try to reduce regressions (when I write some tests). A few minor cleanups.
MattD <mattd@symbian.org>
parents: 245
diff changeset
   161
      print 'excluding...'
398d483e91bb Changed help so that summaries come from components. Added smoketest method to try to reduce regressions (when I write some tests). A few minor cleanups.
MattD <mattd@symbian.org>
parents: 245
diff changeset
   162
      res |= filter.include(results)
398d483e91bb Changed help so that summaries come from components. Added smoketest method to try to reduce regressions (when I write some tests). A few minor cleanups.
MattD <mattd@symbian.org>
parents: 245
diff changeset
   163
    return results - res
242
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   164
  
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   165
  def filter(self, results):
245
fd0a8d235c70 DBRTools - Filtering Logic fix for doing both include and exclude. This should be a bit better.
MattD <mattd@symbian.org>
parents: 242
diff changeset
   166
    return self.include(results) & self.exclude(results)
242
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   167
     
9fd4819bf104 DBRTools - Added filtering support. It's currently implmented in checkenv and diffenv, but adding it to other commands is pretty easy.
MattD <mattd@symbian.org>
parents:
diff changeset
   168